Date: 05 Jan 2001 01:52:07 +0100 From: Assar Westerlund <assar@FreeBSD.ORG> To: ecureuil <ecureuil@easynet.fr> Cc: hackers@FreeBSD.ORG Subject: Re: getifaddrs Message-ID: <5l4rzen7m0.fsf@assaris.sics.se> In-Reply-To: ecureuil's message of "Thu, 4 Jan 2001 18:48:28 %2B0100" References: <20010104184828.A12168@foret>
index | next in thread | previous in thread | raw e-mail
ecureuil <ecureuil@easynet.fr> writes:
> Hi
Hello.
> I'm trying to get interfaces' list and infos with getifaddrs().
> The ifa_data struct should contain all needed information, but
> this is a NULL pointer for IPv4 interfaces. Why ?
What you are printing is the link level address and the v4 address for
each interface.
> a sample output for my ethernet card :
>
> ed0 ( 6.3.6.0) : UP, AF_INET6 MTU=1500 (struct ifa_data)
> ed0 ( 10.0.0.1) : UP MTU=1500 (struct ifa_data is a null pointer)
>
>
> BTW, there is always 2 nodes for each interface, even if INET6 is not
> enabled in the kernel. is it normal ?
Yes, one link-level and one v4-level.
> /* get if address */
> sa = (struct sockaddr_in *) ifa->ifa_addr;
> strncpy(ifstraddr, inet_ntoa(sa->sin_addr), 16);
Don't do this. You don't know if it's a v4 adress. Look at
sa->sa_family to figure out what kind of address it is first.
> if (ifa->ifa_addr->sa_family & AF_INET6) printf(", AF_INET6");
Do == AF_INET6
> if(ifa->ifa_data) printf("(struct ifa_data)\n");
> else printf("(struct ifa_data is a null pointer)\n");
Hu? For v4 addresses, ifa_data is NULL, but for link-level addresses,
ifa_dat points to `struct if_data'.
/assar
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5l4rzen7m0.fsf>
