[ECOS] Re: Why does sending multicast UDP require a gateway?

Grant Edwards grant.b.edwards@gmail.com
Thu Mar 31 18:24:00 GMT 2011

On 2011-03-30, Grant Edwards <grant.b.edwards@gmail.com> wrote:
>> It turns out this was fixed in the FreeBSD sources in 2001:
>>   http://svn.freebsd.org/viewvc/base?view=revision&revision=79830   
>>   http://svn.freebsd.org/viewvc/base?view=revision&revision=79836
>> I'll work up a patch...
> It turns out that doesn't fix the problem.  That only handles the
> case where you've explicitly asked the multicast packets to go out a
> specific interface.  Binding a socket to an interface and sending
> multicast packets still doesn't work unless there's a route to the
> "destination".
> One would think that binding the socket to a particular interface
> would cause sent packets to go out that interface, but I guess not...

After more Googling, it appears that unless you want a "default
interface" chosen (via the normal routing table, I guess), you are
indeed expected to explicitly set the sending interface independently
of what interface the sending socket is bound to:

   bind(sock, (struct sockaddr *)&local, sizeof local);
   setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &local.sin_addr, sizeof local.sin_addr);

It appears that if you don't bind the socket, ip_output will fill in
the source IP field with the IP address of the sending interface, but
if you want to specify the source port, you still have to bind() the
socket.  [Whether you can bind the socket to one interface but send
packets via a different one, I don't know.]

I'll have a patch tomorrow.
Grant Edwards               grant.b.edwards        Yow! An air of FRENCH FRIES
                                  at               permeates my nostrils!!

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list