node_pcap icon indicating copy to clipboard operation
node_pcap copied to clipboard

unpack is not defined

Open idy opened this issue 10 years ago • 9 comments

I get the error unpack is not defined when running the following coffee script:

util = require 'util'
pcap = require 'pcap'
argv = require 'yargs'
  .alias 'd', 'device'
  .argv
pcapSession = pcap.createSession argv.device
pcapSession.on 'packet', (raw_packet) ->
  console.log pcap.decode.packet raw_packet

shell output:

➜  pcappp git:(master) ✗ sudo node dist/bin/pcappp.js -d lo0

/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/decode/ipv6.js:63
    ret.payload_length = unpack.uint16(raw_packet, offset+4);
                         ^
ReferenceError: unpack is not defined
    at IPv6.decode (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/decode/ipv6.js:63:26)
    at NullPacket.decode (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/decode/null_packet.js:22:35)
    at PcapPacket.decode (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/decode/pcap_packet.js:39:41)
    at Function.decode (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/decode/index.js:11:29)
    at PcapSession.<anonymous> (/Users/yan/Projects/zuiqt/pcappp/dist/bin/pcappp.js:13:34)
    at PcapSession.emit (events.js:95:17)
    at PcapSession.on_packet_ready (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/pcap.js:98:10)
    at packet_ready (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/pcap.js:43:14)
    at SocketWatcher.pcap_read_callback [as callback] (/Users/yan/Projects/zuiqt/pcappp/node_modules/pcap/pcap.js:63:45)

pcap version:

➜  pcappp git:(master) ✗ npm list pcap
[email protected] /Users/yan/Projects/zuiqt/pcappp
└── [email protected]

idy avatar Feb 08 '15 15:02 idy

It seems that the source code of ipv6.js in master branch is different from the file downloaded from npm server.

idy avatar Feb 08 '15 16:02 idy

Yeah, we need to publish a new version to npm after a bunch of recent changes.

Can you try the version from github and see if it works for you?

mranney avatar Feb 08 '15 18:02 mranney

It works with 0.12.

idy avatar Feb 09 '15 06:02 idy

i have try to build from git repository, but i get this: http://pastebin.com/mA6miy2b

SoulRaven avatar Feb 09 '15 18:02 SoulRaven

Looks like you are missing the nan module, which "npm install" should have added for you.

mranney avatar Feb 09 '15 19:02 mranney

i added manualy, but still not working, and get a lot of errors, new error now,

pcap_session.on('packet', function (raw_packet) { "use strict"; var packet = pcap.decode.packet(raw_packet), linkIP = packet.link.ip, data = linkIP.tcp.data, deviceIP = linkIP.saddr, serverIP = linkIP.daddr,

packet.link.ip is gone, and a guess also the other objects

SoulRaven avatar Feb 09 '15 19:02 SoulRaven

Ahh yes. The API did change for this version, but it hasn't been documented yet. Sorry for tripping you up on this. Things are still coming together after the refactor, new NAN, etc. Once we publish a new version to npm, we'll get the new API documented.

The payload of every encapsulating packet type is now called "payload". Every packet type also has a named constructor, so you can more accurately tell what kind of packets you have. Check out tcp_tracker.js for some related examples. Specifically you can do things like this:

    if (packet.payload.payload instanceof IPv4 && packet.payload.payload.payload instanceof TCP) {
        ip  = packet.payload.payload;
        tcp = ip.payload;
        src = ip.saddr + ":" + tcp.sport;
        dst = ip.daddr + ":" + tcp.dport;

mranney avatar Feb 09 '15 19:02 mranney

any ideea when will be ready and the docs also?

SoulRaven avatar Feb 09 '15 19:02 SoulRaven

It's hard to say. A bunch of changes came through in the past couple of weeks. Hopefully we can get 2.0 published to npm in the next few days, and then it'll take a while after that to update the documentation.

The best documentation right now is to look at how the decoders work.

mranney avatar Feb 09 '15 19:02 mranney