On 09.12.15 18:25, Ken Moore wrote:

Simple example:

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include <err.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char **argv)
{
        char buf[INET6_ADDRSTRLEN];
        struct ifaddrs *ifap, *ifa;
        int error;

        if (getifaddrs(&ifap) != 0)
                err(1, "getifaddrs");
        for (ifa = ifap; ifa; ifa = ifa->ifa_next)
                if (ifa->ifa_addr->sa_family == AF_INET6) {
                        error = getnameinfo(ifa->ifa_addr,
                            ifa->ifa_addr->sa_len, buf, sizeof(buf),
                            NULL, 0, NI_NUMERICHOST);
                        if (error != 0)
                                err(1, "%s", gai_strerror(error));
                        printf("%s\n", buf);
                }
        freeifaddrs(ifap);
        return (0);
}

-- 
WBR, Andrey V. Elsukov

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to