From d065dba34f693b44001fa3d1285c8858dd6634f2 Mon Sep 17 00:00:00 2001 From: breakwa11 Date: Tue, 16 Jun 2015 13:13:19 +0800 Subject: [PATCH] merge manyuser udp ipv6 bug fix --- shadowsocks/tcprelay.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 18aa1f5..66fef68 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -209,7 +209,7 @@ class TCPRelayHandler(object): if addrs: af, socktype, proto, canonname, server_addr = addrs[0] data = data[header_length:] - sock.sendto(data, server_addr) + sock.sendto(data, (server_addr[0], dest_port)) except Exception as e: trace = traceback.format_exc() @@ -352,8 +352,14 @@ class TCPRelayHandler(object): self.destroy() def _create_remote_socket(self, ip, port): + addrs = None if self._remote_udp: - addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_DGRAM, socket.SOL_UDP) + try: + addrs = socket.getaddrinfo("::", 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP) + except Exception as e: + pass + if addrs is None: + addrs = socket.getaddrinfo("0.0.0.0", 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP) else: addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: