Skip to content

Commit 0849a9b

Browse files
valentin benozillomcipperly
authored andcommitted
Fix how to check if the host is IPv6, work with domain name
PIP8 ok Signed-off-by: Matt Cipperly <[email protected]>
1 parent 43efa0d commit 0849a9b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

fluent/sender.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,13 @@ def close(self):
121121

122122
self._close()
123123
self.pendings = None
124-
125-
def _host_is_ipv6(self) :
126-
try :
127-
socket.inet_pton(socket.AF_INET6, self.host)
128-
return True
129-
except :
130-
try :
131-
socket.inet_aton(self.host)
132-
return False
133-
except Exception as e:
134-
raise e
124+
125+
def _is_ipv6_host(self):
126+
try:
127+
socket.getaddrinfo(self.host, None, socket.AF_INET6)
128+
return True
129+
except socket.error:
130+
return False
135131

136132
def _make_packet(self, label, timestamp, data):
137133
if label:
@@ -214,10 +210,12 @@ def _reconnect(self):
214210
sock.settimeout(self.timeout)
215211
sock.connect(self.host[len('unix://'):])
216212
else:
217-
if self._host_is_ipv6() :
218-
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
219-
else :
220-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
213+
if self._host_is_ipv6():
214+
sock = socket.socket(socket.AF_INET6,
215+
socket.SOCK_STREAM)
216+
else:
217+
sock = socket.socket(socket.AF_INET,
218+
socket.SOCK_STREAM)
221219
sock.settimeout(self.timeout)
222220
# This might be controversial and may need to be removed
223221
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

0 commit comments

Comments
 (0)