set default socket options: IPV6_V6ONLY, SO_REUSEADDR
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- 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");