Skip to content

ipv6 is not supported #96

@clayg

Description

@clayg

mostly bind does the right thing if you set AF_INET6 as the family type - maybe try that as a fallback?

diff --git a/pystatsd/server.py b/pystatsd/server.py
index 40118c8..0bb9f9a 100644
--- a/pystatsd/server.py
+++ b/pystatsd/server.py
@@ -300,8 +300,23 @@ class Server(object):
     def serve(self, hostname='', port=8125):
         assert type(port) is int, 'port is not an integer: %s' % (port)
         addr = (hostname, port)
-        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        self._sock.bind(addr)
+        try:
+            self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+            self._sock.bind(addr)
+        except socket.gaierror as e:
+            if e.errno not in (
+                    # Address family for hostname not supported
+                    socket.EAI_ADDRFAMILY,
+                    # Name or service not known
+                    socket.EAI_NONAME):
+                raise
+            # IPv6 address calls for (host, port, flowinfo, scopeid)
+            # although, flowinfo and scopeid would default to 0 in
+            # socketmodule.c we're explict here
+            flowinfo = scopeid = 0
+            addr = (hostname, port, flowinfo, scopeid)
+            self._sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+            self._sock.bind(addr)

         import signal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions