commit 60b6fd399d0af62c043e0a98f9e2ee141c052eb8
parent 69756422271ad06e3d3592eb7002c60927f77704
Author: ThomasV <thomasv@gitorious>
Date: Fri, 13 Dec 2013 09:22:39 +0100
exit gracefully if host cannot be resolved. Fixes #488
Diffstat:
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/interface.py b/lib/interface.py
@@ -315,7 +315,13 @@ class Interface(threading.Thread):
is_new = True
# get server certificate.
# Do not use ssl.get_server_certificate because it does not work with proxy
- for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ try:
+ l = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM)
+ except socket.gaierror:
+ print_error("error: cannot resolve", self.host)
+ return
+
+ for res in l:
try:
s = socket.socket( res[0], socket.SOCK_STREAM )
s.connect(res[4])
@@ -346,7 +352,13 @@ class Interface(threading.Thread):
else:
is_new = False
- for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ try:
+ addrinfo = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM)
+ except socket.gaierror:
+ print_error("error: cannot resolve", self.host)
+ return
+
+ for res in addrinfo:
try:
s = socket.socket( res[0], socket.SOCK_STREAM )
s.settimeout(2)