]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Set NOSIGPIPE on all sockets.
[meshlink] / src / meshlink.c
index d3cf36ad5e5801fdaae0d8591520841cea230385..a5d8d43121b025cf1c7b5993c93b4f464d31e675 100644 (file)
@@ -268,6 +268,11 @@ char *meshlink_get_external_address_for_family(meshlink_handle_t *mesh, int fami
 
                int s = socket_in_netns(aip->ai_family, aip->ai_socktype, aip->ai_protocol, mesh->netns);
 
+#ifdef SO_NOSIGPIPE
+               int nosigpipe = 1;
+               setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
                if(s >= 0) {
                        set_timeout(s, 5000);
 
@@ -2905,6 +2910,11 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
                                        continue;
                                }
 
+#ifdef SO_NOSIGPIPE
+                               int nosigpipe = 1;
+                               setsockopt(state.sock, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
                                set_timeout(state.sock, 5000);
 
                                if(connect(state.sock, aip->ai_addr, aip->ai_addrlen)) {