From 17122c299c24a22f56c093139264865e7faa5982 Mon Sep 17 00:00:00 2001 From: breakwa11 Date: Tue, 16 Jun 2015 21:55:36 +0800 Subject: [PATCH] fix udp ipv6 --- shadowsocks/tcprelay.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 66fef68..5fa9d8b 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -351,14 +351,18 @@ class TCPRelayHandler(object): # TODO use logging when debug completed self.destroy() + def _is_support_ipv6(self): + local = socket.gethostbyaddr(socket.gethostname()) + for ip in local: + if ':' in ip: + return True + return False + def _create_remote_socket(self, ip, port): - addrs = None if self._remote_udp: - try: + if self._is_support_ipv6(): addrs = socket.getaddrinfo("::", 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP) - except Exception as e: - pass - if addrs is None: + else: 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)