node_pcap icon indicating copy to clipboard operation
node_pcap copied to clipboard

Add decode DHCP in decode folder

Open John-Lin opened this issue 9 years ago • 2 comments

Hi, I'm trying to write a DHCP parser for decoding DHCP also make a contribution. I wrote a dhcp.js in decode folder and using eventsOnDecode = true, but I can't see the decode results.

<skip>

DHCP.prototype.decoderName = "dhcp";
DHCP.prototype.eventsOnDecode = true;

module.exports = DHCP;

Here is my example code

var buffer = require('buffer');
var pcap = require('pcap');

function main() {
  var pcap_session = pcap.createOfflineSession("pcaps/dhcp.pcap",'ip proto \\udp');
  pcap_session.on('packet', function (raw_packet) {
    var packet = pcap.decode.packet(raw_packet);
    var linkLayer =  packet.payload;
    var networkLayer =  packet.payload.payload;
    var tranportLayer = packet.payload.payload.payload;
    console.log(tranportLayer);
  });
}

main();

And it output was

{ sport: 67,
  dport: 68,
  length: 308,
  checksum: 57307,
  data: <Buffer 02 01 06 00 00 00 3d 1e 00 00 00 00 00 00 00 00 c0 a8 00 0a 00 00 00 00 00 00 00 00 00 0b 82 01 fc 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... > }

I expected it output will like this

{ sport: 67,
  dport: 68,
  length: 308,
  checksum: 57307,
  payload: {op:1,
                  htype:xxx,
                  hlen:xxxx,
                  hops: xxx 
                  <skip>   }

It seems dhcp.js not been used when event decode. How to fix this problem? Thanks :smiley:

John-Lin avatar Apr 25 '15 12:04 John-Lin

can you provide me a link to your work?

jmaxxz avatar Apr 25 '15 19:04 jmaxxz

Hi, I have not yet completed the dhcp.js. I just want to do some test.

Here is the link about dhcp.js https://gist.github.com/John-Lin/97f8622d3a52bbba1ecd

John-Lin avatar Apr 26 '15 04:04 John-Lin