@@ -609,6 +609,21 @@ int upipe_udp_open_socket(struct upipe *upipe, const char *_uri, int ttl,
609609 if (setsockopt (fd , SOL_SOCKET , SO_RCVBUF , (void * ) & i , sizeof (i )))
610610 upipe_warn (upipe , "fail to increase receive buffer" );
611611
612+ #ifdef SO_BINDTODEVICE
613+ if (ifname ) {
614+ /* linux specific, needs root or CAP_NET_RAW */
615+ if (setsockopt (fd , SOL_SOCKET , SO_BINDTODEVICE ,
616+ ifname , strlen (ifname ) + 1 ) < 0 ) {
617+ upipe_err_va (upipe , "couldn't bind to device %s (%m)" ,
618+ ifname );
619+ free (ifname );
620+ close (fd );
621+ return -1 ;
622+ }
623+ ubase_clean_str (& ifname );
624+ }
625+ #endif
626+
612627 /* Join the multicast group if the socket is a multicast address */
613628 if (bind_addr .ss .ss_family == AF_INET
614629 && IN_MULTICAST (ntohl (bind_addr .sin .sin_addr .s_addr ))) {
@@ -663,20 +678,6 @@ int upipe_udp_open_socket(struct upipe *upipe, const char *_uri, int ttl,
663678 return -1 ;
664679 }
665680 }
666- #ifdef SO_BINDTODEVICE
667- if (ifname ) {
668- /* linux specific, needs root or CAP_NET_RAW */
669- if (setsockopt (fd , SOL_SOCKET , SO_BINDTODEVICE ,
670- ifname , strlen (ifname ) + 1 ) < 0 ) {
671- upipe_err_va (upipe , "couldn't bind to device %s (%m)" ,
672- ifname );
673- free (ifname );
674- close (fd );
675- return -1 ;
676- }
677- ubase_clean_str (& ifname );
678- }
679- #endif
680681 }
681682 }
682683 }
0 commit comments