|
From: <mr...@mr...> - 2004-08-25 12:46:26
|
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2004/08/25 14:46:01+02:00 mr...@fo... =
# udp: allow selection of interface for multicast
# =
# src/multicast/mc.c
# 2004/08/25 14:46:00+02:00 mr...@fo... +30 -2
# select interface for multicast using ?if=3Daddr syntax
# =
diff -Nru a/src/multicast/mc.c b/src/multicast/mc.c
--- a/src/multicast/mc.c 2004-08-25 14:46:16 +02:00
+++ b/src/multicast/mc.c 2004-08-25 14:46:16 +02:00
@@ -103,6 +103,7 @@
mc_stream_t *mcs;
uint32_t addr;
url_t *u;
+ char *iface =3D NULL;
char *pp;
int port;
int sock;
@@ -122,7 +123,21 @@
return NULL;
=
*pp++ =3D 0;
- port =3D strtol(pp, NULL, 0);
+ port =3D strtol(pp, &pp, 0);
+
+ if(*pp++ =3D=3D '?'){
+ while(pp && *pp){
+ char *np =3D strchr(pp, '&');
+ char *v =3D strchr(pp, '=3D');
+ if(np)
+ *np++ =3D 0;
+ if(v)
+ *v++ =3D 0;
+ if(!strcmp(pp, "if"))
+ iface =3D v;
+ pp =3D np;
+ }
+ }
=
if(!(hn =3D gethostbyname(url)))
return NULL;
@@ -139,8 +154,21 @@
addr =3D *(uint32_t *) hn->h_addr;
if(IN_MULTICAST(ntohl(addr))){
struct ip_mreq mrq;
+ uint32_t ifaddr =3D htonl(INADDR_ANY);
+
+ if(iface){
+ hn =3D gethostbyname(iface);
+ if(hn){
+ ifaddr =3D *(uint32_t *) hn->h_addr;
+ tc2_print("UDP", TC2_PRINT_DEBUG, "using interface %s\n",
+ iface);
+ } else {
+ tc2_print("UDP", TC2_PRINT_WARNING, "bad interface address\n");
+ }
+ }
+
mrq.imr_multiaddr.s_addr =3D addr;
- mrq.imr_interface.s_addr =3D htonl(INADDR_ANY);
+ mrq.imr_interface.s_addr =3D ifaddr;
if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mrq,
sizeof(mrq)) < 0)
return NULL;
|