Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dhcp

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dhcp - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

examples/malformed.js

7

lib/dhcp.js

@@ -0,1 +1,8 @@

/**
* @license DHCP.js v0.2.3 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/
*
* Copyright (c) 2017, Robert Eisele (robert@xarg.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/

@@ -2,0 +9,0 @@ const util = require('util');

23

lib/protocol.js

@@ -0,1 +1,8 @@

/**
* @license DHCP.js v0.2.3 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/
*
* Copyright (c) 2017, Robert Eisele (robert@xarg.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/

@@ -5,14 +12,16 @@ var SeqBuffer = require('./seqbuffer.js');

module.exports = {
MIN_BUFFER_LENGTH: 230, // 230 byte minimum length of DHCP packet
parse: function (buf) {
parse: function(buf) {
var sb = new SeqBuffer(buf);
var hlen, htype;
// RFC 2131
var msg = {
op: sb.getUInt8(), // op code: 1=request, 2=reply
htype: sb.getUInt8(), // hardware addr type: 1 for 10mb ethernet
hlen: sb.getUInt8(), // hardware addr length: 6 for 10mb ethernet
htype: (htype = sb.getUInt8()), // hardware addr type: 1 for 10mb ethernet
hlen: (hlen = sb.getUInt8()), // hardware addr length: 6 for 10mb ethernet
hops: sb.getUInt8(), // relay hop count

@@ -26,3 +35,3 @@ xid: sb.getUInt32(), // session id, initialized by client

giaddr: sb.getIP(), // gateway/relay agent IP
chaddr: sb.getMAC(), // client hardware address
chaddr: sb.getMAC(htype, hlen), // client hardware address
sname: sb.getUTF8(64), // server host name

@@ -36,3 +45,3 @@ file: sb.getASCII(128), // boot file name

format: function (data) {
format: function(data) {

@@ -59,3 +68,3 @@ var sb = new SeqBuffer;

sb.addUInt8(255); // Mark end
// TODO: Must options packet be >= 68 byte and 4 byte alligned?

@@ -62,0 +71,0 @@

@@ -0,1 +1,8 @@

/**
* @license DHCP.js v0.2.3 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/
*
* Copyright (c) 2017, Robert Eisele (robert@xarg.org)
* Dual licensed under the MIT or GPL Version 2 licenses.
**/

