node-pcap / node_pcap

libpcap bindings for node
MIT License
928 stars 253 forks source link

Is it possible to extract the socket message from the raw packet? #275

Closed tylers-username closed 3 years ago

tylers-username commented 3 years ago

I'm trying to drop the headers and fluff so that only the original socket message remains.

So, if I have another NodeJS running and I send socket.write(Buffer.from([0xAB])), how would I get 0xAB from the raw_packet using node_pcap?

This is what I have so far.

pcap_session.on("packet", function (raw_packet) {
    console.log("raw packet", raw_packet);
    const packet = pcap.decode.packet(raw_packet);
    console.log(
        packet,
        raw_packet.buf.slice(packet.pcap_header.len, raw_packet.buf.length)
    );
});
tylers-username commented 3 years ago

It seems that payload.data should do this.