Skip to content

Commit

Permalink
Fix (Ether() / ARP()).show()
Browse files Browse the repository at this point in the history
Bug introduced in 435918e

Test added.
  • Loading branch information
p-l- committed Jan 9, 2019
1 parent 3e04af3 commit d139af4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 11 additions & 8 deletions scapy/layers/l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def getmacbyip(ip, chainCC=0):
"""Return MAC address corresponding to a given IP address"""
if isinstance(ip, Net):
ip = next(iter(ip))
ip = inet_ntoa(inet_aton(ip))
ip = inet_ntoa(inet_aton(ip or "0.0.0.0"))
tmp = [orb(e) for e in inet_aton(ip)]
if (tmp[0] & 0xf0) == 0xe0: # mcast @
return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1] & 0x7f, tmp[2], tmp[3])
Expand All @@ -85,13 +85,16 @@ def getmacbyip(ip, chainCC=0):
if mac:
return mac

res = srp1(Ether(dst=ETHER_BROADCAST) / ARP(op="who-has", pdst=ip),
type=ETH_P_ARP,
iface=iff,
timeout=2,
verbose=0,
chainCC=chainCC,
nofilter=1)
try:
res = srp1(Ether(dst=ETHER_BROADCAST) / ARP(op="who-has", pdst=ip),
type=ETH_P_ARP,
iface=iff,
timeout=2,
verbose=0,
chainCC=chainCC,
nofilter=1)
except Exception:
return None
if res is not None:
mac = res.payload.hwsrc
conf.netcache.arp_cache[ip] = mac
Expand Down
3 changes: 3 additions & 0 deletions test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -10697,6 +10697,9 @@ test_IPID_count()
############
+ ARP

= Simple Ether() / ARP() show
(Ether() / ARP()).show()

= ARP for IPv4

p = raw(ARP())
Expand Down

0 comments on commit d139af4

Please sign in to comment.