From 1f530ff8f103bf21d548928274ab534f12bc28ac Mon Sep 17 00:00:00 2001 From: breakwa11 Date: Sat, 20 Jun 2015 17:56:33 +0800 Subject: [PATCH] fix udp ipv6 --- shadowsocks/tcprelay.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 5fa9d8b..d86c988 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -94,6 +94,8 @@ BUF_SIZE = 32 * 1024 class TCPRelayHandler(object): + support_ipv6 = None + def __init__(self, server, fd_to_handlers, loop, local_sock, config, dns_resolver, is_local): self._server = server @@ -351,13 +353,21 @@ 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: + def _has_ipv6_addr(self, addr_list): + for item in addr_list: + if type(item) is list: + if self._has_ipv6_addr(item): + return True + elif ':' in item: return True return False + def _is_support_ipv6(self): + if TCPRelayHandler.support_ipv6 is None: + local = socket.gethostbyaddr(socket.gethostname()) + TCPRelayHandler.support_ipv6 = self._has_ipv6_addr(local) + return TCPRelayHandler.support_ipv6 + def _create_remote_socket(self, ip, port): if self._remote_udp: if self._is_support_ipv6():