Skip to content

Commit 47dbb7c

Browse files
committed
Add SO_REUSEPORT support for macOS/BSD NetSIO compatibility
On macOS and BSD systems, SO_REUSEPORT is required for multiple processes to bind to the same UDP port (9997 for NetSIO). Without this flag, only the first process to bind succeeds, preventing bidirectional NetSIO communication. This change: - Adds SO_REUSEPORT socket option for macOS/BSD builds - Maintains compatibility with existing code (guarded by #ifdef) - Uses standard #ifdef SO_REUSEPORT guard for automatic platform detection - no build system changes required. Works on macOS, BSD, and modern Linux. - Enables proper NetSIO operation when emulator and FujiNet-PC both need to bind to port 9997
1 parent 571e594 commit 47dbb7c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/tcpip/fnUDP.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ bool fnUDP::begin(in_addr_t address, uint16_t port)
9999
return false;
100100
}
101101

102+
/* On macOS/BSD, SO_REUSEPORT is required to allow multiple processes to bind to the same port */
103+
#ifdef SO_REUSEPORT
104+
if (setsockopt(udp_server, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0)
105+
{
106+
Debug_printf("could not set SO_REUSEPORT: %d\r\n", compat_getsockerr());
107+
}
108+
#endif
109+
102110
struct sockaddr_in addr;
103111
memset(&addr, 0, sizeof(addr));
104112

0 commit comments

Comments
 (0)