

@staticmethod
def _decode_address(addr, family):
    'Accept an "ip:port" address as displayed in /proc/net/*\n        and convert it into a human readable form, like:\n\n        "0500000A:0016" -> ("10.0.0.5", 22)\n        "0000000000000000FFFF00000100007F:9E49" -> ("::ffff:127.0.0.1", 40521)\n\n        The IP address portion is a little or big endian four-byte\n        hexadecimal number; that is, the least significant byte is listed\n        first, so we need to reverse the order of the bytes to convert it\n        to an IP address.\n        The port is represented as a two-byte hexadecimal number.\n\n        Reference:\n        http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html\n        '
    (ip, port) = addr.split(':')
    port = int(port, 16)
    if PY3:
        ip = ip.encode('ascii')
    if (not port):
        return ()
    if (family == socket.AF_INET):
        if (sys.byteorder == 'little'):
            ip = socket.inet_ntop(family, base64.b16decode(ip)[::(- 1)])
        else:
            ip = socket.inet_ntop(family, base64.b16decode(ip))
    else:
        ip = base64.b16decode(ip)
        if (sys.byteorder == 'little'):
            ip = socket.inet_ntop(socket.AF_INET6, struct.pack('>4I', *struct.unpack('<4I', ip)))
        else:
            ip = socket.inet_ntop(socket.AF_INET6, struct.pack('<4I', *struct.unpack('<4I', ip)))
    return (ip, port)

dataset/ETHPy150Open packages/psutil/psutil/_pslinux.py Process._decode_address/original