Returns a pseudo-randomly generated Local Unique prefix. Function follows recommendation of Section 3.2.2 of RFC 4193 for prefix generation.
()
| 403 | |
| 404 | |
| 405 | def 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 | |
| 435 | def in6_getRandomizedIfaceId(ifaceid, previous=None): |
nothing calls this directly
no test coverage detected