From 65f01f92595ea5ff907746a30c62ce08e88c209e Mon Sep 17 00:00:00 2001 From: igutidze <125119026+igutidze@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:43:43 +0400 Subject: [PATCH 1/4] util.c: log failed attempts to set SO_RCVBUF size --- util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index 61b36b4..943f923 100644 --- a/util.c +++ b/util.c @@ -830,7 +830,11 @@ int OpenSocketSafe( const char *_psz_arg, int i_ttl, uint16_t i_bind_port, /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to * avoid packet loss caused by scheduling problems */ i = 0x80000; - setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, (void *) &i, sizeof( i ) ); + if ( setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, (void *) &i, sizeof( i ) ) < 0 ) + { + msg_Err( NULL, "couldn't adjust socket receive buffer size (%s)", + strerror(errno) ); + } /* Join the multicast group if the socket is a multicast address */ if ( bind_addr.ss.ss_family == AF_INET From 35571caef8a594c0ee869aea590b4813ae00b85a Mon Sep 17 00:00:00 2001 From: igutidze <125119026+igutidze@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:10:11 +0400 Subject: [PATCH 2/4] util.c: make sure requested SO_RCVBUF is applied --- util.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 943f923..addf904 100644 --- a/util.c +++ b/util.c @@ -558,6 +558,7 @@ int OpenSocketSafe( const char *_psz_arg, int i_ttl, uint16_t i_bind_port, in_addr_t i_raw_srcaddr = INADDR_ANY; int i_raw_srcport = 0; char *psz_ifname = NULL; + int i_rcvbufsz = 0x80000; #ifdef __FreeBSD__ int hincl = 1; #endif @@ -827,13 +828,24 @@ int OpenSocketSafe( const char *_psz_arg, int i_ttl, uint16_t i_bind_port, if ( !*pb_tcp ) { - /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to - * avoid packet loss caused by scheduling problems */ - i = 0x80000; + /* Increase the receive buffer size to avoid packet loss caused by scheduling + * problems */ + i = i_rcvbufsz; if ( setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, (void *) &i, sizeof( i ) ) < 0 ) { - msg_Err( NULL, "couldn't adjust socket receive buffer size (%s)", + msg_Err( NULL, "couldn't adjust socket receive buffer size to %d (%s)", + i_rcvbufsz, strerror(errno) ); + } + size_t len = sizeof(i); + if ( getsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, (void *) &i, (void *) &len ) < 0 ) + { + msg_Err( NULL, "couldn't retrieve socket receive buffer size (%s)", strerror(errno) ); + } else { + /* setsockopt doubles requested value, getsockopt returns the doubled value */ + if ( i / 2 < i_rcvbufsz ) + msg_Err( NULL, "tried to adjust receive buffer to %d but ended up with %d", + i_rcvbufsz, i / 2); } /* Join the multicast group if the socket is a multicast address */ From 9509ed152f085eeb7f35faca1a264377adf19d8e Mon Sep 17 00:00:00 2001 From: igutidze <125119026+igutidze@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:13:44 +0400 Subject: [PATCH 3/4] util.c: add rcvbufsz command line option --- util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util.c b/util.c index addf904..d7d9e51 100644 --- a/util.c +++ b/util.c @@ -682,6 +682,8 @@ int OpenSocketSafe( const char *_psz_arg, int i_ttl, uint16_t i_bind_port, i_raw_srcport = strtol( ARG_OPTION("srcport="), NULL, 0 ); else if ( IS_OPTION("fd=") ) i_fd = strtol( ARG_OPTION("fd="), NULL, 0 ); + else if ( IS_OPTION("rcvbufsz=") ) + i_rcvbufsz = strtol( ARG_OPTION("rcvbufsz="), NULL, 0 ); else msg_Warn( NULL, "unrecognized option %s", psz_token2 ); From 75d14c91156cb6d450eae6467b0a7ff7aec2f5ee Mon Sep 17 00:00:00 2001 From: igutidze <125119026+igutidze@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:17:09 +0400 Subject: [PATCH 4/4] Update README --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index e08d7c1..8d71076 100644 --- a/README +++ b/README @@ -76,6 +76,7 @@ Options include: /tcp (binds a TCP socket instead of UDP) /srcaddr=XXX.XXX.XXX.XXX (source address for raw packets) /srcportr=XX (source port for raw packets) + /rcvbufsz=XX (UDP receive buffer size) Example: 239.255.0.1:5004/ttl=64