Commit 7f3c522c authored by Avery Pennarun's avatar Avery Pennarun

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

parent ebfc3703
...@@ -6,21 +6,6 @@ from helpers import * ...@@ -6,21 +6,6 @@ from helpers import *
_extra_fd = os.open('/dev/null', os.O_RDONLY) _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): def got_signal(signum, frame):
log('exiting on signal %d\n' % signum) log('exiting on signal %d\n' % signum)
sys.exit(1) sys.exit(1)
...@@ -283,7 +268,7 @@ def _main(listener, fw, ssh_cmd, remotename, python, latency_control, ...@@ -283,7 +268,7 @@ def _main(listener, fw, ssh_cmd, remotename, python, latency_control,
dstip = original_dst(sock) dstip = original_dst(sock)
debug1('Accept: %s:%r -> %s:%r.\n' % (srcip[0],srcip[1], debug1('Accept: %s:%r -> %s:%r.\n' % (srcip[0],srcip[1],
dstip[0],dstip[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") debug1("-- ignored: that's my address!\n")
sock.close() sock.close()
return return
......
import sys, os import sys, os, socket
logprefix = '' logprefix = ''
verbose = 0 verbose = 0
...@@ -57,4 +57,19 @@ def resolvconf_random_nameserver(): ...@@ -57,4 +57,19 @@ def resolvconf_random_nameserver():
else: else:
return '127.0.0.1' 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment