Fix onionbindip for some systems with IPv6

- in some cases when IPv6 stack is available and onionbindip is an IPv4
  address, socket.bind doesn't change the bound address, ending up
  listening on everything
This commit is contained in:
Peter Šurda 2017-05-10 20:01:23 +02:00
parent 90ef2d54e1
commit fd2603247d
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 4 additions and 0 deletions

View File

@ -33,6 +33,10 @@ class singleListener(threading.Thread, StoppableThread):
HOST = '' # Symbolic name meaning all available interfaces
# If not sockslisten, but onionhostname defined, only listen on localhost
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'sockslisten') and ".onion" in BMConfigParser().get('bitmessagesettings', 'onionhostname'):
if family == socket.AF_INET6 and "." in BMConfigParser().get('bitmessagesettings', 'onionbindip'):
raise socket.error(errno.EINVAL, "Invalid mix of IPv4 and IPv6")
elif family == socket.AF_INET and ":" in BMConfigParser().get('bitmessagesettings', 'onionbindip'):
raise socket.error(errno.EINVAL, "Invalid mix of IPv4 and IPv6")
HOST = BMConfigParser().get('bitmessagesettings', 'onionbindip')
PORT = BMConfigParser().getint('bitmessagesettings', 'port')
sock = socket.socket(family, socket.SOCK_STREAM)