This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Receiving Multicast Packets on a socket
- From: Andrew Lunn <andrew at lunn dot ch>
- To: Adolfo Lucha <Adolfo dot Lucha at controlware dot de>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Wed, 10 Sep 2003 09:43:11 +0200
- Subject: Re: [ECOS] Receiving Multicast Packets on a socket
- References: <sf5eea76.093@controlware.de>
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