Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcap writer should use native endianness when writing pcaps #48

Closed
GoogleCodeExporter opened this issue May 5, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. use pcap.Writer to create a pcap
2. od -X <> | head shows big-endian pcap file.

What is the expected output? What do you see instead?
Expected a little endian pcap on x86 platforms.

What version of the product are you using? On what operating system?
dpkt 1.7, Linux (Ubuntu 10.04 x86), Mac OS X (Snow Leopard 10.6.4 x86)

Please provide any additional information below.

--- pcap.py 2009-11-06 22:28:26.000000000 +0000
+++ pcap-new.py 2010-09-09 13:07:09.000000000 +0100
@@ -70,7 +70,10 @@
     """Simple pcap dumpfile writer."""
     def __init__(self, fileobj, snaplen=1500, linktype=DLT_EN10MB):
         self.__f = fileobj
-        fh = FileHdr(snaplen=snaplen, linktype=linktype)
+        if sys.byteorder == 'little':
+            fh = LEFileHdr(snaplen=snaplen, linktype=linktype)
+        else:
+            fh = FileHdr(snaplen=snaplen, linktype=linktype)
         self.__f.write(str(fh))

     def writepkt(self, pkt, ts=None):
@@ -78,7 +81,12 @@
             ts = time.time()
         s = str(pkt)
         n = len(s)
-        ph = PktHdr(tv_sec=int(ts),
+        if sys.byteorder == 'little':
+            ph = LEPktHdr(tv_sec=int(ts),
+                    tv_usec=int((float(ts) - int(ts)) * 1000000.0),
+                    caplen=n, len=n)
+        else:
+            ph = PktHdr(tv_sec=int(ts),
                     tv_usec=int((float(ts) - int(ts)) * 1000000.0),
                     caplen=n, len=n)
         self.__f.write(str(ph))

Original issue reported on code.google.com by pete.sha...@gmail.com on 9 Sep 2010 at 12:10

@GoogleCodeExporter
Copy link
Author

Thanks - committed in r77.

Original comment by dugsong on 6 Jan 2011 at 4:00

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant