Commits

Keli Hu committed d5fc300

inet_pton fix for windows

Comments (0)

Files changed (3)

                 client.close()
     raise e
 
+# Some versions of windows don't have socket.inet_pton
+if hasattr(socket, 'inet_pton'):
+    def my_inet_aton(ip_string):
+        af, _, _, _, _ = socket.getaddrinfo(ip_string, 80, 0, socket.SOCK_STREAM)[0]
+        return socket.inet_pton(af, ip_string)
+else:
+    my_inet_aton = socket.inet_aton
+
 def hexstring(s):
     return ' '.join(['%02X' % ord(c) for c in s])
     

pyinstaller/pyinstaller.bat

-python -O C:\pyinstaller\Configure.py
-python -O C:\pyinstaller\Makespec.py --onefile --upx --icon=furion.ico ..\furion.py
-python -O C:\pyinstaller\Build.py furion.spec
-
+python -O C:\pyinstaller\pyinstaller.py --onefile --icon=furion.ico ..\furion.py
+python -O C:\pyinstaller\pyinstaller.py furion.spec
 from Queue import Queue
 from types import *
 
-from helpers import log, make_connection
+from helpers import log, make_connection, my_inet_aton
 
 ####################################
 ## Constants
                                 log.info("Connecting to %s.", domain)
                                 dest = make_connection((domain, port), my_ip)
 
+                            # Connected to upstream/destination
+                            client_ip, client_port = dest.getsockname()
+                            ip_bytes = my_inet_aton(client_ip)                            
+                            port_bytes = struct.pack('!H', client_port)
+                            self.request.sendall('\x05\x00\x00\x01' + ip_bytes + port_bytes)
+                                
+                            stage = CONN_ACCEPTED
+
                         except Exception, e:
                             log.debug('Error when trying to resolve/connect to: %s, reason: %s', (domain, port), e)
                             #traceback.print_exc()
                             self.request.sendall('\x05\x01')
                             raise
 
-
-                        # Connected to upstream/destination
-                        client_ip, client_port = dest.getsockname()
-                        ip_bytes = socket.inet_pton(socket.AF_INET, client_ip)
-                        port_bytes = struct.pack('!H', client_port)
-                        self.request.sendall('\x05\x00\x00\x01' + ip_bytes + port_bytes)
-                                
-                        stage = CONN_ACCEPTED
                         
             # Starting to forward data
             try:
                 self.forward(self.request, dest)
             except Socks5Exception, e:
                 log.debug("Forwarding finished: %s", e)
+            except Exception, e:
+                log.debug('Error when forwarding: %s', e)
+                #traceback.print_exc()
             finally:
                 dest.close()
                 log.info("%d bytes out, %d bytes in. Socks5 session finished %s <-> %s.", self.bytes_out, self.bytes_in, self.client_name, self.server_name)
                     self.authority.usage(self.member_id, self.bytes_in + self.bytes_out)
         except Socks5Exception, e:
             log.debug("Connection closed. Reason: %s", e)
+        except Exception, e:
+            log.debug('Error when proxying: %s', e)
+            #traceback.print_exc()
         finally:
             try:
                 self.request.shutdown(socket.SHUT_RDWR)