summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2011-01-26 04:32:00 -0800
committerAvery Pennarun <apenwarr@gmail.com>2011-01-26 05:25:26 -0800
commit7f3c522c564b79e0f96a25c7a94705a99a65d09e (patch)
treed25aeb5a05a9bb9492f7fa0eb533d321e3e96e61
parentebfc3703ec209af8ec818394d5d623ead1a18d1d (diff)
Move client._islocal() to helpers.islocal() in preparation for sharing.
-rw-r--r--client.py17
-rw-r--r--helpers.py19
2 files changed, 18 insertions, 18 deletions
diff --git a/client.py b/client.py
index a824bff..4f47226 100644
--- a/client.py
+++ b/client.py
@@ -6,21 +6,6 @@ from helpers import *
_extra_fd = os.open('/dev/null', os.O_RDONLY)
-def _islocal(ip):
- sock = socket.socket()
- try:
- try:
- sock.bind((ip, 0))
- except socket.error, e:
- if e.args[0] == errno.EADDRNOTAVAIL:
- return False # not a local IP
- else:
- raise
- finally:
- sock.close()
- return True # it's a local IP, or there would have been an error
-
-
def got_signal(signum, frame):
log('exiting on signal %d\n' % signum)
sys.exit(1)
@@ -283,7 +268,7 @@ def _main(listener, fw, ssh_cmd, remotename, python, latency_control,
dstip = original_dst(sock)
debug1('Accept: %s:%r -> %s:%r.\n' % (srcip[0],srcip[1],
dstip[0],dstip[1]))
- if dstip[1] == listener.getsockname()[1] and _islocal(dstip[0]):
+ if dstip[1] == listener.getsockname()[1] and islocal(dstip[0]):
debug1("-- ignored: that's my address!\n")
sock.close()
return
diff --git a/helpers.py b/helpers.py
index d8d7e85..c169d0c 100644
--- a/helpers.py
+++ b/helpers.py
@@ -1,4 +1,4 @@
-import sys, os
+import sys, os, socket
logprefix = ''
verbose = 0
@@ -57,4 +57,19 @@ def resolvconf_random_nameserver():
else:
return '127.0.0.1'
-
+
+def islocal(ip):
+ sock = socket.socket()
+ try:
+ try:
+ sock.bind((ip, 0))
+ except socket.error, e:
+ if e.args[0] == errno.EADDRNOTAVAIL:
+ return False # not a local IP
+ else:
+ raise
+ finally:
+ sock.close()
+ return True # it's a local IP, or there would have been an error
+
+