node_pcap
node_pcap copied to clipboard
unpack is not defined
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]
It seems that the source code of ipv6.js
in master branch is different from the file downloaded from npm server.
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?
It works with 0.12.
i have try to build from git repository, but i get this: http://pastebin.com/mA6miy2b
Looks like you are missing the nan module, which "npm install" should have added for you.
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
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;
any ideea when will be ready and the docs also?
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.