Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scapy/arch/bpf/pfroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ class sockaddr(Packet):
XStrLenField(
"sa_data",
"",
length_from=lambda pkt: pkt.sa_len - 2 if pkt.sa_len >= 2 else 0,
# NOTE: Darwin right-justifies netmask on 4 byte word alignment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a PadField instead? I will check, but most likely this padding isn't DARWIN-specific.

What's the padding. 8?

length_from=lambda pkt:
((pkt.sa_len+3)//4*4 - 2 if pkt.sa_len >= 2 else 0) if DARWIN else
(pkt.sa_len - 2 if pkt.sa_len >= 2 else 0),
),
lambda pkt: pkt.sa_family
not in [
Expand Down Expand Up @@ -1023,6 +1026,9 @@ def read_routes():
if DARWIN and flags.RTF_WASCLONED and msg.rtm_parentflags.RTF_PRCLONING:
# OSX needs filtering
continue
if DARWIN and flags.RTF_HOST and not flags.RTF_BROADCAST:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do a

if DARWIN:
    # OSX needs filtering
    if ....:
        continue
    # <...>
    if ....:
        continue

for clarity? Thanks.

# DARWIN includes the entire ARP table in the route response. Remove it.
continue
addrs = msg.rtm_addrs
net = 0
mask = 0xFFFFFFFF
Expand All @@ -1046,7 +1052,10 @@ def read_routes():
if nm.sa_family == socket.AF_INET:
mask = atol(nm.sin_addr)
elif nm.sa_family in [0x00, 0xFF]: # NetBSD
mask = struct.unpack("<I", nm.sa_data[:4].rjust(4, b"\x00"))[0]
if DARWIN:
mask = struct.unpack(">I", nm.sa_data[-4:].rjust(4, b"\x00"))[0]
else:
mask = struct.unpack("<I", nm.sa_data[:4].rjust(4, b"\x00"))[0]
else:
mask = int.from_bytes(nm.sa_data[:4], "big")
i += 1
Expand Down