[Xorp-hackers] Multicast Programming

Pavlin Radoslavov pavlin at icir.org
Wed Oct 3 12:31:05 PDT 2007


Luca Giraudo <luca.giraudo at gmail.com> wrote:

> I have a PC with 2 ethernet cards and I want to receive multicast packets
> from both the cards: so I have to bind the UDP socket to every IP address on
> the PC (10.1.0.39 and 192.168.0.1).
> 
> I try to do:
> 
> ...
> 
> const IPv4 local_addr = IPv4Constants::any   //equivalent to INADDR_ANY
> 
> _xrl_socket4_client.send_udp_open_bind_join(_socket4_target.c_str(),
> xrl_router().instance_name(),
>                 local_addr, default_udp_port, default_multicast_group, ttl,
> reuse,
>                 callback(this,
> &XrlPolidistNode::send_udp_open_bind_join_cb));
> 
> 
> ...
> 
> The error from rtrmgr is this:
> 
> [ 2007/10/03 14:12:11 WARNING xorp_fea XrlFeaTarget ] Handling method for
> socket4/0.1/udp_open_bind_join failed: XrlCmdError 102 Command failed Cannot
> open, bind and join an UDP socket to address ZERO: the address must belong
> to a local interface
> 
> The solution to this problem is to bind to a specific ipv4 address (I bind
> to 10.1.0.39), but if I bind the socket on a specific address I can't
> receive multicast packets from the other card, also when I join the
> multicast group on this interface.
> 
> In the end, I try also to bind the same socket on both the addresses, but
> the second time there is an error, probably because it's possible to call
> once the bind on the same socket.
> 
> Someone could help me?

If we ignore XORP for a moment, the UNIX multicast semantics are
that when you join a multicast group, you have to specify the
interface to join (in IPv4 the interface is specified by one of its
IP addresses; in IPv6 the interface index is used to specify it).
In other words, there is no "wildcard" API mechanism to join all
interfaces at the same time.

The XORP XRL API is similar in that aspect, so yes you need to join
explicitly on each interface.
The difference is that the XORP API combines several system
operations together, so from your protocol's perspective they appear
atomic. E.g., udp_open_and_bind will open the socket and bind it to
an address.

In your case what you can do is:

* Use udp_open_and_bind to open the socket and bind it to ANY.
  BTW, I would recommend to use IPv4::ZERO() or IPv4::ANY() instead
  of IPv4Constants::any. They are the same thing, but it is just
  question of being consistent with the rest of the XORP code.

* Use udp_join_group to join the same multicast group on each
  interface you need.

Please let me know if it doesn't work for you.

Regards,
Pavlin



More information about the Xorp-hackers mailing list