diff options
author | Andrew Bartlett <abartlet@samba.org> | 2008-02-29 10:09:35 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2008-02-29 10:09:35 +1100 |
commit | 99c61a0804378433f2b577c3cbe3026e14f188a2 (patch) | |
tree | 5fa5f149c1053e0a8ade0d760852a241f13dc606 /source4/lib/replace/test | |
parent | 3eef0664c59c7afef117132c1d2ebccf22ad748e (diff) | |
parent | 53654f5caf701a32b615bed784d78765f351cb73 (diff) | |
download | samba-99c61a0804378433f2b577c3cbe3026e14f188a2.tar.gz samba-99c61a0804378433f2b577c3cbe3026e14f188a2.tar.bz2 samba-99c61a0804378433f2b577c3cbe3026e14f188a2.zip |
Merge branch 'v4-0-test' of git://git.samba.org/samba into 4-0-local
(This used to be commit f002a98c7ae0fc93cc738fde1ee62534f8e576ac)
Diffstat (limited to 'source4/lib/replace/test')
-rw-r--r-- | source4/lib/replace/test/getifaddrs.c | 96 | ||||
-rw-r--r-- | source4/lib/replace/test/testsuite.c | 9 |
2 files changed, 99 insertions, 6 deletions
diff --git a/source4/lib/replace/test/getifaddrs.c b/source4/lib/replace/test/getifaddrs.c new file mode 100644 index 0000000000..66eed70268 --- /dev/null +++ b/source4/lib/replace/test/getifaddrs.c @@ -0,0 +1,96 @@ +/* + * Unix SMB/CIFS implementation. + * + * libreplace getifaddrs test + * + * Copyright (C) Michael Adam <obnox@samba.org> 2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef AUTOCONF_TEST +#include "replace.h" +#include "system/network.h" +#endif + +#ifdef HAVE_INET_NTOP +#define rep_inet_ntop inet_ntop +#endif + +static const char *format_sockaddr(struct sockaddr *addr, + char *addrstring, + socklen_t addrlen) +{ + const char *result = NULL; + + if (addr->sa_family == AF_INET) { + result = rep_inet_ntop(AF_INET, + &((struct sockaddr_in *)addr)->sin_addr, + addrstring, + addrlen); + } else if (addr->sa_family == AF_INET6) { + result = rep_inet_ntop(AF_INET6, + &((struct sockaddr_in6 *)addr)->sin6_addr, + addrstring, + addrlen); + } + return result; +} + +int getifaddrs_test(void) +{ + struct ifaddrs *ifs = NULL; + int ret; + + ret = getifaddrs(&ifs); + if (ret != 0) { + fprintf(stderr, "getifaddrs() failed: %s", strerror(errno)); + return 1; + } + + while (ifs) { + printf("%-10s ", ifs->ifa_name); + if (ifs->ifa_addr != NULL) { + char addrstring[INET6_ADDRSTRLEN]; + const char *result; + + result = format_sockaddr(ifs->ifa_addr, + addrstring, + sizeof(addrstring)); + if (result != NULL) { + printf("IP=%s ", addrstring); + } + + if (ifs->ifa_netmask != NULL) { + result = format_sockaddr(ifs->ifa_netmask, + addrstring, + sizeof(addrstring)); + if (result != NULL) { + printf("NETMASK=%s", addrstring); + } + } else { + printf("AF=%d ", ifs->ifa_addr->sa_family); + } + } else { + printf("<no address>"); + } + + printf("\n"); + ifs = ifs->ifa_next; + } + + freeifaddrs(ifs); + + return 0; +} diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c index c9f3301005..b538360365 100644 --- a/source4/lib/replace/test/testsuite.c +++ b/source4/lib/replace/test/testsuite.c @@ -856,21 +856,18 @@ static int test_strptime(void) return libreplace_test_strptime(); } +extern int getifaddrs_test(void); + static int test_getifaddrs(void) { - struct ifaddrs *ifa; - int ret; printf("test: getifaddrs\n"); - ret = getifaddrs(&ifa); - if (ret != 0) { + if (getifaddrs_test() != 0) { printf("failure: getifaddrs\n"); return false; } - freeifaddrs(ifa); - printf("success: getifaddrs\n"); return true; } |