public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Cannot sendto multicast using FreeBSD stack
@ 2008-01-10 14:29 Chad Handrich
  2008-01-10 14:53 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Chad Handrich @ 2008-01-10 14:29 UTC (permalink / raw)
  To: ecos-discuss

Hello,

I wrote about this problem previously, but still have not found a 
solution (see the subject "Problem with multicast using FreeBSD stack" 
from 11/29/07)

I have eCos configured with the FreeBSD stack.  Everything is working 
except a portion where I have to SEND multicast UDP packets using 
sendto().  In these instances, sendto() returns -1, and errno == 
EHOSTUNREACH.

Here is my test multicast code that is failing:

    struct in_addr interface_addr;

    // eth0 is configured to be 89.89.200.181
    inet_aton("89.89.200.181", &interface_addr);
    setsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, 
sizeof(interface_addr));
     
    struct in_addr multi_iface;
    getsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &multi_iface, 
sizeof(multi_iface));
    diag_printf("getsockopt specifies %s as multicast interface\n", 
inet_ntoa(multi_iface));
    // This outputs the string:     getsockopt specifies 89.89.200.181 
as multicast interface

    // Sample data to send via multicast
    char buf[5]; buf[0] = 0; buf[1] = 1; buf[2] = 2; buf[3] = 3; buf[4] = 4;
   
    struct sockaddr_in to;
    to.sin_family = AF_INET;
    to.sin_port = htons(2222);
    inet_aton("239.192.23.160", &(to.sin_addr));
   
    int retval = sendto(skt, buf, 5, 0, (struct sockaddr *)&to, sizeof(to));
    diag_printf("post-sendto: errno=%d   retval=%d\n", errno, retval);
    // This outputs the string:     post-sendto: errno=365   retval=-1
    //  errno=365 corresponds to EHOSTUNREACH


Any help to get this multicast sendto() to succeed would be greatly 
appreciated.

My thanks,

Chad Handrich



   

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] Cannot sendto multicast using FreeBSD stack
  2008-01-10 14:29 [ECOS] Cannot sendto multicast using FreeBSD stack Chad Handrich
@ 2008-01-10 14:53 ` Andrew Lunn
  2008-01-10 16:10   ` Chad Handrich
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2008-01-10 14:53 UTC (permalink / raw)
  To: Chad Handrich; +Cc: ecos-discuss

On Thu, Jan 10, 2008 at 09:29:05AM -0500, Chad Handrich wrote:
> Hello,
>
> I wrote about this problem previously, but still have not found a solution 
> (see the subject "Problem with multicast using FreeBSD stack" from 
> 11/29/07)
>
> I have eCos configured with the FreeBSD stack.  Everything is working 
> except a portion where I have to SEND multicast UDP packets using sendto(). 
>  In these instances, sendto() returns -1, and errno == EHOSTUNREACH.
>
> Here is my test multicast code that is failing:
>
>    struct in_addr interface_addr;
>
>    // eth0 is configured to be 89.89.200.181
>    inet_aton("89.89.200.181", &interface_addr);
>    setsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, 
> sizeof(interface_addr));
>        struct in_addr multi_iface;
>    getsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &multi_iface, 
> sizeof(multi_iface));
>    diag_printf("getsockopt specifies %s as multicast interface\n", 
> inet_ntoa(multi_iface));
>    // This outputs the string:     getsockopt specifies 89.89.200.181 as 
> multicast interface
>
>    // Sample data to send via multicast
>    char buf[5]; buf[0] = 0; buf[1] = 1; buf[2] = 2; buf[3] = 3; buf[4] = 4;
>      struct sockaddr_in to;
>    to.sin_family = AF_INET;
>    to.sin_port = htons(2222);
>    inet_aton("239.192.23.160", &(to.sin_addr));
>      int retval = sendto(skt, buf, 5, 0, (struct sockaddr *)&to, 
> sizeof(to));
>    diag_printf("post-sendto: errno=%d   retval=%d\n", errno, retval);
>    // This outputs the string:     post-sendto: errno=365   retval=-1
>    //  errno=365 corresponds to EHOSTUNREACH
>
>
> Any help to get this multicast sendto() to succeed would be greatly 
> appreciated.

Do you also add a multicast route? Typically on Linux you have to add
a route:

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

      Andrew

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] Cannot sendto multicast using FreeBSD stack
  2008-01-10 14:53 ` Andrew Lunn
@ 2008-01-10 16:10   ` Chad Handrich
  0 siblings, 0 replies; 3+ messages in thread
From: Chad Handrich @ 2008-01-10 16:10 UTC (permalink / raw)
  To: Chad Handrich, ecos-discuss

Andrew Lunn wrote:
> On Thu, Jan 10, 2008 at 09:29:05AM -0500, Chad Handrich wrote:
>   
>> Hello,
>>
>> I wrote about this problem previously, but still have not found a solution 
>> (see the subject "Problem with multicast using FreeBSD stack" from 
>> 11/29/07)
>>
>> I have eCos configured with the FreeBSD stack.  Everything is working 
>> except a portion where I have to SEND multicast UDP packets using sendto(). 
>>  In these instances, sendto() returns -1, and errno == EHOSTUNREACH.
>>
>> Here is my test multicast code that is failing:
>>
>>    struct in_addr interface_addr;
>>
>>    // eth0 is configured to be 89.89.200.181
>>    inet_aton("89.89.200.181", &interface_addr);
>>    setsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, 
>> sizeof(interface_addr));
>>        struct in_addr multi_iface;
>>    getsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &multi_iface, 
>> sizeof(multi_iface));
>>    diag_printf("getsockopt specifies %s as multicast interface\n", 
>> inet_ntoa(multi_iface));
>>    // This outputs the string:     getsockopt specifies 89.89.200.181 as 
>> multicast interface
>>
>>    // Sample data to send via multicast
>>    char buf[5]; buf[0] = 0; buf[1] = 1; buf[2] = 2; buf[3] = 3; buf[4] = 4;
>>      struct sockaddr_in to;
>>    to.sin_family = AF_INET;
>>    to.sin_port = htons(2222);
>>    inet_aton("239.192.23.160", &(to.sin_addr));
>>      int retval = sendto(skt, buf, 5, 0, (struct sockaddr *)&to, 
>> sizeof(to));
>>    diag_printf("post-sendto: errno=%d   retval=%d\n", errno, retval);
>>    // This outputs the string:     post-sendto: errno=365   retval=-1
>>    //  errno=365 corresponds to EHOSTUNREACH
>>
>>
>> Any help to get this multicast sendto() to succeed would be greatly 
>> appreciated.
>>     
>
> Do you also add a multicast route? Typically on Linux you have to add
> a route:
>
> route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
>
>       Andrew
>
>   

It appears that you are correct. Using ioctl to add a route with the 
parameters you specified seems to be working. My thanks.


Chad


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-10 16:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-10 14:29 [ECOS] Cannot sendto multicast using FreeBSD stack Chad Handrich
2008-01-10 14:53 ` Andrew Lunn
2008-01-10 16:10   ` Chad Handrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).