2 * Unix SMB/CIFS implementation.
4 * libreplace getifaddrs test
6 * Copyright (C) Michael Adam <obnox@samba.org> 2008
8 * ** NOTE! The following LGPL license applies to the replace
9 * ** library. This does NOT imply that all of Samba is released
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 3 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 #include "system/network.h"
29 #include "replace-test.h"
33 #define rep_inet_ntop inet_ntop
36 static const char *format_sockaddr(struct sockaddr
*addr
,
40 const char *result
= NULL
;
42 if (addr
->sa_family
== AF_INET
) {
43 result
= rep_inet_ntop(AF_INET
,
44 &((struct sockaddr_in
*)addr
)->sin_addr
,
47 #ifdef HAVE_STRUCT_SOCKADDR_IN6
48 } else if (addr
->sa_family
== AF_INET6
) {
49 result
= rep_inet_ntop(AF_INET6
,
50 &((struct sockaddr_in6
*)addr
)->sin6_addr
,
58 int getifaddrs_test(void)
60 struct ifaddrs
*ifs
= NULL
;
61 struct ifaddrs
*ifs_head
= NULL
;
64 ret
= getifaddrs(&ifs
);
67 fprintf(stderr
, "getifaddrs() failed: %s\n", strerror(errno
));
72 printf("%-10s ", ifs
->ifa_name
);
73 if (ifs
->ifa_addr
!= NULL
) {
74 char addrstring
[INET6_ADDRSTRLEN
];
77 result
= format_sockaddr(ifs
->ifa_addr
,
81 printf("IP=%s ", addrstring
);
84 if (ifs
->ifa_netmask
!= NULL
) {
85 result
= format_sockaddr(ifs
->ifa_netmask
,
89 printf("NETMASK=%s", addrstring
);
92 printf("AF=%d ", ifs
->ifa_addr
->sa_family
);
95 printf("<no address>");
102 freeifaddrs(ifs_head
);