1 /* $Id: testgetifaddr.c,v 1.8 2014/03/09 23:09:36 nanard Exp $ */
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2014 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
14 #include "getifaddr.h"
17 /* solaris 10 does not define LOG_PERROR */
21 int main(int argc
, char * * argv
) {
30 fprintf(stderr
, "Usage:\t%s interface_name\n", argv
[0]);
34 openlog("testgetifaddr", LOG_CONS
|LOG_PERROR
, LOG_USER
);
35 if(getifaddr(argv
[1], str_addr
, sizeof(str_addr
), &addr
, &mask
) < 0) {
36 fprintf(stderr
, "Cannot get address for interface %s.\n", argv
[1]);
39 printf("Interface %s has IP address %s.\n", argv
[1], str_addr
);
40 printf("addr=%s ", inet_ntoa(addr
));
41 printf("mask=%s\n", inet_ntoa(mask
));
43 r
= find_ipv6_addr(argv
[1], str_addr6
, sizeof(str_addr6
));
45 fprintf(stderr
, "find_ipv6_addr() failed\n");
48 printf("Interface %s has no IPv6 address.\n", argv
[1]);
50 printf("Interface %s has IPv6 address %s.\n", argv
[1], str_addr6
);