Skip to content

ipv6 is not supported #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
clayg opened this issue Jan 26, 2016 · 0 comments
Open

ipv6 is not supported #96

clayg opened this issue Jan 26, 2016 · 0 comments

Comments

@clayg
Copy link

clayg commented Jan 26, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant