MCPcopy Index your code
hub / github.com/secdev/scapy / in6_ifaceidtomac

Function in6_ifaceidtomac

scapy/utils6.py:244–269  ·  view source on GitHub ↗

Extract the mac address from provided iface ID. Iface ID is provided in printable format ("XXXX:XXFF:FEXX:XXXX", eventually compressed). None is returned on error.

(ifaceid_s)

Source from the content-addressed store, hash-verified

242
243
244def in6_ifaceidtomac(ifaceid_s):
245 # type: (str) -> Optional[str]
246 """
247 Extract the mac address from provided iface ID. Iface ID is provided
248 in printable format ("XXXX:XXFF:FEXX:XXXX", eventually compressed). None
249 is returned on error.
250 """
251 try:
252 # Set ifaceid to a binary form
253 ifaceid = inet_pton(socket.AF_INET6, "::" + ifaceid_s)[8:16]
254 except Exception:
255 return None
256
257 if ifaceid[3:5] != b'\xff\xfe': # Check for burned-in MAC address
258 return None
259
260 # Unpacking and converting first byte of faceid to MAC address equivalent
261 first = struct.unpack("B", ifaceid[:1])[0]
262 ulbit = 2 * [1, '-', 0][first & 0x02]
263 first = struct.pack("B", ((first & 0xFD) | ulbit))
264 # Split into two vars to remove the \xff\xfe bytes
265 oui = first + ifaceid[1:3]
266 end = ifaceid[5:]
267 # Convert and reconstruct into a MAC Address
268 mac_bytes = ["%.02x" % orb(x) for x in list(oui + end)]
269 return ":".join(mac_bytes)
270
271
272def in6_addrtomac(addr):

Callers 1

in6_addrtomacFunction · 0.85

Calls 3

inet_ptonFunction · 0.90
orbFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected