2
* Unix SMB/CIFS implementation.
4
* libreplace getifaddrs test
6
* Copyright (C) Michael Adam <obnox@samba.org> 2008
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 3 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include "system/network.h"
28
#define rep_inet_ntop inet_ntop
31
static const char *format_sockaddr(struct sockaddr *addr,
35
const char *result = NULL;
37
if (addr->sa_family == AF_INET) {
38
result = rep_inet_ntop(AF_INET,
39
&((struct sockaddr_in *)addr)->sin_addr,
42
#ifdef HAVE_STRUCT_SOCKADDR_IN6
43
} else if (addr->sa_family == AF_INET6) {
44
result = rep_inet_ntop(AF_INET6,
45
&((struct sockaddr_in6 *)addr)->sin6_addr,
53
int getifaddrs_test(void)
55
struct ifaddrs *ifs = NULL;
56
struct ifaddrs *ifs_head = NULL;
59
ret = getifaddrs(&ifs);
62
fprintf(stderr, "getifaddrs() failed: %s\n", strerror(errno));
67
printf("%-10s ", ifs->ifa_name);
68
if (ifs->ifa_addr != NULL) {
69
char addrstring[INET6_ADDRSTRLEN];
72
result = format_sockaddr(ifs->ifa_addr,
76
printf("IP=%s ", addrstring);
79
if (ifs->ifa_netmask != NULL) {
80
result = format_sockaddr(ifs->ifa_netmask,
84
printf("NETMASK=%s", addrstring);
87
printf("AF=%d ", ifs->ifa_addr->sa_family);
90
printf("<no address>");
97
freeifaddrs(ifs_head);