From 96f40f052d92d65edce40540907581c1fa236318 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jul 2026 14:14:27 +0200 Subject: [PATCH 1/3] Set SO_BROADCAST --- src/shared/net/netraw.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/shared/net/netraw.cpp b/src/shared/net/netraw.cpp index 0f41229a..09b21e2f 100644 --- a/src/shared/net/netraw.cpp +++ b/src/shared/net/netraw.cpp @@ -93,9 +93,9 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ if(flags < 0) flags = 0; fcntl(fd, F_SETFL, flags | (blocking ? 0 : O_NONBLOCK)); + int yes = 1; if (share_port_for_multicasting) { - int reuse=1; - if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse,sizeof(reuse))!=0) { + if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&yes, sizeof(yes))!=0) { fprintf(stderr,"ERROR WHEN SETTING SO_REUSEADDR ON UDP SOCKET\n"); fflush(stderr); } @@ -106,7 +106,6 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ } if (multicast_include_localhost) { - int yes = 1; // allow packets to be received on this host if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&yes, sizeof(yes))!=0) { fprintf(stderr,"ERROR WHEN SETTING IP_MULTICAST_LOOP ON UDP SOCKET\n"); @@ -121,6 +120,13 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ return false; } + ret = setsockopt(fd, IPPROTO_IP, SO_BROADCAST, &yes, sizeof(yes)); + if(ret != 0) + { + printf("ERROR %d WHEN SETTING SO_BROADCAST\n", ret); + return false; + } + // bind socket to port if nonzero if(port != 0){ sockaddr_in sockname; From ad4f16bc72f7a040f53f3a3e4e1e53eae7c1a9d1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jul 2026 14:31:06 +0200 Subject: [PATCH 2/3] Test yes changes --- src/shared/net/netraw.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shared/net/netraw.cpp b/src/shared/net/netraw.cpp index 09b21e2f..1b9ab5f5 100644 --- a/src/shared/net/netraw.cpp +++ b/src/shared/net/netraw.cpp @@ -107,6 +107,7 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ if (multicast_include_localhost) { // allow packets to be received on this host + yes = 1; if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&yes, sizeof(yes))!=0) { fprintf(stderr,"ERROR WHEN SETTING IP_MULTICAST_LOOP ON UDP SOCKET\n"); fflush(stderr); @@ -120,6 +121,7 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ return false; } + yes = 1; ret = setsockopt(fd, IPPROTO_IP, SO_BROADCAST, &yes, sizeof(yes)); if(ret != 0) { From 2e8ce055fa246882486053dfa83afe60b2aadcfe Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Jul 2026 14:37:21 +0200 Subject: [PATCH 3/3] Fix SO_BROADCAST --- src/shared/net/netraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/net/netraw.cpp b/src/shared/net/netraw.cpp index 1b9ab5f5..03612e98 100644 --- a/src/shared/net/netraw.cpp +++ b/src/shared/net/netraw.cpp @@ -122,7 +122,7 @@ bool UDP::open(int port, bool share_port_for_multicasting, bool multicast_includ } yes = 1; - ret = setsockopt(fd, IPPROTO_IP, SO_BROADCAST, &yes, sizeof(yes)); + ret = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes)); if(ret != 0) { printf("ERROR %d WHEN SETTING SO_BROADCAST\n", ret);