Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/netutil.py
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | elif ':' in addr: # IPv6 | ||||
x = 0 | x = 0 | ||||
addr = addr.split(':') | addr = addr.split(':') | ||||
for i, comp in enumerate(addr): | for i, comp in enumerate(addr): | ||||
if comp == '': | if comp == '': | ||||
# skip empty component at beginning or end | # skip empty component at beginning or end | ||||
if i == 0 or i == (len(addr) - 1): | if i == 0 or i == (len(addr) - 1): | ||||
continue | continue | ||||
x += 1 # :: skips to suffix | x += 1 # :: skips to suffix | ||||
assert(x < 2) | assert x < 2 | ||||
else: # two bytes per component | else: # two bytes per component | ||||
val = int(comp, 16) | val = int(comp, 16) | ||||
sub[x].append(val >> 8) | sub[x].append(val >> 8) | ||||
sub[x].append(val & 0xff) | sub[x].append(val & 0xff) | ||||
nullbytes = 16 - len(sub[0]) - len(sub[1]) | nullbytes = 16 - len(sub[0]) - len(sub[1]) | ||||
assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0)) | assert (x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0) | ||||
addr = sub[0] + ([0] * nullbytes) + sub[1] | addr = sub[0] + ([0] * nullbytes) + sub[1] | ||||
else: | else: | ||||
raise ValueError('Could not parse address {}'.format(addr)) | raise ValueError('Could not parse address {}'.format(addr)) | ||||
return bytearray(addr).hex() | return bytearray(addr).hex() | ||||
def test_ipv6_local(): | def test_ipv6_local(): | ||||
''' | ''' | ||||
Show All 12 Lines |