@@ -157,7 +164,11 @@ var Options = require('./options.js').opts;

},
getMAC: function () {
getMAC: function (htype, hlen) {
var mac = this._data.toString('hex', this._r, this._r += 6);
var mac = this._data.toString('hex', this._r, this._r += hlen);
this._r += 10; // + 10 since field is 16 byte and only 6 are used
if (16 < hlen) {
throw new Error('Invalid hardware address length ' + hlen);
}
this._r += 16 - hlen; // + 10 since field is 16 byte and only 6 are used for htype=1
return mac.toUpperCase().match(/../g).join('-');

@@ -164,0 +175,0 @@ },

{
"name": "dhcp",
"title": "dhcp",
"version": "0.2.2",
"version": "0.2.3",
"homepage": "https://github.com/infusion/node-dhcp",

@@ -6,0 +6,0 @@ "bugs": {

var should = require('should');
var SeqBuffer = require('../lib/seqbuffer.js');
describe('Segbuffer', function () {
describe('Segbuffer', function() {
it('should init correctly', function () {
it('should init correctly', function() {

@@ -21,3 +21,3 @@ var sb = new SeqBuffer;

it('should add uint8', function () {
it('should add uint8', function() {

@@ -45,3 +45,3 @@ var sb = new SeqBuffer(null, 20);

it('should get uint8', function () {
it('should get uint8', function() {

@@ -64,3 +64,3 @@ var sb = new SeqBuffer(new Buffer([1, 2, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should add uint16', function () {
it('should add uint16', function() {

@@ -88,3 +88,3 @@ var sb = new SeqBuffer(null, 20);

it('should get uint16', function () {
it('should get uint16', function() {

@@ -110,3 +110,3 @@ var sb = new SeqBuffer(new Buffer([0, 1, 0, 2, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should add uint32', function () {
it('should add uint32', function() {

@@ -134,3 +134,3 @@ var sb = new SeqBuffer(null, 20);

it('should get uint32', function () {
it('should get uint32', function() {

@@ -156,3 +156,3 @@ var sb = new SeqBuffer(new Buffer([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should add ascii', function () {
it('should add ascii', function() {

@@ -175,3 +175,3 @@ var sb = new SeqBuffer(null, 20);

it('should get ascii', function () {
it('should get ascii', function() {

@@ -186,3 +186,3 @@ var sb = new SeqBuffer(new Buffer([97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should add utf8', function () {
it('should add utf8', function() {

@@ -205,3 +205,3 @@ var sb = new SeqBuffer(null, 20);

it('should get utf8', function () {
it('should get utf8', function() {

@@ -216,3 +216,3 @@ var sb = new SeqBuffer(new Buffer([0x69, 0xe2, 0x9d, 0xa4, 0x75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should work with fixed string', function () {
it('should work with fixed string', function() {

@@ -243,3 +243,3 @@ var sb = new SeqBuffer(Buffer.from('abcdefghij'));

it('should add IPs', function () {
it('should add IPs', function() {

@@ -256,3 +256,3 @@ var sb = new SeqBuffer(null, 20);

it('should get IPs', function () {
it('should get IPs', function() {

@@ -267,3 +267,3 @@ var sb = new SeqBuffer(new Buffer([1, 2, 3, 4, 8, 8, 8, 8, 192, 255, 238, 238, 0, 0, 0, 0, 0, 0, 0, 0]));

it('should add Mac', function () {
it('should add Mac', function() {

@@ -281,3 +281,3 @@ var sb = new SeqBuffer(null, 20);

it('should add Mac with offsetted word', function () {
it('should add Mac with offsetted word', function() {

@@ -296,7 +296,7 @@ var sb = new SeqBuffer(null, 20);

it('should get Mac', function () {
it('should get Mac', function() {
var sb = new SeqBuffer(new Buffer([1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
sb.getMAC().should.be.equal('01-02-03-04-05-06');
sb.getMAC(1, 6).should.be.equal('01-02-03-04-05-06');

@@ -307,3 +307,3 @@ sb._r.should.be.equal(16);

it('should get Mac with offsetted byte', function () {
it('should get Mac with offsetted byte', function() {

@@ -314,3 +314,3 @@ var sb = new SeqBuffer(new Buffer([0, 0xff, 0xff, 0xff, 0xff, 0xce, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));

sb.getMAC().should.be.equal('FF-FF-FF-FF-CE-FF');
sb.getMAC(1, 6).should.be.equal('FF-FF-FF-FF-CE-FF');

@@ -321,3 +321,3 @@ sb._r.should.be.equal(17);

it('should add mixed options - 1st', function () {
it('should add mixed options - 1st', function() {

@@ -342,3 +342,3 @@ var sb = new SeqBuffer(null, 30);

it('should get mixed options - 1st', function () {
it('should get mixed options - 1st', function() {

@@ -362,3 +362,3 @@ var sb = new SeqBuffer(new Buffer([

it('should add mixed options - 2nd', function () {
it('should add mixed options - 2nd', function() {

@@ -383,3 +383,3 @@ var sb = new SeqBuffer(null, 21);

it('should get mixed options - 2st', function () {
it('should get mixed options - 2st', function() {

@@ -404,3 +404,3 @@ var sb = new SeqBuffer(new Buffer([

it('should add UInt16s options', function () {
it('should add UInt16s options', function() {

@@ -416,5 +416,5 @@ var sb = new SeqBuffer(null, 10);

});
it('should get UInt16s options', function () {
it('should get UInt16s options', function() {
var sb = new SeqBuffer(new Buffer([

@@ -431,3 +431,3 @@ 25, 6, 0, 1, 0, 2, 0, 3, 0, 0]));

it('should add nothing for empty options', function () {
it('should add nothing for empty options', function() {

@@ -443,3 +443,3 @@ var sb = new SeqBuffer(new Buffer(20).fill(32));

it('should get hex correctly', function () {
it('should get hex correctly', function() {

@@ -446,0 +446,0 @@ var sb = new SeqBuffer(new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9]));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc