Comparing version 0.2.4 to 0.2.5
@@ -66,9 +66,11 @@ /** | ||
if (buf.length < Protocol.MIN_BUFFER_LENGTH) { | ||
self.emit('error', new Error('Malformed packet'), buf); | ||
var req; | ||
try { | ||
req = Protocol.parse(buf); | ||
} catch (e) { | ||
self.emit('error', e); | ||
return; | ||
} | ||
var req = Protocol.parse(buf); | ||
if (req.op !== BOOTREQUEST) { | ||
@@ -477,9 +479,11 @@ self.emit('error', new Error('Malformed packet'), req); | ||
if (buf.length < Protocol.MIN_BUFFER_LENGTH) { | ||
self.emit('error', new Error('Malformed packet'), buf); | ||
var req; | ||
try { | ||
req = Protocol.parse(buf); | ||
} catch (e) { | ||
self.emit('error', e); | ||
return; | ||
} | ||
var req = Protocol.parse(buf); | ||
if (req.op !== BOOTREPLY) { | ||
@@ -486,0 +490,0 @@ self.emit('error', new Error('Malformed packet'), req); |
@@ -13,5 +13,7 @@ /** | ||
MIN_BUFFER_LENGTH: 230, // 230 byte minimum length of DHCP packet | ||
parse: function(buf) { | ||
if (buf.length < 230) { // 230 byte minimum length of DHCP packet | ||
throw new Error('Received data is too short'); | ||
} | ||
@@ -18,0 +20,0 @@ var sb = new SeqBuffer(buf); |
@@ -28,45 +28,45 @@ /** | ||
addUInt8: function (val) { | ||
addUInt8: function(val) { | ||
this._w = this._data.writeUInt8(val, this._w, true); | ||
}, | ||
getUInt8: function () { | ||
getUInt8: function() { | ||
return this._data.readUInt8(this._r++, true); | ||
}, | ||
// | ||
addInt8: function (val) { | ||
addInt8: function(val) { | ||
this._w = this._data.writeInt8(val, this._w, true); | ||
}, | ||
getInt8: function () { | ||
getInt8: function() { | ||
return this._data.readInt8(this._r++, true); | ||
}, | ||
// | ||
addUInt16: function (val) { | ||
addUInt16: function(val) { | ||
this._w = this._data.writeUInt16BE(val, this._w, true); | ||
}, | ||
getUInt16: function () { | ||
getUInt16: function() { | ||
return this._data.readUInt16BE((this._r += 2) - 2, true); | ||
}, | ||
// | ||
addInt16: function (val) { | ||
addInt16: function(val) { | ||
this._w = this._data.writeInt16BE(val, this._w, true); | ||
}, | ||
getInt16: function () { | ||
getInt16: function() { | ||
return this._data.readInt16BE((this._r += 2) - 2, true); | ||
}, | ||
// | ||
addUInt32: function (val) { | ||
addUInt32: function(val) { | ||
this._w = this._data.writeUInt32BE(val, this._w, true); | ||
}, | ||
getUInt32: function () { | ||
getUInt32: function() { | ||
return this._data.readUInt32BE((this._r += 4) - 4, true); | ||
}, | ||
// | ||
addInt32: function (val) { | ||
addInt32: function(val) { | ||
this._w = this._data.writeInt32BE(val, this._w, true); | ||
}, | ||
getInt32: function () { | ||
getInt32: function() { | ||
return this._data.readInt32BE((this._r += 4) - 4, true); | ||
}, | ||
// | ||
addUTF8: function (val, fixLen) { | ||
addUTF8: function(val, fixLen) { | ||
@@ -81,7 +81,7 @@ if (fixLen) { | ||
}, | ||
getUTF8: function (len) { | ||
getUTF8: function(len) { | ||
return trimZero(this._data.toString('utf8', this._r, this._r += len)); | ||
}, | ||
// | ||
addASCII: function (val, fixLen) { | ||
addASCII: function(val, fixLen) { | ||
@@ -96,7 +96,7 @@ if (fixLen) { | ||
}, | ||
getASCII: function (len) { | ||
getASCII: function(len) { | ||
return trimZero(this._data.toString('ascii', this._r, this._r += len)); | ||
}, | ||
// | ||
addIP: function (ip) { | ||
addIP: function(ip) { | ||
var self = this; | ||
@@ -119,3 +119,3 @@ var octs = ip.split('.'); | ||
}, | ||
getIP: function () { | ||
getIP: function() { | ||
@@ -128,3 +128,3 @@ return this.getUInt8() + | ||
// | ||
addIPs: function (ips) { | ||
addIPs: function(ips) { | ||
@@ -139,3 +139,3 @@ if (ips instanceof Array) { | ||
}, | ||
getIPs: function (len) { | ||
getIPs: function(len) { | ||
var ret = []; | ||
@@ -148,3 +148,3 @@ for (var i = 0; i < len; i += 4) { | ||
// | ||
addMac: function (mac) { | ||
addMac: function(mac) { | ||
@@ -171,22 +171,22 @@ var octs = mac.split(/[-:]/); | ||
}, | ||
getMAC: function (htype, hlen) { | ||
getMAC: function(htype, hlen) { | ||
var mac = this._data.toString('hex', this._r, this._r += hlen); | ||
if (16 < hlen) { | ||
throw new Error('Invalid hardware address length ' + hlen); | ||
if (htype !== 1 || hlen !== 6) { | ||
throw new Error('Invalid hardware address (len=' + hlen + ', type=' + htype + ')'); | ||
} | ||
this._r += 16 - hlen; // + 10 since field is 16 byte and only 6 are used for htype=1 | ||
this._r += 10; // + 10 since field is 16 byte and only 6 are used for htype=1 | ||
return mac.toUpperCase().match(/../g).join('-'); | ||
}, | ||
// | ||
addBool: function () { | ||
addBool: function() { | ||
/* void */ | ||
}, | ||
getBool: function () { | ||
getBool: function() { | ||
return true; | ||
}, | ||
// | ||
addOptions: function (opts) { | ||
addOptions: function(opts) { | ||
@@ -268,3 +268,3 @@ for (var i in opts) { | ||
}, | ||
getOptions: function () { | ||
getOptions: function() { | ||
@@ -296,3 +296,3 @@ var options = {}; | ||
// | ||
addUInt8s: function (arr) { | ||
addUInt8s: function(arr) { | ||
@@ -307,3 +307,3 @@ if (arr instanceof Array) { | ||
}, | ||
getUInt8s: function (len) { | ||
getUInt8s: function(len) { | ||
var ret = []; | ||
@@ -315,3 +315,3 @@ for (var i = 0; i < len; i++) { | ||
}, | ||
addUInt16s: function (arr) { | ||
addUInt16s: function(arr) { | ||
@@ -326,3 +326,3 @@ if (arr instanceof Array) { | ||
}, | ||
getUInt16s: function (len) { | ||
getUInt16s: function(len) { | ||
var ret = []; | ||
@@ -335,3 +335,3 @@ for (var i = 0; i < len; i += 2) { | ||
// | ||
getHex: function (len) { | ||
getHex: function(len) { | ||
return this._data.toString('hex', this._r, this._r += len); | ||
@@ -338,0 +338,0 @@ } |
{ | ||
"name": "dhcp", | ||
"title": "dhcp", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "https://github.com/infusion/node-dhcp", | ||
@@ -6,0 +6,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2068
72429