Move client._islocal() to helpers.islocal() in preparation for sharing.

This commit is contained in:
Avery Pennarun 2011-01-26 04:32:00 -08:00
parent ebfc3703ec
commit 7f3c522c56
2 changed files with 18 additions and 18 deletions

View File

@ -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

View File

@ -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