Skip to content
Snippets Groups Projects
Commit df4e97b5 authored by Pierre LALET's avatar Pierre LALET
Browse files

Use `Packet().raw_packet_cache` attribute when iterating

When iterating over `Packet` instances, `.raw_packet_cache` attribute
was not used, causing bugs similar to the one detailed in issue #913
to appear when packets sniffed or built from strings representations
were used with `wrpcap()`, `send`(`p`?), `sr`(`p`?), etc.

This commit essentially copies the `.raw_packet_cache` attribute in
`.clone_with()` method.

--HG--
branch : issue-5105
parent e4de3aa9
No related branches found
No related tags found
No related merge requests found
...@@ -634,10 +634,10 @@ Creates an EPS file describing a packet. If filename is not provided a temporary ...@@ -634,10 +634,10 @@ Creates an EPS file describing a packet. If filename is not provided a temporary
pkt.underlayer = self.underlayer pkt.underlayer = self.underlayer
pkt.overload_fields = self.overload_fields.copy() pkt.overload_fields = self.overload_fields.copy()
pkt.post_transforms = self.post_transforms pkt.post_transforms = self.post_transforms
pkt.raw_packet_cache = self.raw_packet_cache
if payload is not None: if payload is not None:
pkt.add_payload(payload) pkt.add_payload(payload)
return pkt return pkt
def __iter__(self): def __iter__(self):
def loop(todo, done, self=self): def loop(todo, done, self=self):
...@@ -666,7 +666,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary ...@@ -666,7 +666,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary
pkt = self.clone_with(payload=payl, **done2) pkt = self.clone_with(payload=payl, **done2)
yield pkt yield pkt
if self.explicit: if self.explicit or self.raw_packet_cache is not None:
todo = [] todo = []
done = self.fields done = self.fields
else: else:
......
...@@ -646,8 +646,9 @@ class RawPcapWriter: ...@@ -646,8 +646,9 @@ class RawPcapWriter:
def write(self, pkt): def write(self, pkt):
"""accepts a either a single packet or a list of packets """accepts either a single packet or a list of packets to be
to be written to the dumpfile written to the dumpfile
""" """
if not self.header_present: if not self.header_present:
self._write_header(pkt) self._write_header(pkt)
...@@ -700,7 +701,7 @@ class PcapWriter(RawPcapWriter): ...@@ -700,7 +701,7 @@ class PcapWriter(RawPcapWriter):
self.linktype = 1 self.linktype = 1
RawPcapWriter._write_header(self, pkt) RawPcapWriter._write_header(self, pkt)
def _write_packet(self, packet): def _write_packet(self, packet):
sec = int(packet.time) sec = int(packet.time)
usec = int(round((packet.time-sec)*1000000)) usec = int(round((packet.time-sec)*1000000))
s = str(packet) s = str(packet)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment