Listening to multicast on all interfaces
I have the following interfaces :
ifconfig
bond0 Link encap:Ethernet HWaddr 1C:C1:DE:1F:71:CA
inet addr:10.3.3.13 Bcast:10.3.3.255 Mask:255.255.255.0
inet6 addr: fe80::1ec1:deff:fe1f:71ca/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:39972916 errors:0 dropped:0 overruns:0 frame:0
TX packets:21849588 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:60630723698 (56.4 GiB) TX bytes:1570500163 (1.4 GiB)
eth0 Link encap:Ethernet HWaddr 1C:C1:DE:1开发者_如何学编程F:71:CA
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:39959516 errors:0 dropped:0 overruns:0 frame:0
TX packets:21849585 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60629214902 (56.4 GiB) TX bytes:1570499971 (1.4 GiB)
Interrupt:16 Memory:f2000000-f2012800
eth1 Link encap:Ethernet HWaddr 1C:C1:DE:1F:71:CA
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:13400 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1508796 (1.4 MiB) TX bytes:192 (192.0 b)
Interrupt:17 Memory:f0000000-f0012800
eth5 Link encap:Ethernet HWaddr 00:0F:53:07:50:7D
inet addr:90.206.66.13 Bcast:90.206.66.255 Mask:255.255.255.0
inet6 addr: fe80::f:5300:107:507d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8590042795 errors:0 dropped:4 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8308671 (7.9 MiB) TX bytes:1132 (1.1 KiB)
Interrupt:39
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:700 (700.0 b) TX bytes:700 (700.0 b)
I have the following multicast code to listen :
socket_file_descriptor_ = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
int flag_on = 1;
if ( ( setsockopt ( socket_file_descriptor_, SOL_SOCKET, SO_REUSEADDR, &flag_on,
sizeof(flag_on) ) ) < 0 )
{ exit(1); }
struct ip_mreq mc_req;
inet_pton ( AF_INET, listen_ip_.c_str(), &(mc_req.imr_multiaddr.s_addr) );
mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
if ( ( setsockopt ( socket_file_descriptor_, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(void*) &mc_req, sizeof(mc_req))) < 0)
{ exit(1); }
{
struct sockaddr_in mcast_Addr;
bzero ( &mcast_Addr, sizeof(mcast_Addr) );
mcast_Addr.sin_family = AF_INET;
mcast_Addr.sin_addr.s_addr = htonl(INADDR_ANY);
mcast_Addr.sin_port = htons ( listen_port_ );
/* bind to specified port onany interface */
if ( bind ( socket_file_descriptor_, (struct sockaddr *) &mcast_Addr, sizeof ( struct sockaddr_in ) ) < 0 )
{ exit(1); }
}
// then recvfrom ( socket_file_descriptor_, _dest_, _len_, 0, NULL, NULL );
But this does not seem to be returning data received on interface "eth5". Any pointers ?
What platform are you using? I'd guess a linux OS?
Are you completely sure that messages arrive on your interface (tcpdump, netcat?). Where does the expected data come from - did you develop the 'sender' code too? Does it use SO_BROADCAST option?
精彩评论