set default socket options: IPV6_V6ONLY, SO_REUSEADDR
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 14:49:47 +0100
changeset 159 44823a881da1
parent 158 2cddd4d26139
child 160 26414889dded
set default socket options: IPV6_V6ONLY, SO_REUSEADDR committer: Markus Bröker <mbroeker@largo.homelinux.org>
ddos/server.c
--- a/ddos/server.c
+++ b/ddos/server.c
@@ -30,7 +30,7 @@
     struct addrinfo hints;
     struct addrinfo *result, *rp;
 
-    int yes = 1;
+    int yes = 1, no = 0;
 
     memset (&hints, 0, sizeof (hints));
     hints.ai_family = AF_UNSPEC;
@@ -48,11 +48,14 @@
             perror ("SOCKET");
             continue;
         }
-
+        // enable rebinding of the socket
         if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (int)) == -1) {
             perror ("setsockopt");
             return -1;
         }
+        // disable IPV6ONLY, eg enable an hybrid socket
+        if (rp->ai_family == AF_INET6)
+            setsockopt (server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof (int));
 
         if ((bind (server_socket, rp->ai_addr, rp->ai_addrlen)) == -1) {
             perror ("BIND");