use IPV6_V6ONLY socket option on linux

Thu, 13 Oct 2022 19:26:15 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 13 Oct 2022 19:26:15 +0200
changeset 398
83234bc3bee9
parent 397
f202a655f4c2
child 399
05d4e75d1912

use IPV6_V6ONLY socket option on linux

src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httplistener.c	Thu Oct 13 18:46:00 2022 +0200
+++ b/src/server/daemon/httplistener.c	Thu Oct 13 19:26:15 2022 +0200
@@ -310,7 +310,7 @@
         perror("Error: http_listener_new: socket v6");
         return NULL;
     }
-
+    
     int o = 1;
     setsockopt(
             listener->server_socket,
@@ -323,6 +323,16 @@
             SOL_SOCKET, SO_REUSEADDR,
             &o,
             sizeof(int));
+    
+#ifdef LINUX
+    o = 1;
+    setsockopt(
+            listener->server_socket6,
+            IPPROTO_IPV6,
+            IPV6_V6ONLY,
+            &o,
+            sizeof(int));
+#endif
 
     /* bind server socket to address */
     if(bind(listener->server_socket, (struct sockaddr*)&servaddr, sizeof(servaddr))){
@@ -354,11 +364,11 @@
     log_ereport(LOG_INFORM, "start listener on port %d", listener->port);
 
     if (listen(listener->server_socket, 256) == -1) {
-        log_ereport(LOG_FAILURE, "http_listener_start: listen failed");
+        log_ereport(LOG_FAILURE, "http_listener_start: listen failed: %s", strerror(errno));
         return -1;
     }
     if (listen(listener->server_socket6, 256) == -1) {
-        log_ereport(LOG_FAILURE, "http_listener_start: listen failed");
+        log_ereport(LOG_FAILURE, "http_listener_start: listen v6 failed: %s", strerror(errno));
         return -1;
     }
 

mercurial