Skip to content

Commit 43efa0d

Browse files
valentin benozillomcipperly
authored andcommitted
Add compatibility for Ipv6 address
Signed-off-by: Matt Cipperly <[email protected]>
1 parent 7389fb6 commit 43efa0d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fluent/sender.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ 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
124135

125136
def _make_packet(self, label, timestamp, data):
126137
if label:
@@ -203,7 +214,10 @@ def _reconnect(self):
203214
sock.settimeout(self.timeout)
204215
sock.connect(self.host[len('unix://'):])
205216
else:
206-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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)
207221
sock.settimeout(self.timeout)
208222
# This might be controversial and may need to be removed
209223
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

0 commit comments

Comments
 (0)