Date: Sun, 17 Feb 2002 04:28:45 +0000 (WET) From: Nuno Miguel Fernandes Sucena Almeida <slug@alumni.deec.uc.pt> To: freebsd-net@freebsd.org Subject: getifaddrs usage (bug?) Message-ID: <Pine.BSF.4.21.0202170419160.1461-100000@alumni.deec.uc.pt>
next in thread | raw e-mail | index | archive | help
Hello,
i'm using getifaddrs to get the IP and HW address of an ethernet
interface but it seems that the ifap->ifa_next pointer is never NULL so I
end up with an infinite loop! If i uncomment the // printf's I get the
HW address correctly but after that I get the IP address repeated ad
eternum! Any ideas ?
()s
Nuno Sucena
PS: Please CC to me since i'm not subscribed in this list.
i have something like:
struct ifaddrs *ifap,*current; /* man getifaddrs */
struct sockaddr_dl *e_tmp;
struct sockaddr_in *i_tmp;
(...)
error = getifaddrs (&ifap);
if (error!=0)
{
perror("getifaddrs()");
return(EXIT_FAILURE);
}
current = ifap;
while (current!=NULL)
{
if ((strcmp(current->ifa_name,device)==0)&&
(((current->ifa_flags)&IFF_UP)==IFF_UP)&&
(current->ifa_addr!=NULL))
{
/* ethernet physical address - <net/if_dl.h> */
e_tmp = (struct sockaddr_dl*)current->ifa_addr;
if (e_tmp->sdl_family==AF_LINK)
{
/* hope that sdl_alen < ETHER_ADDR_LEN ;) */
memcpy(*eth_address,LLADDR(e_tmp),e_tmp->sdl_alen);
// printf("ethernet: %s\n",ethernet_print (*eth_address));
got_eth=1;
}
/* ethernet IP address - <netinet/in.h> */
i_tmp = (struct sockaddr_in*)current->ifa_addr;
if (i_tmp->sin_family==AF_INET)
{
ip_address->s_addr = i_tmp->sin_addr.s_addr;
// printf ("%s\n",inet_ntoa(*ip_address));
got_ip=1;
}
}
current = ifap->ifa_next;
}
freeifaddrs(ifap);
(...)
--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0202170419160.1461-100000>
