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"
25 #include "replace-test.h"
29 #define rep_inet_ntop inet_ntop
32 static const char *format_sockaddr(struct sockaddr
*addr
,
36 const char *result
= NULL
;
38 if (addr
->sa_family
== AF_INET
) {
39 result
= rep_inet_ntop(AF_INET
,
40 &((struct sockaddr_in
*)addr
)->sin_addr
,
43 #ifdef HAVE_STRUCT_SOCKADDR_IN6
44 } else if (addr
->sa_family
== AF_INET6
) {
45 result
= rep_inet_ntop(AF_INET6
,
46 &((struct sockaddr_in6
*)addr
)->sin6_addr
,
54 int getifaddrs_test(void)
56 struct ifaddrs
*ifs
= NULL
;
57 struct ifaddrs
*ifs_head
= NULL
;
60 ret
= getifaddrs(&ifs
);
63 fprintf(stderr
, "getifaddrs() failed: %s\n", strerror(errno
));
68 printf("%-10s ", ifs
->ifa_name
);
69 if (ifs
->ifa_addr
!= NULL
) {
70 char addrstring
[INET6_ADDRSTRLEN
];
73 result
= format_sockaddr(ifs
->ifa_addr
,
77 printf("IP=%s ", addrstring
);
80 if (ifs
->ifa_netmask
!= NULL
) {
81 result
= format_sockaddr(ifs
->ifa_netmask
,
85 printf("NETMASK=%s", addrstring
);
88 printf("AF=%d ", ifs
->ifa_addr
->sa_family
);
91 printf("<no address>");
98 freeifaddrs(ifs_head
);