Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 17 Nov 2015 11:33:48 +0100
From: Jo-Philipp Wich <>
Subject: Fix handling of peer-to-peer interfaces in getifaddrs()

properly handle point-to-point interfaces in getifaddrs()

With point-to-point interfaces, the IFA_ADDRESS netlink attribute contains
the peer address while an extra attribute IFA_LOCAL carries the actual local
interface address.

Currently musl lacks any treatment of IFA_LOCAL leading to bogus results
when using getifaddrs() to obtain the local and remote IP addresses of
point-to-point interfaces like ppp ones.

The following test case illustrates the problem:

-- 8< --
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <stdio.h>
int main(int argc, char **argv) {
        struct ifaddrs *ifa, *ifap;
        char local[32];
        char remote[32];
        if (!getifaddrs(&ifa)) {
                for (ifap = ifa; ifap; ifap = ifap->ifa_next) {
                        if (!ifap->ifa_name || strcmp(ifap->ifa_name, argv[1]) ||
                            !ifap->ifa_addr || ifap->ifa_addr->sa_family != AF_INET)
                        inet_ntop(AF_INET, &((struct sockaddr_in *)ifap->ifa_addr)->sin_addr, local, sizeof(local));
                        if (ifap->ifa_dstaddr)
                                inet_ntop(AF_INET, &((struct sockaddr_in *)ifap->ifa_dstaddr)->sin_addr, remote, sizeof(remote));
                                strcpy(remote, "(null)");
                        printf("local addr = %s / remote addr = %s\n", local, remote);
        return 0;
-- >8 --

I used the following command sequence to assert the results:

$ gcc -o /tmp/ifa /tmp/ifa.c
$ ip link add name dummy0 type dummy
$ ip addr add peer dev dummy0
$ /tmp/ifa dummy0

That led to the following result on musl:

  local addr = / remote addr = (null)

Note that the local address is unexpectedly while it should be
and the remote address is not set at all.

Running the same test on an ordinary glibc system (Debian) and on an uclibc
based OpenWrt gives the correct result:

  local addr = / remote addr =

The proposed change adds special treatment of IFA_LOCAL to getifaddrs(),
following the logic used in uclibc and glibc implementations.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.