From 5111d4c9e012569cd513e2c971150a0137d1ea9d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 15 Oct 2010 02:26:26 +0200 Subject: IPv6: As binding to a multicast address isn't possible, bind to :: when a multicast address is given --- util.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/util.c b/util.c index c513a6c..1951f21 100644 --- a/util.c +++ b/util.c @@ -488,19 +488,20 @@ int OpenSocket6( const char *_psz_arg, int i_ttl, unsigned int *pi_weight ) i = 0x80000; setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, (void *) &i, sizeof( i ) ); - if ( bind( i_fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr) ) < 0 ) - { - msg_Err( NULL, "couldn't bind" ); - PrintSocket6( "socket definition:", &bind_addr, &connect_addr ); - exit(EXIT_FAILURE); - } - - /* Join the multicast group if the socket is a multicast address */ if ( IN6_IS_ADDR_MULTICAST( &bind_addr.sin6_addr ) ) { struct ipv6_mreq imr; + struct sockaddr_in6 bind_addr_any = bind_addr; + bind_addr_any.sin6_addr = in6addr_any; + + if ( bind( i_fd, (struct sockaddr *)&bind_addr_any, sizeof(bind_addr_any) ) < 0 ) + { + msg_Err( NULL, "couldn't bind" ); + PrintSocket6( "socket definition:", &bind_addr, &connect_addr ); + exit(EXIT_FAILURE); + } - imr.ipv6mr_multiaddr = bind_addr.sin6_addr; + imr.ipv6mr_multiaddr = bind_addr.sin6_addr; imr.ipv6mr_interface = i_bind_ifindex; /* Join Multicast group without source filter */ @@ -512,6 +513,15 @@ int OpenSocket6( const char *_psz_arg, int i_ttl, unsigned int *pi_weight ) exit(EXIT_FAILURE); } } + else + { + if ( bind( i_fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr) ) < 0 ) + { + msg_Err( NULL, "couldn't bind" ); + PrintSocket6( "socket definition:", &bind_addr, &connect_addr ); + exit(EXIT_FAILURE); + } + } if ( !IN6_IS_ADDR_UNSPECIFIED(&connect_addr.sin6_addr) ) { -- cgit v1.2.3