public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Receiving Multicast Packets on a socket
@ 2003-09-10  7:10 Adolfo Lucha
  2003-09-10  7:43 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Adolfo Lucha @ 2003-09-10  7:10 UTC (permalink / raw)
  To: ecos-discuss

Hello,

I tried to receive Packets sent by routers to the multicast address 224.0.0.2. I coded:

...cat...

    int one = 1;
    
    s = socket(AF_INET, SOCK_DGRAM, 0);

    if (s < 0)
    {
    	printf("datagram socket failed");
    	return -1;
    }
    
    if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)))
    {
    	printf("setsockopt SO_BROADCAST error");
    	return -1;
    }
    
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_len    = sizeof(local);
    local.sin_port   = htons(HSRP_PORT_NUMBER);
    local.sin_addr.s_addr = inet_addr("224.0.0.2"); // or INADDR_ANY ?
    
    if(bind(s, (struct sockaddr *) &local, sizeof(local)) < 0)
    {
    	printf("bind error");
    	return -1;
    }

    ret = recvfrom(s, &HsrpPacket, sizeof(HsrpPacket), (int)0,\
                             (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);

...cat...

But recvfrom() never returns. What am I doing wrong? Hints are appreciated.

Regards
Adolfo



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

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

* Re: [ECOS] Receiving Multicast Packets on a socket
  2003-09-10  7:10 [ECOS] Receiving Multicast Packets on a socket Adolfo Lucha
@ 2003-09-10  7:43 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2003-09-10  7:43 UTC (permalink / raw)
  To: Adolfo Lucha; +Cc: ecos-discuss

On Wed, Sep 10, 2003 at 09:09:45AM +0200, Adolfo Lucha wrote:
> Hello,
> 
> I tried to receive Packets sent by routers to the multicast address 224.0.0.2. I coded:
> 
> ...cat...
> 
>     int one = 1;
>     
>     s = socket(AF_INET, SOCK_DGRAM, 0);
> 
>     if (s < 0)
>     {
>     	printf("datagram socket failed");
>     	return -1;
>     }
>     
>     if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)))
>     {
>     	printf("setsockopt SO_BROADCAST error");
>     	return -1;
>     }
>     
>     memset(&local, 0, sizeof(local));
>     local.sin_family = AF_INET;
>     local.sin_len    = sizeof(local);
>     local.sin_port   = htons(HSRP_PORT_NUMBER);
>     local.sin_addr.s_addr = inet_addr("224.0.0.2"); // or INADDR_ANY ?
>     
>     if(bind(s, (struct sockaddr *) &local, sizeof(local)) < 0)
>     {
>     	printf("bind error");
>     	return -1;
>     }
> 
>     ret = recvfrom(s, &HsrpPacket, sizeof(HsrpPacket), (int)0,\
>                              (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
> 
> ...cat...
> 
> But recvfrom() never returns. What am I doing wrong? Hints are appreciated.

You need to join the multicast group. Find a book/HOWTO etc about
writing multicast programs. eCos uses the standard BSD API, so normal
networking books are OK.

           Andrew

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

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

end of thread, other threads:[~2003-09-10  7:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-10  7:10 [ECOS] Receiving Multicast Packets on a socket Adolfo Lucha
2003-09-10  7:43 ` Andrew Lunn

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).