[ECOS] Re: How to add multicast route? - how to add/remove a route
Lambrecht Jürgen
J.Lambrecht@TELEVIC.com
Mon Jun 6 11:00:00 GMT 2011
Hello Grant,
I guess my answer is a bit late, but also for posterity's sake ;-), and
your code worked for me, thanks.
So with the code found here:
http://sourceware.org/ml/ecos-discuss/2011-03/msg00185.html, you can add
an entry in the routing table.
I updated the code, see attach.
Maybe this code could be added to
ecos/packages/net/bsd_tcpip/current/src/ecos/support.c?
However, to add/delete a multicast entry, we do it in another way, from
code we ported from Linux to eCos:
int LeaveMulticast(unsigned long multicastAddr) /* Adress of the multicast group */
{
struct ip_mreq ipMreq; /* Argument structure to setsockopt */
ipMreq.imr_multiaddr.s_addr = htonl(multicastAddr);
/* Unicast interface addr from which to receive the multicast packets */
ipMreq.imr_interface.s_addr = htonl (INADDR_ANY);
/* Set the socket option to leave the multicas group */
if (setsockopt (globalSocket, IPPROTO_IP, IP_DROP_MEMBERSHIP,
(char *)&ipMreq, sizeof (ipMreq)))
{
...}
}
int JoinMulticast(unsigned long multicastAddr) /* Adress of the multicast group */
{
....idem
/* Set the socket option to join the MULTICAST group */
if (setsockopt (gMDSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&ipMreq, sizeof (ipMreq)) == SOCKET_ERROR)
Those socket defines are in
ecos/packages/net/bsd_tcpip/current/include/netinet/in.h:
And this is the resulting routing table:
Destination Gateway Mask Flags Interface
0.0.0.0 10.0.0.1 0.0.0.0 UG eth0
10.0.0.0 10.0.0.0 255.255.240.0 U eth0
127.0.0.0 127.0.0.1 0.0.0.0 UG lo0
127.0.0.1 127.0.0.1 0.0.0.0 UH lo0
224.0.0.0 224.0.0.0 0.0.0.0 U eth0
(mark, I don't know why the Mask is always 0, this is not correct,
because to delete an entry, you must specify the correct mask! That is
why I added the correct mask myself for eth0 in my notes.)
On 04/01/2011 04:59 PM, Grant Edwards wrote:
> On 2011-04-01, Grant Edwards<grant.b.edwards@gmail.com> wrote:
>
>> I think next I'll try passing either my own address (10.0.0.102, or
>> the local network 10.0.0.0 and see what happens).
> Specifying 10.0.0.0 as the gateway address works. Oddly, the
> resulting routing table looks like this:
>
> Destination Gateway Mask Flags Interface
> 10.0.0.0 10.0.0.0 255.0.0.0 U eth0
> 224.0.0.0 224.0.0.0 240.0.0.0 U eth0
>
> Specifying 10.0.0.0 as the gateway results in the route I wanted with
> 224.0.0.0 as the gateway. Specifying 224.0.0.0 as the gateway fails.
>
> IMO, that's a bug, but whatever...
>
> So for posterity's sake, the initial routing table looked like this:
>
> Destination Gateway Mask Flags Interface
> 10.0.0.0 10.0.0.0 255.0.0.0 U eth0
>
> And the contents of rtentry to add the multicast route were:
>
> rt_dst = 224.0.0.0
> rt_genmask = 240.0.0.0
> rt_gateway = 10.0.0.0
> rt_flags = RTF_UP
>
> It turns out that the rt_dev field is ignored (or at least redundant).
Indeed, that is also what I noticed.
> That's different than the way Linux works: if you specify a device,
> you don't specify a gateway. I'm not sure what the rt_dev field is
> for with the FreeBSD stack...
>
Kind regards,
Jürgen
--
Jürgen Lambrecht
R&D Associate
Tel: +32 (0)51 303045 Fax: +32 (0)51 310670
http://www.televic-rail.com
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: route_utils.c
Type: text/x-csrc
Size: 8692 bytes
Desc: route_utils.c
URL: <http://sourceware.org/pipermail/ecos-discuss/attachments/20110606/b57edf0c/attachment.bin>
-------------- next part --------------
--
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