Skip to content

Commit 578a7b3

Browse files
committed
adds tv_usec field for precision capture
1 parent 343c166 commit 578a7b3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pylibpcap/base.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ cdef class BasePcap(object):
6464
# create file
6565
open(self.path, 'w').close()
6666

67-
self.out_pcap = pcap_dump_open(self.handler, self.path)
67+
self.out_pcap = pcap_dump_open(self.handler, self.path)
6868

6969
if self.out_pcap == NULL:
70-
raise LibpcapError(self.get_handler_error())
70+
raise LibpcapError(self.get_handler_error())
7171

7272
def _to_c_str(self, v):
7373
"""Python str to C str
@@ -269,7 +269,7 @@ cdef class Sniff(BasePcap):
269269
cdef object nonblocking_thread
270270

271271
def __init__(self, str iface, int count=-1, int promisc=0, int snaplen=65535,
272-
int timeout=0, str filters="", str out_file="", int monitor=-1,
272+
int timeout=0, str filters="", str out_file="", int monitor=-1,
273273
immediate_mode=0, *args, **kwargs):
274274
"""init
275275
"""
@@ -319,7 +319,7 @@ cdef class Sniff(BasePcap):
319319
self.set_filter(self.handler, self.filters)
320320

321321
self.out_pcap = pcap_dump_open(self.handler, self.out_file) if out_file else NULL
322-
322+
323323
def capture_nonblocking_thread(self):
324324
"""Code that runs in the thread
325325
"""
@@ -342,7 +342,6 @@ cdef class Sniff(BasePcap):
342342
"""
343343
return self.nonblocking_thread and self.nonblocking_thread.is_alive()
344344

345-
346345
def stop_capture_nonblocking(self):
347346
"""Stop capturing packets in another thread (capture_nonblocking)
348347
"""
@@ -375,7 +374,9 @@ cdef class Sniff(BasePcap):
375374
if count > 0:
376375
count -= 1
377376

378-
yield pkt_header.caplen, pkt_header.ts.tv_sec, (<char*>pkt)[:pkt_header.caplen]
377+
timestamp = pkt_header.ts.tv_sec + (pkt_header.ts.tv_usec / 1000000.0)
378+
379+
yield pkt_header.caplen, timestamp, (<char*>pkt)[:pkt_header.caplen]
379380

380381
def stats(self):
381382
"""stats

0 commit comments

Comments
 (0)