@@ -166,6 +166,12 @@ def __init__(self, name):
166166
167167 def i2h (self , pkt , x ):
168168 # type: (Optional[Packet], Optional[str]) -> str
169+ if x is None and pkt is not None :
170+ x = "None (resolved on build)"
171+ return super (DestMACField , self ).i2h (pkt , x )
172+
173+ def i2m (self , pkt , x ):
174+ # type: (Optional[Packet], Optional[str]) -> bytes
169175 if x is None and pkt is not None :
170176 try :
171177 x = conf .neighbor .resolve (pkt , pkt .payload )
@@ -176,12 +182,10 @@ def i2h(self, pkt, x):
176182 raise ScapyNoDstMacException ()
177183 else :
178184 x = "ff:ff:ff:ff:ff:ff"
179- warning ("Mac address to reach destination not found. Using broadcast." ) # noqa: E501
180- return super (DestMACField , self ).i2h (pkt , x )
181-
182- def i2m (self , pkt , x ):
183- # type: (Optional[Packet], Optional[str]) -> bytes
184- return super (DestMACField , self ).i2m (pkt , self .i2h (pkt , x ))
185+ warning (
186+ "MAC address to reach destination not found. Using broadcast."
187+ )
188+ return super (DestMACField , self ).i2m (pkt , x )
185189
186190
187191class SourceMACField (MACField ):
@@ -311,8 +315,10 @@ class LLC(Packet):
311315 ByteField ("ctrl" , 0 )]
312316
313317
314- def l2_register_l3 (l2 , l3 ):
315- # type: (Packet, Packet) -> Optional[str]
318+ def l2_register_l3 (l2 : Packet , l3 : Packet ) -> Optional [str ]:
319+ """
320+ Delegates resolving the default L2 destination address to the payload of L3.
321+ """
316322 neighbor = conf .neighbor # type: Neighbor
317323 return neighbor .resolve (l2 , l3 .payload )
318324
@@ -554,15 +560,28 @@ def mysummary(self):
554560 return self .sprintf ("ARP %op% %psrc% > %pdst%" )
555561
556562
557- def l2_register_l3_arp (l2 , l3 ):
558- # type: (Packet, Packet) -> Optional[str]
559- # TODO: support IPv6?
560- plen = l3 .plen if l3 .plen is not None else l3 .get_field ("pdst" ).i2len (l3 , l3 .pdst )
563+ def l2_register_l3_arp (l2 : Packet , l3 : Packet ) -> Optional [str ]:
564+ """
565+ Resolves the default L2 destination address when ARP is used.
566+ """
567+ if l3 .op == 1 : # who-has
568+ return "ff:ff:ff:ff:ff:ff"
569+ elif l3 .op == 2 : # is-at
570+ log_runtime .warning (
571+ "You should be providing the Ethernet destination MAC address when "
572+ "sending an is-at ARP."
573+ )
574+ # Need ARP request to send ARP request...
575+ plen = l3 .get_field ("pdst" ).i2len (l3 , l3 .pdst )
561576 if plen == 4 :
562577 return getmacbyip (l3 .pdst )
578+ elif plen == 32 :
579+ from scapy .layers .inet6 import getmacbyip6
580+ return getmacbyip6 (l3 .pdst )
581+ # Can't even do that
563582 log_runtime .warning (
564- "Unable to guess L2 MAC address from an ARP packet with a "
565- "non-IPv4 pdst. Provide it manually ! "
583+ "You should be providing the Ethernet destination mac when sending this "
584+ "kind of ARP packets. "
566585 )
567586 return None
568587
0 commit comments