import socket


def pack_addr(addr):
    """Pack a (host, port) tuple into the format expected by socket methods."""
    if isinstance(addr, (bytes, bytearray)):
        return addr

    if len(addr) != 2:
        raise NotImplementedError("Only IPv4/v6 supported")

    addrinfo = socket.getaddrinfo(addr[0], addr[1])
    return addrinfo[0][4]