Skip to contentSkip to conversation

problems with using multicast

DISCUSSION Shantanu.Gogate 1 participant 1 message May 12, 2003

lore
Share & tools
lore
#0 lore raw

Hi,
I am trying to use multicast in an application which. I am running
kernel 2.4.19.I have interfaces lo, and eth0 on bootup. Here is what I am trying to do...

When i try to create a socket which becomes a member of a multicast group by specifying the grp address and using INADDR_ANY as the interface to use, i am able to receive packets sent out the multicast group. However if i specifically bind it to the address of eth0 and then try to receive packets...i am not getting any....The only other interfaces i have are lo. I cant explain why it is working when i use INADDR_ANY and does not receive packets when i use the specific address of the device....

the code for this socket init looks as follows ...i have removed error handling for readability right now
--------------

         server_socket = socket(AF_INET, SOCK_DGRAM,0);
  
         memset(&saddr,0,sizeof(struct sockaddr_in));
         saddr.sin_family = AF_INET;
         saddr.sin_addr.s_addr = htonl(INADDR_ANY);
         saddr.sin_port = port;

        bind(server_socket, (struct sockaddr *) &saddr, sizeof(saddr);

on=1; setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on));

        mreq.imr_multiaddr.s_addr = mcast_addr;
        mreq.imr_interface.s_addr = htonl(INADDR_ANY);

setsockopt(server_socket,SOL_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq))

ttl = 1;
setsockopt(server_socket, IPPROTO_IP, IP_MULTICAST_TTL,&ttl,sizeof(ttl))

loop = 0; setsockoptserver_socket,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof(loop))

return server_socket;
----------------------------------
if i replace INADDR_ANY with the actual interface address which i get using ioctl, then i cant receive any packets... However when i see the dump from tcpdump i can see the packets coming in, but for some reason they are not reaching the socket which had become a member. I can also see that the group membership was added if i do netstat -g

I would appreciate any help.

Thanks and regards,
Shantanu.