Skip to content

Commit 9c3d51c

Browse files
authored
Fix interface IP for point-to-point links (#4887)
- For point-to-point links, IFA_ADDRESS is the peer rather than local interface IP; we need to instead use IFA_LOCAL
1 parent 69fdfbf commit 9c3d51c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scapy/arch/linux/rtnetlink.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,23 @@ def _get_ips(af_family=socket.AF_UNSPEC):
774774
ifindex = msg.ifa_index
775775
address = None
776776
family = msg.ifa_family
777+
local = None
777778
for attr in msg.data:
778779
if attr.rta_type == 0x01: # IFA_ADDRESS
779780
address = attr.rta_data
780-
break
781-
if address is not None:
781+
elif attr.rta_type == 0x02: # IFA_LOCAL
782+
local = attr.rta_data
783+
# include/uapi/linux/if_addr.h: for point-to-point links, IFA_LOCAL is the local
784+
# interface address and IFA_ADDRESS is the peer address
785+
local_address = local if local is not None else address
786+
if local_address is not None:
782787
data = {
783788
"af_family": family,
784789
"index": ifindex,
785-
"address": address,
790+
"address": local_address,
786791
}
787792
if family == 10: # ipv6
788-
data["scope"] = scapy.utils6.in6_getscope(address)
793+
data["scope"] = scapy.utils6.in6_getscope(local_address)
789794
ips.setdefault(ifindex, list()).append(data)
790795
return ips
791796

0 commit comments

Comments
 (0)