node-pcap / node_pcap

libpcap bindings for node
MIT License
930 stars 254 forks source link

Add decode DHCP in decode folder #166

Open John-Lin opened 9 years ago

John-Lin commented 9 years ago

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:

jmaxxz commented 9 years ago

can you provide me a link to your work?

John-Lin commented 9 years ago

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