Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Apr 2012 11:53:59 +1200
From:      Andrew Thompson <thompsa@FreeBSD.org>
To:        freebsd-net <freebsd-net@freebsd.org>
Subject:   getifaddrs & ipv6 scope
Message-ID:  <CAFAOGNQv3pW2RwmEkcv3Oez7eP%2BF_q872ayj0=UgxsytBkj3ug@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,


I have noticed that getifaddrs() does not have sin6_scope_id set to
the interface id for link local addresses on AF_INET6 types.  Running
the following program gives different results on Linux

FreeBSD:

dev: bge0     address: <fe80:2::a6ba:dbff:fe03:d69> scope 0
dev: xl0      address: <fe80:4::204:75ff:fedc:39c1> scope 0
dev: lo0      address: <::1> scope 0
dev: lo0      address: <fe80:5::1> scope 0

Linux:

dev: lo       address: <::1> scope 0
dev: eth1     address: <2404:130:0:1000:204:75ff:febc:b8f0> scope 0
dev: eth1     address: <fe80::204:75ff:febc:b8f0%eth1> scope 2
dev: eth0     address: <fe80::222:4dff:fe54:3b1d%eth0> scope 3


Should FreeBSD be setting sin6_scope_id?

Andrew

----

#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <netinet/in.h>
#include <arpa/inet.h>

int
main(int argc, char *argv[])
{
        struct ifaddrs *ifaddr, *ifa;
        char host[NI_MAXHOST];
        int rc;

        if (getifaddrs(&ifaddr) == -1) {
                perror("getifaddrs");
                exit(EXIT_FAILURE);
        }

        for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
                struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)ifa->ifa_addr;

                if (ifa->ifa_addr == NULL)
                        continue;
                if (ifa->ifa_addr->sa_family != AF_INET6)
                        continue;

                rc = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
                    host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
                if (rc != 0) {
                        printf("getnameinfo() failed: %s\n", gai_strerror(rc));
                        exit(EXIT_FAILURE);
                }
                printf("dev: %-8s address: <%s> scope %d\n",
                    ifa->ifa_name, host, in6->sin6_scope_id);
        }

        freeifaddrs(ifaddr);
        exit(EXIT_SUCCESS);
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFAOGNQv3pW2RwmEkcv3Oez7eP%2BF_q872ayj0=UgxsytBkj3ug>