forked from node-pcap/node_pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
var dec = require("../util").int8_to_dec; | ||
|
||
function IPv4Addr(raw_packet, offset) { | ||
this.o1 = raw_packet[offset]; | ||
this.o2 = raw_packet[offset + 1]; | ||
this.o3 = raw_packet[offset + 2]; | ||
this.o4 = raw_packet[offset + 3]; | ||
this.addr = new Array(4); | ||
this.addr[0] = raw_packet[offset]; | ||
this.addr[1] = raw_packet[offset + 1]; | ||
this.addr[2] = raw_packet[offset + 2]; | ||
this.addr[3] = raw_packet[offset + 3]; | ||
} | ||
|
||
// Don't use Array.prototype.join here, because string concat is much faster | ||
IPv4Addr.prototype.toString = function () { | ||
return dec[this.o1] + "." + dec[this.o2] + "." + dec[this.o3] + "." + dec[this.o4]; | ||
return dec[this.addr[0]] + "." + dec[this.addr[1]] + "." + dec[this.addr[2]] + "." + dec[this.addr[3]]; | ||
}; | ||
|
||
module.exports = IPv4Addr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var Igmp = require("../../decode/igmp"); | ||
var util = require("../../util"); | ||
require("should"); | ||
|
||
describe("IGMP", function(){ | ||
var exampleIgmp, instance; | ||
beforeEach(function () { | ||
exampleIgmp = new Buffer("0102030405060708", "hex"); | ||
instance = new Igmp(); | ||
}); | ||
|
||
describe("#decode()", function(){ | ||
it("is a function", function(){ | ||
instance.decode.should.be.type("function"); | ||
}); | ||
|
||
it("sets the #type to the IGMP type", function() { | ||
instance.decode(exampleIgmp, 0); | ||
instance.should.have.property("type", 1); | ||
}); | ||
|
||
it("sets the #maxResponseTime", function() { | ||
instance.decode(exampleIgmp, 0); | ||
instance.should.have.property("maxResponseTime", 2); | ||
}); | ||
|
||
it("sets the #checksum", function() { | ||
instance.decode(exampleIgmp, 0); | ||
instance.should.have.property("checksum", 772); | ||
}); | ||
|
||
it("sets the #groupAddress", function() { | ||
instance.decode(exampleIgmp, 0); | ||
instance.groupAddress.should.have.property("addr", [5, 6, 7, 8]); | ||
}); | ||
}); | ||
|
||
describe("#toString()", function() { | ||
var verifyToString = function verifyToString(type, result){ | ||
it("return \""+result+"\" for igmp of type="+type, function(){ | ||
instance = new Igmp(); | ||
instance.decode(new Buffer(util.int8_to_hex[type] + "000000000000", "hex"), 0); | ||
instance.toString().should.be.exactly(result); | ||
}); | ||
}; | ||
|
||
//verifyToString(type, string) | ||
verifyToString(0x11, "Membership Query"); | ||
verifyToString(0x12, "Membership Report"); | ||
verifyToString(0x16, "Membership Report"); | ||
verifyToString(0x17, "Leave Group"); | ||
verifyToString(0x22, "Membership Report"); | ||
|
||
//Default handler | ||
verifyToString(0x01, "type 1"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters