From owner-freebsd-net Sat Feb 16 20:29: 0 2002 Delivered-To: freebsd-net@freebsd.org Received: from alumni.deec.uc.pt (alumni.deec.uc.pt [193.136.238.200]) by hub.freebsd.org (Postfix) with ESMTP id 7F8C137B400 for ; Sat, 16 Feb 2002 20:28:52 -0800 (PST) Received: (from root@localhost) by alumni.deec.uc.pt (8.11.6/8.11.2) id g1H4Skt01583 for freebsd-net@freebsd.org; Sun, 17 Feb 2002 04:28:46 GMT (envelope-from slug@alumni.deec.uc.pt) Received: from localhost (slug@localhost) by alumni.deec.uc.pt (8.11.6/8.11.1av) with ESMTP id g1H4SjV01575 for ; Sun, 17 Feb 2002 04:28:45 GMT (envelope-from slug@alumni.deec.uc.pt) X-Authentication-Warning: alumni.deec.uc.pt: slug owned process doing -bs Date: Sun, 17 Feb 2002 04:28:45 +0000 (WET) From: Nuno Miguel Fernandes Sucena Almeida To: freebsd-net@freebsd.org Subject: getifaddrs usage (bug?) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS perl-10 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 - */ 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 - */ 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