Re: multiple multicast group membership problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 








>I'm haveing a problem where, in one app I have a number of sockets all
>IP_ADD_MEMBERSHIPed to individual meulticast groups, and i'm finding that
a
>local transmission to one of these groups is appearing on all the sockets,
>when according to teh sockets standard it shoudl only appear on the one
that
>was IP_ADD_MEMBERSHIPed to that group.

That isn't true. Multicast membership is for the entire interface. If you
want the socket to receive only a particular group, you need to bind to
that group address. All INADDR_ANY sockets will (and should) receive all
packets for any local address with the same port, including all multicast
groups that have been joined.

                        +-DLS

I create and attach a socket to s singel group using (roughly) this code:
[error checking removed for brevity]


  this->socketID = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

  localAddress.sin_port=6666;
  localAddress.sin_addr.s_addr = htonl(INADDR_ANY);

  on = 1;

  setsockopt(this->socketID, SOL_SOCKET, SO_REUSEADDR,
                   (RMF_OPTVAL_TYPE)&on, (socklen_t)sizeof(on)) ;


  setsockopt(this->socketID, SOL_SOCKET, SO_REUSEPORT,
                   (RMF_OPTVAL_TYPE)&on, (socklen_t)sizeof(on));

  bind(this->socketID, (struct sockaddr*)&localAddress,
           sizeof(localAddress));

  localAddressSize = sizeof(localAddress);

  getsockname(this->socketID, (struct sockaddr*)&localAddress,
                  (socklen_t*)&localAddressSize);


  struct ip_mreq      localGroup;
  localGroup.imr_multiaddr.s_addr = htonl(mcastGroup);
  localGroup.imr_interface.s_addr = htonl(mcastIF);
  setsockopt(this->socketID, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                 (RMF_OPTVAL_TYPE)&localGroup,
                 (socklen_t)sizeof(localGroup));

  ifAddress.s_addr = htonl(mcastIF);
  setsockopt(this->socketID, IPPROTO_IP, IP_MULTICAST_IF,
                 (RMF_OPTVAL_TYPE)&ifAddress,
                 (socklen_t)sizeof(ifAddress));

  setsockopt(this->socketID, IPPROTO_IP, IP_MULTICAST_LOOP,
                  (RMF_OPTVAL_TYPE)&on, (socklen_t)sizeof(on));

and i'm finding that i can do a recvfrom on a socket subscribed in this way
to, say 239.255.48.42:6666 on interface 192.168.0.210, and receive a udp
packet sent from, say 192.168.0.210:34330 to 239.255.48.40:6666. I've
checked that this is what's on the wire using ethereal. Has anyone got any
idea why i see this?

Thanks,

Rob Taylor
Senior Developer    robt at flyingpig dot com
Flying Pig Systems  http://www.flyingpig.com

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html


-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux