Skip to content

Commit

Permalink
Fix in4_pseudoheader being destructive (#4259)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Feb 6, 2024
1 parent d3442b4 commit 970aa8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions scapy/layers/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def in4_pseudoheader(proto, u, plen):
:param u: IP layer instance
:param plen: the length of the upper layer and payload
"""
u = u.copy()
if u.len is not None:
if u.ihl is None:
olen = sum(len(x) for x in u.options)
Expand Down
9 changes: 9 additions & 0 deletions test/scapy/layers/inet.uts
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,12 @@ assert no_sr[UDP].chksum == sr[UDP].chksum

sr = IP(raw(IP(options=[IPOption_LSRR(routers=["1.1.1.1"]), IPOption_SSRR(routers=["8.8.8.8"])])/UDP()/DNS()))
assert no_sr[UDP].chksum != sr[UDP].chksum

# GH4174
sr = Ether(src="de:ad:be:ef:aa:55", dst="ca:fe:00:00:00:00")/IP(src="20.0.0.1",dst="100.0.0.1")/ \
IP(src="20.0.0.1",dst="100.0.0.1", options=[IPOption_SSRR(copy_flag=1, pointer=4, routers=["1.1.1.1", "8.8.8.8"])])/ \
UDP(sport=1111, dport=2222) / VXLAN() / \
Ether(src="de:ad:be:ef:aa:55", dst="ca:fe:00:00:00:00")/IP(src="20.0.0.1",dst="100.0.0.1") / \
TCP()
bytes(sr[UDP])
assert sr[IP:2].dst == "100.0.0.1"

0 comments on commit 970aa8a

Please sign in to comment.