[ECOS] Antw: Re: [ECOS] Receiving Multicast Packets on a socket

Adolfo Lucha Adolfo.Lucha@controlware.de
Wed Sep 10 08:43:00 GMT 2003


Hello Andrew,

thanks fir hint. http://www.infres.enst.fr/~dax/polys/multicast/api_en.html is a good example. I will try it.

Thangs and Regards
Adolfo

>>> Andrew Lunn <andrew@lunn.ch> 10.09.03 09.43 >>>
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



More information about the Ecos-discuss mailing list