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

Function in6_get_common_plen

scapy/utils6.py:882–901  ·  view source on GitHub ↗

Return common prefix length of IPv6 addresses a and b.

(a, b)

Source from the content-addressed store, hash-verified

880
881
882def in6_get_common_plen(a, b):
883 # type: (str, str) -> int
884 """
885 Return common prefix length of IPv6 addresses a and b.
886 """
887 def matching_bits(byte1, byte2):
888 # type: (int, int) -> int
889 for i in range(8):
890 cur_mask = 0x80 >> i
891 if (byte1 & cur_mask) != (byte2 & cur_mask):
892 return i
893 return 8
894
895 tmpA = inet_pton(socket.AF_INET6, a)
896 tmpB = inet_pton(socket.AF_INET6, b)
897 for i in range(16):
898 mbits = matching_bits(orb(tmpA[i]), orb(tmpB[i]))
899 if mbits != 8:
900 return 8 * i + mbits
901 return 128
902
903
904def in6_isvalid(address):

Callers 1

rfc3484_cmpFunction · 0.85

Calls 3

inet_ptonFunction · 0.90
orbFunction · 0.90
matching_bitsFunction · 0.85

Tested by

no test coverage detected