[ECOS] Receiving Multicast Packets on a socket
Adolfo Lucha
Adolfo.Lucha@controlware.de
Wed Sep 10 07:10:00 GMT 2003
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
More information about the Ecos-discuss
mailing list