diff options
author | Rob Austein <sra@hactrn.net> | 2013-06-12 19:07:57 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2013-06-12 19:07:57 +0000 |
commit | 72075c4103ced3973eed75b74d012bc4046d8cde (patch) | |
tree | d8871b5bb9ae539aea0ad6289917cac5e9b241a8 /rtr-origin | |
parent | d3b0ac482e88d07235184f159c52365922e995c6 (diff) |
Do IPv6 client support properly, using getaddrinfo().
svn path=/trunk/; revision=5397
Diffstat (limited to 'rtr-origin')
-rwxr-xr-x | rtr-origin/rtr-origin.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/rtr-origin/rtr-origin.py b/rtr-origin/rtr-origin.py index a3bde86e..a1013528 100755 --- a/rtr-origin/rtr-origin.py +++ b/rtr-origin/rtr-origin.py @@ -1238,12 +1238,19 @@ class client_channel(pdu_channel): Set up TCP connection and start listening for first PDU. """ blather("[Starting raw TCP connection to %s:%s]" % (host, port)) - if ":" in host: - s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) - else: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((host, int(port))) - return cls(sock = s, proc = None, killsig = None) + for ai in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM): + af, socktype, proto, cn, sa = ai + try: + s = socket.socket(af, socktype, proto) + except: + continue + try: + s.connect(sa) + except: + s.close() + continue + return cls(sock = s, proc = None, killsig = None) + sys.exit("Couldn't connect to host %s port %s" % (host, port)) @classmethod def loopback(cls): |