Question

I'm using getnameinfo as follows:

ifaddrs *ifaddr = NULL, *ifa = NULL;
int rc, family, insize;

rc = getifaddrs(&ifaddr);
...

for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    family = ifa->ifa_addr->sa_family
    insize = (family == AF_INET) ?
            (int)sizeof(struct sockaddr_in) :
            (int)sizeof(struct sockaddr_in6);

    char host[HOST_NAME_MAX];
    rc = getnameinfo(ifa->ifa_addr, insize,
            host, sizeof(host), NULL, 0, NI_NUMERICHOST);
}
...

When the function returns with an IPv6 address, it include the interface appended to the numeric IP address:

fe80::62a4:4cff:fe05:dc1b%eth0

What's the purpose of appending the interface to the numerical IP address?

Is there a flag available that controls the appending of the interface to the IP address?

Was it helpful?

Solution

fe80::* addresses are link-local in scope, which means the address is only valid for that particular network, the same address may reference a difference host on a different network. It is thus meaningless to specify a link-local address without specifying which network adapter. Also, DNS becomes rather meaningless outside of link-local scope such as provided by ZeroConf / multicast-DNS.

Unix hosts tend to specify the adapter by name, Windows hosts will specify the adapter by index. Note that Windows maintains separate interface indexes for IPv4 and IPv6.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top