[statsd_logger] handle ipv6 addresses
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 26 Jun 2015 14:30:24 +0200
changeset 10478 026b4ee032fb
parent 10477 ee21c559f94f
child 10481 6ac4b1726e9f
[statsd_logger] handle ipv6 addresses
statsd_logger.py
--- a/statsd_logger.py	Mon May 04 17:37:43 2015 +0200
+++ b/statsd_logger.py	Fri Jun 26 14:30:24 2015 +0200
@@ -75,8 +75,17 @@
                     couple (ip, port).
     """
     global _bucket, _address, _socket
+    packed = None
+    for family in (socket.AF_INET6, socket.AF_INET):
+        try:
+            packed = socket.inet_pton(family, address)
+            break
+        except socket.error:
+            continue
+    if packed is None:
+        return
     _bucket, _address = bucket, address
-    _socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    _socket = socket.socket(family, socket.SOCK_DGRAM)
 
 
 def statsd_c(context, n=1):