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

Function in6_getLocalUniquePrefix

scapy/utils6.py:405–432  ·  view source on GitHub ↗

Returns a pseudo-randomly generated Local Unique prefix. Function follows recommendation of Section 3.2.2 of RFC 4193 for prefix generation.

()

Source from the content-addressed store, hash-verified

403
404
405def in6_getLocalUniquePrefix():
406 # type: () -> str
407 """
408 Returns a pseudo-randomly generated Local Unique prefix. Function
409 follows recommendation of Section 3.2.2 of RFC 4193 for prefix
410 generation.
411 """
412 # Extracted from RFC 1305 (NTP) :
413 # NTP timestamps are represented as a 64-bit unsigned fixed-point number,
414 # in seconds relative to 0h on 1 January 1900. The integer part is in the
415 # first 32 bits and the fraction part in the last 32 bits.
416
417 # epoch = (1900, 1, 1, 0, 0, 0, 5, 1, 0)
418 # x = time.time()
419 # from time import gmtime, strftime, gmtime, mktime
420 # delta = mktime(gmtime(0)) - mktime(self.epoch)
421 # x = x-delta
422
423 tod = time.time() # time of day. Will bother with epoch later
424 i = int(tod)
425 j = int((tod - i) * (2**32))
426 btod = struct.pack("!II", i, j)
427 mac = RandMAC()
428 # construct modified EUI-64 ID
429 eui64 = inet_pton(socket.AF_INET6, '::' + in6_mactoifaceid(str(mac)))[8:]
430 import hashlib
431 globalid = hashlib.sha1(btod + eui64).digest()[:5]
432 return inet_ntop(socket.AF_INET6, b'\xfd' + globalid + b'\x00' * 10)
433
434
435def in6_getRandomizedIfaceId(ifaceid, previous=None):

Callers

nothing calls this directly

Calls 5

RandMACClass · 0.90
inet_ptonFunction · 0.90
inet_ntopFunction · 0.90
in6_mactoifaceidFunction · 0.85
digestMethod · 0.45

Tested by

no test coverage detected