'Return the host and port packed for the SOCKS5 protocol,
and the resolved address as a tuple object.'

def _write_SOCKS5_address(self, addr, file):

    (host, port) = addr
    (proxy_type, _, _, rdns, username, password) = self.proxy
    try:
        addr_bytes = socket.inet_aton(host)
        file.write(('\x01' + addr_bytes))
        host = socket.inet_ntoa(addr_bytes)
    except socket.error:
        if rdns:
            host_bytes = host.encode('idna')
            file.write((('\x03' + chr(len(host_bytes)).encode()) + host_bytes))
        else:
            addr_bytes = socket.inet_aton(socket.gethostbyname(host))
            file.write(('\x01' + addr_bytes))
            host = socket.inet_ntoa(addr_bytes)
    file.write(struct.pack('>H', port))
    return (host, port)
