# HG changeset patch # User d3v11 # Date 1352047364 0 # Node ID fea68ff4c04a94ac502a49275bd8b6a5981f3f7d # Parent c6bf58b459dd1d2bdf9d3fa6399cc7506915e49d [quicktun.socks4a] more simple diff -r c6bf58b459dd -r fea68ff4c04a contrib/quicktun.socks4a/quicktun.socks4a --- a/contrib/quicktun.socks4a/quicktun.socks4a Sun Nov 04 15:37:45 2012 +0000 +++ b/contrib/quicktun.socks4a/quicktun.socks4a Sun Nov 04 16:42:44 2012 +0000 @@ -28,9 +28,11 @@ if REMOTE_FLOAT==0: tun = subprocess.Popen ( - [ 'socat','stdio','socks4a:'+SOCKS_ADDRESS+':' - +DST_ADDRESS+':'+DST_PORT - +',socksport='+SOCKS_PORT + [ 'socat', + 'STDIO', + 'SOCKS4A:' + +SOCKS_ADDRESS+':'+DST_ADDRESS+':'+DST_PORT + +',SOCKSPORT='+SOCKS_PORT, ], stdout = subprocess.PIPE, stdin = subprocess.PIPE, ) @@ -41,23 +43,21 @@ tun.stdout.fileno(),select.POLLIN|select.POLLPRI) if REMOTE_FLOAT==1: - tcp = socket.socket ( - socket.AF_INET,socket.SOCK_STREAM) - tcp.setsockopt (socket.SOL_SOCKET,socket.SO_REUSEADDR,1) - tcp.setblocking (0) - tcp.bind ((LOCAL_ADDRESS,LOCAL_PORT)) - tcp.listen (1) - tcp_poll = select.poll () - tcp_poll.register (tcp.fileno(),select.POLLIN|select.POLLPRI) - - while len(tcp_poll.poll(65536))>0: - tun = tcp.accept ()[0] - tun_stdout = tun.fileno () - tun_stdin = tun.fileno () - tun_poll = select.poll () - tun_poll.register ( - tun.fileno(),select.POLLIN|select.POLLPRI) - break + tun = subprocess.Popen ( + [ 'socat', + 'TCP-LISTEN:' + +str(LOCAL_PORT)+',BIND='+LOCAL_ADDRESS + +',REUSEADDR', + 'UDP-CONNECT:'+LOCAL_ADDRESS+':' + +str(LOCAL_PORT), + ], + stdout = subprocess.PIPE, + stdin = subprocess.PIPE, ) + tun_stdout = tun.stdout.fileno () + tun_stdin = tun.stdin.fileno () + tun_poll = select.poll () + tun_poll.register ( + tun.stdout.fileno(),select.POLLIN|select.POLLPRI) fcntl.fcntl (tun_stdin,fcntl.F_SETFL,fcntl.fcntl (tun_stdin,fcntl.F_GETFL)&~os.O_NONBLOCK|os.O_NONBLOCK) @@ -66,7 +66,8 @@ (tun_stdout,fcntl.F_GETFL)&~os.O_NONBLOCK|os.O_NONBLOCK) tun = subprocess.Popen ( - ['/usr/sbin/quicktun.'+PROTOCOL], + [ '/usr/sbin/quicktun.'+PROTOCOL, + ], stdout = subprocess.PIPE, stdin = subprocess.PIPE, )