GTiroadkill / dpkt

Automatically exported from code.google.com/p/dpkt
Other
0 stars 0 forks source link

Write timestamp arithmetic error #86

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In Writepkt, tv_usec contain arithmetic error.
   82:        tv_usec=int((float(ts) - int(ts)) * 1000000.0)
2. For example.
   >>> ts = 123234345.667883
   >>> int((float(ts) - int(ts)) * 1000000.0)
   667882
   ^^^^^^ will be 667883 ?

What version of the product are you using? On what operating system?
Python 2.7.2
dpkt-1.7

Please provide any additional information below.

Only microsecond pcap.

diff -r a9f4cfba928f -r d599f177d81e dpkt/pcap.py
--- a/dpkt/pcap.py  Thu Jan 26 10:31:28 2012 +0900
+++ b/dpkt/pcap.py  Tue Mar 13 14:21:59 2012 +0900
@@ -79,7 +79,7 @@
         s = str(pkt)
         n = len(s)
         ph = PktHdr(tv_sec=int(ts),
-                    tv_usec=int((float(ts) - int(ts)) * 1000000.0),
+                    tv_usec=int(round((float(ts) - int(ts)),6) * 1000000.0),
                     caplen=n, len=n)
         self.__f.write(str(ph))
         self.__f.write(s)

Original issue reported on code.google.com by ruy.su...@gmail.com on 13 Mar 2012 at 3:18

GoogleCodeExporter commented 9 years ago
No round(), will make correct...

ph = PktHdr(tv_sec=int(ts)&0xffffffff,
        tv_usec=int((ts * 1000000.0 - int(ts) * 1000000.0))&0xffffffff,
        caplen=n, len=origin_len)

Original comment by ruy.su...@gmail.com on 13 Mar 2013 at 11:40