diff --git a/CHANGES b/CHANGES index 0994c32..a1d6fca 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1.4.3 2014-05-13 +- Fix Windows + 1.4.2 2014-05-10 - Add salsa20-ctr cipher diff --git a/README.md b/README.md index 23b206a..857de7c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ shadowsocks =========== -Current version: 1.4.2 [![Build Status][1]][0] +Current version: 1.4.3 [![Build Status][1]][0] shadowsocks is a lightweight tunnel proxy which can help you get through firewalls. diff --git a/setup.py b/setup.py index 3193fa9..1068689 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open('README.rst') as f: setup( name="shadowsocks", - version="1.4.2", + version="1.4.3", license='MIT', description="a lightweight tunnel proxy", author='clowwindy', diff --git a/shadowsocks/utils.py b/shadowsocks/utils.py index 4da4a8b..f5bcba3 100644 --- a/shadowsocks/utils.py +++ b/shadowsocks/utils.py @@ -22,9 +22,53 @@ # SOFTWARE. import os +import socket import logging +def inet_ntop(family, ipstr): + if family == socket.AF_INET: + return socket.inet_ntoa(ipstr) + elif family == socket.AF_INET6: + v6addr = ':'.join(('%02X%02X' % (ord(i), ord(j))) + for i, j in zip(ipstr[::2], ipstr[1::2])) + return v6addr + + +def inet_pton(family, addr): + if family == socket.AF_INET: + return socket.inet_aton(addr) + elif family == socket.AF_INET6: + if '.' in addr: # a v4 addr + v4addr = addr[addr.rindex(':') + 1:] + v4addr = socket.inet_aton(v4addr) + v4addr = map(lambda x: ('%02X' % ord(x)), v4addr) + v4addr.insert(2, ':') + newaddr = addr[:addr.rindex(':') + 1] + ''.join(v4addr) + return inet_pton(family, newaddr) + dbyts = [0] * 8 # 8 groups + grps = addr.split(':') + for i, v in enumerate(grps): + if v: + dbyts[i] = int(v, 16) + else: + for j, w in enumerate(grps[::-1]): + if w: + dbyts[7 - j] = int(w, 16) + else: + break + break + return ''.join((chr(i // 256) + chr(i % 256)) for i in dbyts) + else: + raise RuntimeError("What family?") + + +if not hasattr(socket, 'inet_pton'): + socket.inet_pton = inet_pton + +if not hasattr(socket, 'inet_ntop'): + socket.inet_ntop = inet_ntop + def find_config(): config_path = 'config.json' if os.path.exists(config_path):