def name_to_ipv6(addr):
    if ((len(addr) > 6) and addr.endswith('.onion')):
        vchAddr = b32decode(addr[0:(- 6)], True)
        if (len(vchAddr) != (16 - len(pchOnionCat))):
            raise ValueError(('Invalid onion %s' % s))
        return (pchOnionCat + vchAddr)
    elif ('.' in addr):
        return (pchIPv4 + bytearray((int(x) for x in addr.split('.'))))
    elif (':' in addr):
        sub = [[], []]
        x = 0
        addr = addr.split(':')
        for (i, comp) in enumerate(addr):
            if (comp == ''):
                if ((i == 0) or (i == (len(addr) - 1))):
                    continue
                x += 1
                assert (x < 2)
            else:
                val = int(comp, 16)
                sub[x].append((val >> 8))
                sub[x].append((val & 255))
        nullbytes = ((16 - len(sub[0])) - len(sub[1]))
        assert (((x == 0) and (nullbytes == 0)) or ((x == 1) and (nullbytes > 0)))
        return bytearray(((sub[0] + ([0] * nullbytes)) + sub[1]))
    elif addr.startswith('0x'):
        return (pchIPv4 + bytearray(reversed(a2b_hex(addr[2:]))))
    else:
        raise ValueError(('Could not parse address %s' % addr))
def name_to_ipv6(addr):
    if ((len(addr) > 6) and addr.endswith('.onion')):
        vchAddr = b32decode(addr[0:(- 6)], True)
        if (len(vchAddr) != (16 - len(pchOnionCat))):
            raise ValueError(('Invalid onion %s' % s))
        return (pchOnionCat + vchAddr)
    elif ('.' in addr):
        return (pchIPv4 + bytearray((int(x) for x in addr.split('.'))))
    elif (':' in addr):
        sub = [[], []]
        x = 0
        addr = addr.split(':')
        for (i, comp) in enumerate(addr):
            if (comp == ):
                if ((i == 0) or (i == (len(addr) - 1))):
                    continue
                x += 1
                assert (x < 2)
            else:
                val = int(comp, 16)
                sub[x].append((val >> 8))
                sub[x].append((val & 255))
        nullbytes = ((16 - len(sub[0])) - len(sub[1]))
        assert (((x == 0) and (nullbytes == 0)) or ((x == 1) and (nullbytes > 0)))
        return bytearray(((sub[0] + ([0] * nullbytes)) + sub[1]))
    elif addr.startswith('0x'):
        return (pchIPv4 + bytearray(reversed(a2b_hex(addr[2:]))))
    else:
        raise ValueError(('Could not parse address %s' % addr))