Skip to content

Commit eb68ff6

Browse files
committed
Add test and support for 'comment' parameter for back compatibility
1 parent 0a17862 commit eb68ff6

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

scapy/utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,11 +2094,9 @@ def read_packet(self, size=MTU, **kwargs):
20942094
if tshigh is not None:
20952095
p.time = EDecimal((tshigh << 32) + tslow) / tsresol
20962096
p.wirelen = wirelen
2097-
p.comment = comment
2098-
if comments is not None:
2099-
comments.remove(comment)
2100-
if len(comments) > 0:
2101-
p.comments = comments
2097+
p.comments = comments
2098+
if p.comments is None:
2099+
p.comment = comment
21022100
p.direction = direction
21032101
p.process_information = process_information.copy()
21042102
if ifname is not None:
@@ -2595,8 +2593,8 @@ def _write_block_epb(self,
25952593
# Options
25962594
opts = b''
25972595
if comments is not None and len(comments) > 0:
2598-
for comment in comments:
2599-
comment = bytes_encode(comment)
2596+
for c in comments:
2597+
comment = bytes_encode(c)
26002598
opts += struct.pack(self.endian + "HH", 1, len(comment))
26012599
# Pad Option Value to 32 bits
26022600
opts += self._add_padding(comment)

test/regression.uts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,12 @@ wrpcapng(tmpfile, p)
22502250
l = rdpcap(tmpfile)
22512251
assert l[0].comment == p.comment
22522252

2253+
p = Ether() / IPv6() / TCP()
2254+
p.comments = [b"Hello!", b"Scapy!", b"Pcapng!"]
2255+
wrpcapng(tmpfile, p)
2256+
l = rdpcap(tmpfile)
2257+
assert l[0].comments == p.comments
2258+
22532259
= rdpcap on fifo
22542260
~ linux
22552261
f = get_temp_file()

0 commit comments

Comments
 (0)