Ensure IPv6 addresses are surrounded by '[]' (#425)

This commit is contained in:
Lonami Exo 2017-11-16 13:47:15 +01:00
parent edd73ed69a
commit 4ddbc78699

View File

@ -37,6 +37,12 @@ class TcpClient:
'timeout' must be given in seconds
"""
if ':' in ip: # IPv6
# The address needs to be surrounded by [] as discussed on PR#425
if not ip.startswith('['):
ip = '[' + ip
if not ip.endswith(']'):
ip = ip + ']'
mode, address = socket.AF_INET6, (ip, port, 0, 0)
else:
mode, address = socket.AF_INET, (ip, port)