diff --git a/README.md b/README.md index af4feec..b1eaed5 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,11 @@ var linkType = c.open(device, filter, bufSize, buffer); c.setMinBytes && c.setMinBytes(0); -c.on('packet', function(nbytes, trunc) { +c.on('packet', function(nbytes, trunc, ts) { console.log('packet: length ' + nbytes + ' bytes, truncated? ' + (trunc ? 'yes' : 'no')); + const timestamp = Number(`${ts.seconds}${Math.floor(ts.microseconds/1000)}`); + console.log(`timestamp: ${new Date(timestamp).toISOString()}`); // raw packet data === buffer.slice(0, nbytes) diff --git a/src/binding.cc b/src/binding.cc index a71491a..a0d5091 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -134,15 +134,23 @@ class Pcap : public Nan::ObjectWrap { } memcpy(obj->buffer_data, pkt_data, copy_len); - Local emit_argv[3] = { + Local Timestamp; + Timestamp = Nan::New(); + Timestamp->Set(Nan::New("seconds").ToLocalChecked(), + Nan::New(pkt_hdr->ts.tv_sec)); + Timestamp->Set(Nan::New("microseconds").ToLocalChecked(), + Nan::New(pkt_hdr->ts.tv_usec)); + + Local emit_argv[4] = { Nan::New(packet_symbol), Nan::New(copy_len), - Nan::New(truncated) + Nan::New(truncated), + Timestamp }; Nan::MakeCallback( Nan::New(obj->persistent()), Nan::New(obj->Emit), - 3, + 4, emit_argv ); } @@ -183,7 +191,7 @@ class Pcap : public Nan::ObjectWrap { } #else static void cb_packets(uv_poll_t* handle, int status, int events) { - assert(status == 0); + // assert(status == 0); Pcap *obj = (Pcap*)handle->data; int packet_count;