mirror of
https://github.com/samba-team/samba.git
synced 2024-12-27 03:21:53 +03:00
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-test
This commit is contained in:
commit
80ce9a3bbc
@ -40,7 +40,7 @@ test: all
|
||||
|
||||
installcheck: install test
|
||||
|
||||
TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o
|
||||
TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o
|
||||
|
||||
testsuite: libreplace.a $(TEST_OBJS)
|
||||
$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS)
|
||||
|
@ -109,38 +109,33 @@ int rep_getifaddrs(struct ifaddrs **ifap)
|
||||
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
for (i=n-1; i>=0; i--) {
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
|
||||
if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) == -1) {
|
||||
freeifaddrs(*ifap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
curif = calloc(1, sizeof(struct ifaddrs));
|
||||
curif->ifa_name = strdup(ifr[i].ifr_name);
|
||||
curif->ifa_flags = ifr[i].ifr_flags;
|
||||
curif->ifa_dstaddr = NULL;
|
||||
curif->ifa_data = NULL;
|
||||
curif->ifa_next = NULL;
|
||||
|
||||
curif->ifa_addr = NULL
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) {
|
||||
curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
|
||||
}
|
||||
|
||||
curif->ifa_netmask = NULL;
|
||||
if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != -1) {
|
||||
curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr);
|
||||
}
|
||||
|
||||
if (lastif == NULL) {
|
||||
*ifap = curif;
|
||||
} else {
|
||||
lastif->ifa_next = curif;
|
||||
}
|
||||
|
||||
curif->ifa_name = strdup(ifr[i].ifr_name);
|
||||
curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
|
||||
curif->ifa_dstaddr = NULL;
|
||||
curif->ifa_data = NULL;
|
||||
curif->ifa_next = NULL;
|
||||
curif->ifa_netmask = NULL;
|
||||
|
||||
if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) {
|
||||
freeifaddrs(*ifap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
curif->ifa_flags = ifr[i].ifr_flags;
|
||||
|
||||
if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
|
||||
freeifaddrs(*ifap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr);
|
||||
|
||||
lastif = curif;
|
||||
}
|
||||
|
||||
@ -363,32 +358,3 @@ int rep_getifaddrs(struct ifaddrs **ifap)
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef AUTOCONF_TEST
|
||||
/* this is the autoconf driver to test getifaddrs() */
|
||||
|
||||
int main()
|
||||
{
|
||||
struct ifaddrs *ifs = NULL;
|
||||
int ret;
|
||||
|
||||
ret = getifaddrs(&ifs);
|
||||
if (ret != 0) {
|
||||
perror("getifaddrs() failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (ifs) {
|
||||
printf("%-10s ", ifs->ifa_name);
|
||||
if (ifs->ifa_addr != NULL &&
|
||||
ifs->ifa_addr->sa_family == AF_INET) {
|
||||
printf("IP=%s ", inet_ntoa(((struct sockaddr_in *)ifs->ifa_addr)->sin_addr));
|
||||
if (ifs->ifa_netmask != NULL)
|
||||
printf("NETMASK=%s", inet_ntoa(((struct sockaddr_in *)ifs->ifa_netmask)->sin_addr));
|
||||
}
|
||||
printf("\n");
|
||||
ifs = ifs->ifa_next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -49,7 +49,10 @@ AC_TRY_RUN([
|
||||
#define AUTOCONF_TEST 1
|
||||
#define SOCKET_WRAPPER_NOT_REPLACE
|
||||
#include "$libreplacedir/replace.c"
|
||||
#include "$libreplacedir/getifaddrs.c"],
|
||||
#include "$libreplacedir/inet_ntop.c"
|
||||
#include "$libreplacedir/getifaddrs.c"
|
||||
#define getifaddrs_test main
|
||||
#include "$libreplacedir/test/getifaddrs.c"],
|
||||
libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
|
||||
if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
|
||||
iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
|
||||
@ -67,7 +70,10 @@ AC_TRY_RUN([
|
||||
#undef _XOPEN_SOURCE_EXTENDED
|
||||
#define SOCKET_WRAPPER_NOT_REPLACE
|
||||
#include "$libreplacedir/replace.c"
|
||||
#include "$libreplacedir/getifaddrs.c"],
|
||||
#include "$libreplacedir/inet_ntop.c"
|
||||
#include "$libreplacedir/getifaddrs.c"
|
||||
#define getifaddrs_test main
|
||||
#include "$libreplacedir/test/getifaddrs.c"],
|
||||
libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
|
||||
if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
|
||||
iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
|
||||
@ -84,7 +90,10 @@ AC_TRY_RUN([
|
||||
#define AUTOCONF_TEST 1
|
||||
#define SOCKET_WRAPPER_NOT_REPLACE
|
||||
#include "$libreplacedir/replace.c"
|
||||
#include "$libreplacedir/getifaddrs.c"],
|
||||
#include "$libreplacedir/inet_ntop.c"
|
||||
#include "$libreplacedir/getifaddrs.c"
|
||||
#define getifaddrs_test main
|
||||
#include "$libreplacedir/test/getifaddrs.c"],
|
||||
libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
|
||||
if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
|
||||
iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
|
||||
@ -100,7 +109,10 @@ AC_TRY_RUN([
|
||||
#define AUTOCONF_TEST 1
|
||||
#define SOCKET_WRAPPER_NOT_REPLACE
|
||||
#include "$libreplacedir/replace.c"
|
||||
#include "$libreplacedir/getifaddrs.c"],
|
||||
#include "$libreplacedir/inet_ntop.c"
|
||||
#include "$libreplacedir/getifaddrs.c"
|
||||
#define getifaddrs_test main
|
||||
#include "$libreplacedir/test/getifaddrs.c"],
|
||||
libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
|
||||
if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
|
||||
iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
|
||||
|
96
source/lib/replace/test/getifaddrs.c
Normal file
96
source/lib/replace/test/getifaddrs.c
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ PRIVATE_PROTO_HEADER = \
|
||||
OBJ_FILES = \
|
||||
../../lib/charset/tests/iconv.o \
|
||||
../../lib/talloc/testsuite.o \
|
||||
../../lib/replace/test/getifaddrs.o \
|
||||
../../lib/replace/test/os2_delete.o \
|
||||
../../lib/replace/test/strptime.o \
|
||||
../../lib/replace/test/testsuite.o \
|
||||
|
Loading…
Reference in New Issue
Block a user