@@ -154,7 +154,7 @@ udp_get_solip( void )
154154udp_connection_t *
155155udp_bind ( int subsystem , const char * name ,
156156 const char * bindaddr , int port , const char * multicast_src ,
157- const char * ifname , int rxsize , int txsize )
157+ const char * ifname , int rxsize , int txsize , int bind_fail_allowed )
158158{
159159 int fd , ifindex , reuse = 1 ;
160160 udp_connection_t * uc ;
@@ -186,8 +186,8 @@ udp_bind ( int subsystem, const char *name,
186186
187187 uc -> fd = fd ;
188188
189- /* Mark reuse address */
190- if (setsockopt (fd , SOL_SOCKET , SO_REUSEADDR , & reuse , sizeof (reuse ))) {
189+ /* Mark reuse address, only wanted and required for Multicast in UDP (and TCP, but not here, then) */
190+ if (uc -> multicast && setsockopt (fd , SOL_SOCKET , SO_REUSEADDR , & reuse , sizeof (reuse ))) {
191191 tvherror (subsystem , "%s - failed to reuse address for socket [%s]" ,
192192 name , strerror (errno ));
193193 udp_close (uc );
@@ -207,9 +207,11 @@ udp_bind ( int subsystem, const char *name,
207207 /* Bind useful for receiver subsystem (not for udp streamer) */
208208 if (subsystem != LS_UDP ) {
209209 if (bind (fd , (struct sockaddr * )& uc -> ip , sizeof (struct sockaddr_in ))) {
210- inet_ntop (AF_INET , & IP_AS_V4 (& uc -> ip , addr ), buf , sizeof (buf ));
211- tvherror (subsystem , "%s - cannot bind %s:%hu [e=%s]" ,
212- name , buf , ntohs (IP_AS_V4 (& uc -> ip , port )), strerror (errno ));
210+ if (!bind_fail_allowed ) {
211+ inet_ntop (AF_INET , & IP_AS_V4 (& uc -> ip , addr ), buf , sizeof (buf ));
212+ tvherror (subsystem , "%s - cannot bind %s:%hu [e=%s]" ,
213+ name , buf , ntohs (IP_AS_V4 (& uc -> ip , port )), strerror (errno ));
214+ }
213215 goto error ;
214216 }
215217 }
@@ -280,9 +282,11 @@ udp_bind ( int subsystem, const char *name,
280282
281283 /* Bind */
282284 if (bind (fd , (struct sockaddr * )& uc -> ip , sizeof (struct sockaddr_in6 ))) {
283- inet_ntop (AF_INET6 , & IP_AS_V6 (& uc -> ip , addr ), buf , sizeof (buf ));
284- tvherror (subsystem , "%s - cannot bind %s:%hu [e=%s]" ,
285- name , buf , ntohs (IP_AS_V6 (& uc -> ip , port )), strerror (errno ));
285+ if (!bind_fail_allowed ) {
286+ inet_ntop (AF_INET6 , & IP_AS_V6 (& uc -> ip , addr ), buf , sizeof (buf ));
287+ tvherror (subsystem , "%s - cannot bind %s:%hu [e=%s]" ,
288+ name , buf , ntohs (IP_AS_V6 (& uc -> ip , port )), strerror (errno ));
289+ }
286290 goto error ;
287291 }
288292
@@ -334,21 +338,21 @@ udp_bind_double ( udp_connection_t **_u1, udp_connection_t **_u2,
334338 int subsystem , const char * name1 ,
335339 const char * name2 , const char * host , int port ,
336340 const char * ifname , int rxsize1 , int rxsize2 ,
337- int txsize1 , int txsize2 )
341+ int txsize1 , int txsize2 , int bind_fail_allowed )
338342{
339343 udp_connection_t * u1 = NULL , * u2 = NULL ;
340344 udp_connection_t * ucs [10 ];
341345 int tst = 40 , pos = 0 , i , port2 ;
342346
343347 memset (& ucs , 0 , sizeof (ucs ));
344348 while (1 ) {
345- u1 = udp_bind (subsystem , name1 , host , port , NULL , ifname , rxsize1 , txsize1 );
349+ u1 = udp_bind (subsystem , name1 , host , port , NULL , ifname , rxsize1 , txsize1 , bind_fail_allowed );
346350 if (u1 == NULL || u1 == UDP_FATAL_ERROR )
347351 goto fail ;
348352 port2 = ntohs (IP_PORT (u1 -> ip ));
349353 /* RTP port should be even, RTCP port should be odd */
350354 if ((port2 % 2 ) == 0 ) {
351- u2 = udp_bind (subsystem , name2 , host , port2 + 1 , NULL , ifname , rxsize2 , txsize2 );
355+ u2 = udp_bind (subsystem , name2 , host , port2 + 1 , NULL , ifname , rxsize2 , txsize2 , bind_fail_allowed );
352356 if (u2 != NULL && u2 != UDP_FATAL_ERROR )
353357 break ;
354358 }
0 commit comments