binding to a multicast address with multiple listeners

binding to a multicast address with multiple listeners

Post by wrapp » Sat, 26 Apr 2003 10:51:01



I do not have a copy of Stevens' Network Programming Book, but I am
nonetheless curious about why binding to a multicast address is a bad
idea.  I have the situation in my multicast application whereby
multiple sockets are bound to the same multicast port (say 8000) with
INADDR_ANY for the bind() address parameter.  The sockets then each
join a different multicast group.  However, all the sockets receive
any multicast traffic aimed at that port, even multicast traffic for
an address that was not the multicast group the socket joined.  As I
understand, joining the multicast group only tells the IP layer to
accept network traffic for a certain multicast address.  It does not
tell the UDP layer to deliver that data to the appropriate socket.
Therefore, it would seem bind is the way in which the operating system
filters the multicast data so it knows what socket to deliver the data
to.  Without a multicast bind it seems there is no way to have
multiple sockets listen to the same port for different destination
addresses at the same time.  (Putting multicast data on the same port
is done because of network configuration reasons where my application
is to be used.  A router bridges two networks and only allows
multicast data through on a certain port.)  So why is a multicast bind
a bad idea?  It seems to be the only way to discriminate traffic sent
to the port.  In theory it seems possible that any unicast data aimed
at the port could be picked up by a socket bound with INADDR_ANY so
there would even be more potential for confusion as far as the socket
is concerned.  What am I missing?
 
 
 

binding to a multicast address with multiple listeners

Post by Vladislav Yasevic » Fri, 02 May 2003 04:37:05


Well..., binding to a multicast address is not a "bad" idea, you just
have to be carefull on how you use such sockets.

In general, binding a socket to an address causes the local endpoint
to be set to that address.  Subsequent transmittions will use this
address as source.  However, a lot of multicast applications
use shortcuts of using multicast bound sockets for sends.  Strictly
speaking, such sends should fail according to protocol specifications.
However, customers have convinced some vendors to put in hacks that
will pick a unicast address on such sends.  Now, for applications to
be portable, other vendors have to provide similar hacks.

Having just written such a hack for Tru64, I can say that it is not
pretty and is against protocol definitions.

The correct way to program multicast applications is to have a
receiver socket that joined a multicast group (an maybe bound to a
multicast address) and a separate sender socket.  If you join multiple
groups, you can have multiple recievers, but can get away with only one
sender depending on your application.

-vlad


> I do not have a copy of Stevens' Network Programming Book, but I am
> nonetheless curious about why binding to a multicast address is a bad
> idea.  I have the situation in my multicast application whereby
> multiple sockets are bound to the same multicast port (say 8000) with
> INADDR_ANY for the bind() address parameter.  The sockets then each
> join a different multicast group.  However, all the sockets receive
> any multicast traffic aimed at that port, even multicast traffic for
> an address that was not the multicast group the socket joined.  As I
> understand, joining the multicast group only tells the IP layer to
> accept network traffic for a certain multicast address.  It does not
> tell the UDP layer to deliver that data to the appropriate socket.
> Therefore, it would seem bind is the way in which the operating system
> filters the multicast data so it knows what socket to deliver the data
> to.  Without a multicast bind it seems there is no way to have
> multiple sockets listen to the same port for different destination
> addresses at the same time.  (Putting multicast data on the same port
> is done because of network configuration reasons where my application
> is to be used.  A router bridges two networks and only allows
> multicast data through on a certain port.)  So why is a multicast bind
> a bad idea?  It seems to be the only way to discriminate traffic sent
> to the port.  In theory it seems possible that any unicast data aimed
> at the port could be picked up by a socket bound with INADDR_ANY so
> there would even be more potential for confusion as far as the socket
> is concerned.  What am I missing?


 
 
 

1. multicast socket bind() address in use

I'm having a problem binding to a socket on a multicast addess. I'm
interested
only in reading the multicast address.
Here's what I'm doing:

1. I create a UDP socket
2. I use setsockopt options to set IP_MULTICAST_IF, IP_ADD_MEMBERSHIP,
    and SO_REUSEADDR
3. I bind the socket to the multicast address and port number that I'm
interested in

I'm actually doing this twice, because I am interested in two ports -
they
happen to be 1024 and 1026 (immediately following the last reserved port
-
I don't know if this is significant)

I have two linux boxes, both running RH6.0. On one box, I can bind fine
to port 1026 and get the data from the multicast channel, but when it
tries
to bind to 1024 it returns "address already in use." On the other linux
box,
I get the same behavior, except reversed - port 1024 binds ok, but port
1026 says address already in use. I've found that it doesn't matter what

the address is in the sockaddr_in structure that is passed to bind() -
it
could be INADDR_ANY or the particular multicast address that I'm
interested
in, or any other IP address, it still doesn't bind. If I change the port
number
it will bind, but that doesn't do me any good, because the data that I'm

interested in is on ports 1024 and 1026.

Does anyone know how I can force a socket to bind to a particular
address,
regardless of whether something else is bound to it? (When I run netstat
from
the command line, it doesn't appear that anything is using the port
isn't binding)
SO_REUSEADDR doesn't seem to be enough. Does anyone else understand
this any better than I do?

TIA,
Steve

--
-------------------------------------------------------

Research Engineer
Multimedia Communications Research Laboratory
Motorola Labs
-------------------------------------------------------

2. can someone send me linux command and tell me how to run Xwindows

3. Multicast using socket bound to IP looback address

4. Help with oti087

5. bind to a multicast address

6. Samba + IP-Masquerading ??

7. Multicast listener utility losing data

8. CDROM Problems

9. Multicast Message Listener

10. TCP binding on a server with multiple IP address

11. Multiple UDP Binds to the same ip:port address?

12. Linux-Multiple ip address bound to one ethernet card?

13. binding a single IP address to multiple NICs