diff options
Diffstat (limited to 'source3/lib/replace')
| -rw-r--r-- | source3/lib/replace/Makefile.in | 6 | ||||
| -rw-r--r-- | source3/lib/replace/README | 2 | ||||
| -rw-r--r-- | source3/lib/replace/configure.ac | 2 | ||||
| -rw-r--r-- | source3/lib/replace/dlfcn.c | 2 | ||||
| -rw-r--r-- | source3/lib/replace/getifaddrs.c | 361 | ||||
| -rw-r--r-- | source3/lib/replace/getifaddrs.m4 | 127 | ||||
| -rw-r--r-- | source3/lib/replace/getpass.c | 5 | ||||
| -rw-r--r-- | source3/lib/replace/getpass.m4 | 12 | ||||
| -rw-r--r-- | source3/lib/replace/libreplace.m4 | 74 | ||||
| -rw-r--r-- | source3/lib/replace/libreplace_ld.m4 | 4 | ||||
| -rw-r--r-- | source3/lib/replace/replace.h | 20 | ||||
| -rw-r--r-- | source3/lib/replace/socket.c | 35 | ||||
| -rw-r--r-- | source3/lib/replace/socket.m4 | 40 | ||||
| -rw-r--r-- | source3/lib/replace/system/config.m4 | 16 | ||||
| -rw-r--r-- | source3/lib/replace/system/network.h | 48 | ||||
| -rw-r--r-- | source3/lib/replace/test/getifaddrs.c | 100 | ||||
| -rw-r--r-- | source3/lib/replace/test/testsuite.c | 17 | 
17 files changed, 808 insertions, 63 deletions
| diff --git a/source3/lib/replace/Makefile.in b/source3/lib/replace/Makefile.in index 30f39ac6cb..c989835a8d 100644 --- a/source3/lib/replace/Makefile.in +++ b/source3/lib/replace/Makefile.in @@ -10,6 +10,7 @@ VPATH = @libreplacedir@  srcdir = @srcdir@  builddir = @builddir@  INSTALL = @INSTALL@ +LIBS = @LIBS@  .PHONY: test all showflags install installcheck clean distclean realdistclean @@ -25,6 +26,7 @@ showflags:  	@echo '  CC     = $(CC)'  	@echo '  CFLAGS = $(CFLAGS)'  	@echo '  LDFLAGS= $(LDFLAGS)' +	@echo '  LIBS   = $(LIBS)'  install: all  	mkdir -p $(libdir) @@ -38,10 +40,10 @@ 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) +	$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS)  .c.o:  	@echo Compiling $*.c diff --git a/source3/lib/replace/README b/source3/lib/replace/README index c61f78a951..268a1b15cf 100644 --- a/source3/lib/replace/README +++ b/source3/lib/replace/README @@ -60,6 +60,8 @@ getaddrinfo  freeaddrinfo  getnameinfo  gai_strerror +getifaddrs +freeifaddrs  Types:  bool diff --git a/source3/lib/replace/configure.ac b/source3/lib/replace/configure.ac index beeb77e152..f5e054f476 100644 --- a/source3/lib/replace/configure.ac +++ b/source3/lib/replace/configure.ac @@ -3,6 +3,8 @@ AC_INIT(replace.c)  AC_CONFIG_SRCDIR([replace.c])  AC_CONFIG_HEADER(config.h) +CFLAGS="$CFLAGS -I$srcdir" +  AC_LIBREPLACE_ALL_CHECKS  if test "$ac_cv_prog_gcc" = yes; then diff --git a/source3/lib/replace/dlfcn.c b/source3/lib/replace/dlfcn.c index 42848848e8..3b109d7e40 100644 --- a/source3/lib/replace/dlfcn.c +++ b/source3/lib/replace/dlfcn.c @@ -35,6 +35,8 @@ void *rep_dlopen(const char *name, int flags)  #endif  {  #ifdef HAVE_SHL_LOAD +	if (name == NULL) +		return PROG_HANDLE;  	return (void *)shl_load(name, flags, 0);  #else  	return NULL; diff --git a/source3/lib/replace/getifaddrs.c b/source3/lib/replace/getifaddrs.c new file mode 100644 index 0000000000..f6f0ec080c --- /dev/null +++ b/source3/lib/replace/getifaddrs.c @@ -0,0 +1,361 @@ +/*  +   Unix SMB/CIFS implementation. +   Samba utility functions +   Copyright (C) Andrew Tridgell 1998 +   Copyright (C) Jeremy Allison 2007 +   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +    +   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/>. +*/ + +#define SOCKET_WRAPPER_NOT_REPLACE + +#include "replace.h" +#include "system/network.h" + +#include <unistd.h> +#include <stdio.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + +#ifndef SIOCGIFCONF +#ifdef HAVE_SYS_SOCKIO_H +#include <sys/sockio.h> +#endif +#endif + +#ifdef HAVE_IFACE_GETIFADDRS +#define _FOUND_IFACE_ANY +#else + +void rep_freeifaddrs(struct ifaddrs *ifp) +{ +	if (ifp != NULL) { +		free(ifp->ifa_name); +		free(ifp->ifa_addr); +		free(ifp->ifa_netmask); +		free(ifp->ifa_dstaddr); +		freeifaddrs(ifp->ifa_next); +		free(ifp); +	} +} + +static struct sockaddr *sockaddr_dup(struct sockaddr *sa) +{ +	struct sockaddr *ret; +	socklen_t socklen; +#ifdef HAVE_SOCKADDR_SA_LEN +	socklen = sa->sa_len; +#else +	socklen = sizeof(struct sockaddr_storage); +#endif +	ret = calloc(1, socklen); +	if (ret == NULL) +		return NULL; +	memcpy(ret, sa, socklen); +	return ret; +} +#endif + +#if HAVE_IFACE_IFCONF + +/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 +   V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. + +   It probably also works on any BSD style system.  */ + +int rep_getifaddrs(struct ifaddrs **ifap) +{ +	struct ifconf ifc; +	char buff[8192]; +	int fd, i, n; +	struct ifreq *ifr=NULL; +	struct in_addr ipaddr; +	struct in_addr nmask; +	char *iname; +	struct ifaddrs *curif; +	struct ifaddrs *lastif = NULL; + +	*ifap = NULL; + +	if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +		return -1; +	} +   +	ifc.ifc_len = sizeof(buff); +	ifc.ifc_buf = buff; + +	if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { +		close(fd); +		return -1; +	}  + +	ifr = ifc.ifc_req; +   +	n = ifc.ifc_len / sizeof(struct ifreq); + +	/* Loop through interfaces, looking for given IP address */ +	for (i=n-1; i>=0; i--) { +		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; +		} +		lastif = curif; +	} + +	close(fd); + +	return 0; +}   + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_IFCONF */ +#ifdef HAVE_IFACE_IFREQ + +#ifndef I_STR +#include <sys/stropts.h> +#endif + +/**************************************************************************** +this should cover most of the streams based systems +Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code +****************************************************************************/ +int rep_getifaddrs(struct ifaddrs **ifap) +{ +	struct ifreq ifreq; +	struct strioctl strioctl; +	char buff[8192]; +	int fd, i, n; +	struct ifreq *ifr=NULL; +	struct in_addr ipaddr; +	struct in_addr nmask; +	char *iname; +	struct ifaddrs *curif; +	struct ifaddrs *lastif = NULL; + +	*ifap = NULL; + +	if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +		return -1; +	} +   +	strioctl.ic_cmd = SIOCGIFCONF; +	strioctl.ic_dp  = buff; +	strioctl.ic_len = sizeof(buff); +	if (ioctl(fd, I_STR, &strioctl) < 0) { +		close(fd); +		return -1; +	}  + +	/* we can ignore the possible sizeof(int) here as the resulting +	   number of interface structures won't change */ +	n = strioctl.ic_len / sizeof(struct ifreq); + +	/* we will assume that the kernel returns the length as an int +           at the start of the buffer if the offered size is a +           multiple of the structure size plus an int */ +	if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { +		ifr = (struct ifreq *)(buff + sizeof(int));   +	} else { +		ifr = (struct ifreq *)buff;   +	} + +	/* Loop through interfaces */ + +	for (i = 0; i<n; i++) { +		ifreq = ifr[i]; +   +		curif = calloc(1, sizeof(struct ifaddrs)); +		if (lastif == NULL) { +			*ifap = curif; +		} else { +			lastif->ifa_next = curif; +		} + +		strioctl.ic_cmd = SIOCGIFFLAGS; +		strioctl.ic_dp  = (char *)&ifreq; +		strioctl.ic_len = sizeof(struct ifreq); +		if (ioctl(fd, I_STR, &strioctl) != 0) { +			freeifaddrs(*ifap); +			return -1; +		} + +		curif->ifa_flags = ifreq.ifr_flags; +		 +		strioctl.ic_cmd = SIOCGIFADDR; +		strioctl.ic_dp  = (char *)&ifreq; +		strioctl.ic_len = sizeof(struct ifreq); +		if (ioctl(fd, I_STR, &strioctl) != 0) { +			freeifaddrs(*ifap); +			return -1; +		} + +		curif->ifa_name = strdup(ifreq.ifr_name); +		curif->ifa_addr = sockaddr_dup(&ifreq.ifr_addr); +		curif->ifa_dstaddr = NULL; +		curif->ifa_data = NULL; +		curif->ifa_next = NULL; +		curif->ifa_netmask = NULL; + +		strioctl.ic_cmd = SIOCGIFNETMASK; +		strioctl.ic_dp  = (char *)&ifreq; +		strioctl.ic_len = sizeof(struct ifreq); +		if (ioctl(fd, I_STR, &strioctl) != 0) { +			freeifaddrs(*ifap); +			return -1; +		} + +		curif->ifa_netmask = sockaddr_dup(&ifreq.ifr_addr); + +		lastif = curif; +	} + +	close(fd); + +	return 0; +} + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_IFREQ */ +#ifdef HAVE_IFACE_AIX + +/**************************************************************************** +this one is for AIX (tested on 4.2) +****************************************************************************/ +int rep_getifaddrs(struct ifaddrs **ifap) +{ +	char buff[8192]; +	int fd, i; +	struct ifconf ifc; +	struct ifreq *ifr=NULL; +	struct in_addr ipaddr; +	struct in_addr nmask; +	char *iname; +	struct ifaddrs *curif; +	struct ifaddrs *lastif = NULL; + +	*ifap = NULL; + +	if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +		return -1; +	} + +	ifc.ifc_len = sizeof(buff); +	ifc.ifc_buf = buff; + +	if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { +		close(fd); +		return -1; +	} + +	ifr = ifc.ifc_req; + +	/* Loop through interfaces */ +	i = ifc.ifc_len; + +	while (i > 0) { +		uint_t inc; + +		inc = ifr->ifr_addr.sa_len; + +		if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { +			freeaddrinfo(*ifap); +			return -1; +		} + +		curif = calloc(1, sizeof(struct ifaddrs)); +		if (lastif == NULL) { +			*ifap = curif; +		} else { +			lastif->ifa_next = curif; +		} + +		curif->ifa_name = strdup(ifr->ifr_name); +		curif->ifa_addr = sockaddr_dup(&ifr->ifr_addr); +		curif->ifa_dstaddr = NULL; +		curif->ifa_data = NULL; +		curif->ifa_netmask = NULL; +		curif->ifa_next = NULL; + +		if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { +			freeaddrinfo(*ifap); +			return -1; +		} + +		curif->ifa_flags = ifr->ifr_flags; + +		if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { +			freeaddrinfo(*ifap); +			return -1; +		} + +		curif->ifa_netmask = sockaddr_dup(&ifr->ifr_addr); + +		lastif = curif; + +	next: +		/* +		 * Patch from Archie Cobbs (archie@whistle.com).  The +		 * addresses in the SIOCGIFCONF interface list have a +		 * minimum size. Usually this doesn't matter, but if +		 * your machine has tunnel interfaces, etc. that have +		 * a zero length "link address", this does matter.  */ + +		if (inc < sizeof(ifr->ifr_addr)) +			inc = sizeof(ifr->ifr_addr); +		inc += IFNAMSIZ; + +		ifr = (struct ifreq*) (((char*) ifr) + inc); +		i -= inc; +	} + +	close(fd); +	return 0; +} + +#define _FOUND_IFACE_ANY +#endif /* HAVE_IFACE_AIX */ +#ifndef _FOUND_IFACE_ANY +int rep_getifaddrs(struct ifaddrs **ifap) +{ +	errno = ENOSYS; +	return -1; +} +#endif diff --git a/source3/lib/replace/getifaddrs.m4 b/source3/lib/replace/getifaddrs.m4 new file mode 100644 index 0000000000..6cca155de3 --- /dev/null +++ b/source3/lib/replace/getifaddrs.m4 @@ -0,0 +1,127 @@ +AC_CHECK_HEADERS([ifaddrs.h]) + +dnl Used when getifaddrs is not available +AC_CHECK_MEMBERS([struct sockaddr.sa_len],  +	 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])], +	 [], +	 [#include <sys/socket.h>]) + +dnl test for getifaddrs and freeifaddrs +AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[ +AC_TRY_COMPILE([ +#include <sys/types.h> +#if STDC_HEADERS +#include <stdlib.h> +#include <stddef.h> +#endif +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <ifaddrs.h> +#include <netdb.h>], +[ +struct ifaddrs *ifp = NULL; +int ret = getifaddrs (&ifp); +freeifaddrs(ifp); +], +libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)]) +if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then +    AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs]) +    AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs]) +	AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available]) +fi + +################## +# look for a method of finding the list of network interfaces +# +# This tests need LIBS="$NSL_LIBS $SOCKET_LIBS" +# +old_LIBS=$LIBS +LIBS="$NSL_LIBS $SOCKET_LIBS" +iface=no; +################## +# look for a method of finding the list of network interfaces +iface=no; +AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[ +AC_TRY_RUN([ +#define HAVE_IFACE_GETIFADDRS 1 +#define NO_CONFIG_H 1 +#define AUTOCONF_TEST 1 +#define SOCKET_WRAPPER_NOT_REPLACE +#include "$libreplacedir/replace.c" +#include "$libreplacedir/inet_ntop.c" +#include "$libreplacedir/snprintf.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]) +else +	LIBREPLACEOBJ="${LIBREPLACEOBJ} getifaddrs.o" +fi + + +if test $iface = no; then +AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[ +AC_TRY_RUN([ +#define HAVE_IFACE_AIX 1 +#define NO_CONFIG_H 1 +#define AUTOCONF_TEST 1 +#undef _XOPEN_SOURCE_EXTENDED +#define SOCKET_WRAPPER_NOT_REPLACE +#include "$libreplacedir/replace.c" +#include "$libreplacedir/inet_ntop.c" +#include "$libreplacedir/snprintf.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]) +	old_LIBS="$old_LIBS $LIBS" +fi +fi + + +if test $iface = no; then +AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[ +AC_TRY_RUN([ +#define HAVE_IFACE_IFCONF 1 +#define NO_CONFIG_H 1 +#define AUTOCONF_TEST 1 +#define SOCKET_WRAPPER_NOT_REPLACE +#include "$libreplacedir/replace.c" +#include "$libreplacedir/inet_ntop.c" +#include "$libreplacedir/snprintf.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]) +	old_LIBS="$old_LIBS $LIBS" +fi +fi + +if test $iface = no; then +AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[ +AC_TRY_RUN([ +#define HAVE_IFACE_IFREQ 1 +#define NO_CONFIG_H 1 +#define AUTOCONF_TEST 1 +#define SOCKET_WRAPPER_NOT_REPLACE +#include "$libreplacedir/replace.c" +#include "$libreplacedir/inet_ntop.c" +#include "$libreplacedir/snprintf.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]) +	old_LIBS="$old_LIBS $LIBS" +fi +fi + +LIBS=$old_LIBS diff --git a/source3/lib/replace/getpass.c b/source3/lib/replace/getpass.c index d91d029f6a..57e28eb981 100644 --- a/source3/lib/replace/getpass.c +++ b/source3/lib/replace/getpass.c @@ -185,7 +185,10 @@ char *rep_getpass(const char *prompt)  	buf[0] = 0;  	if (!gotintr) {  		in_fd = fileno(in); -		fgets(buf, bufsize, in); +		if (fgets(buf, bufsize, in) == NULL) { +			buf[0] = 0; +			return buf; +		}  	}  	nread = strlen(buf);  	if (nread) { diff --git a/source3/lib/replace/getpass.m4 b/source3/lib/replace/getpass.m4 index c4da9aae59..b93817f9d3 100644 --- a/source3/lib/replace/getpass.m4 +++ b/source3/lib/replace/getpass.m4 @@ -1,22 +1,22 @@ -AC_CHECK_FUNC(getpass, samba_cv_HAVE_GETPASS=yes) -AC_CHECK_FUNC(getpassphrase, samba_cv_HAVE_GETPASSPHRASE=yes) -if test x"$samba_cv_HAVE_GETPASS" = x"yes" -a x"$samba_cv_HAVE_GETPASSPHRASE" = x"yes"; then +AC_CHECK_FUNC(getpass, libreplace_cv_HAVE_GETPASS=yes) +AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes) +if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then          AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars])  	AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])  	LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"  else -AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[ +AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[  SAVE_CPPFLAGS="$CPPFLAGS"  CPPFLAGS="$CPPFLAGS -I$libreplacedir/"  AC_TRY_COMPILE([  #include "confdefs.h"  #define NO_CONFIG_H  #include "$libreplacedir/getpass.c" -],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no) +],[],libreplace_cv_REPLACE_GETPASS=yes,libreplace_cv_REPLACE_GETPASS=no)  CPPFLAGS="$SAVE_CPPFLAGS"  ]) -if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then +if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then  	AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])  	LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"  fi diff --git a/source3/lib/replace/libreplace.m4 b/source3/lib/replace/libreplace.m4 index f866b3648f..e0cc57f4c8 100644 --- a/source3/lib/replace/libreplace.m4 +++ b/source3/lib/replace/libreplace.m4 @@ -85,10 +85,10 @@ AC_INCLUDES_DEFAULT  #endif]  ) -AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[ +AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[  AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"], -           samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)]) -if test x"$samba_cv_HAVE_MMAP" = x"yes"; then +           libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)]) +if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then      AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])  fi @@ -120,7 +120,7 @@ if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then  	AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)  fi -AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[ +AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[  AC_TRY_RUN([  #include <stdio.h>  #include <unistd.h> @@ -133,8 +133,8 @@ main() { struct in_addr ip; ip.s_addr = 0x12345678;  if (strcmp(inet_ntoa(ip),"18.52.86.120") &&      strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }   exit(1);}], -           samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)]) -if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then +           libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)]) +if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then      AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])  fi @@ -182,7 +182,7 @@ AC_HAVE_DECL(setresuid, [#include <unistd.h>])  AC_HAVE_DECL(setresgid, [#include <unistd.h>])  AC_HAVE_DECL(errno, [#include <errno.h>]) -AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[ +AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[  AC_TRY_RUN([#include <stdlib.h>  #include <sys/types.h>  #include <sys/stat.h> @@ -197,10 +197,10 @@ main() {    if ((st.st_mode & 0777) != 0600) exit(1);    exit(0);  }], -samba_cv_HAVE_SECURE_MKSTEMP=yes, -samba_cv_HAVE_SECURE_MKSTEMP=no, -samba_cv_HAVE_SECURE_MKSTEMP=cross)]) -if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then +libreplace_cv_HAVE_SECURE_MKSTEMP=yes, +libreplace_cv_HAVE_SECURE_MKSTEMP=no, +libreplace_cv_HAVE_SECURE_MKSTEMP=cross)]) +if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then      AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])  fi @@ -209,7 +209,7 @@ AC_CHECK_HEADERS(stdio.h strings.h)  AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])  AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf) -AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[ +AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[  AC_TRY_RUN([  #include <sys/types.h>  #include <stdio.h> @@ -243,43 +243,43 @@ void foo(const char *format, ...) {  }  main() { foo("hello"); }  ], -samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)]) -if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then +libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)]) +if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then      AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])  fi  dnl VA_COPY -AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[ +AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[  AC_TRY_LINK([#include <stdarg.h>  va_list ap1,ap2;], [va_copy(ap1,ap2);], -samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)]) -if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then +libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)]) +if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then      AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])  fi -if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then -AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[ +if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then +AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[  AC_TRY_LINK([#include <stdarg.h>  va_list ap1,ap2;], [__va_copy(ap1,ap2);], -samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)]) -if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then +libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)]) +if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then      AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])  fi  fi  dnl __FUNCTION__ macro -AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[ +AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[  AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);], -samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)]) -if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then +libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)]) +if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then      AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])  else      dnl __func__ macro -    AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[ +    AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[      AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);], -    samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)]) -    if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then +    libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)]) +    if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then         AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])      fi  fi @@ -302,7 +302,7 @@ eprintf("bla", "bar");  ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available])) -AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [ +AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [      AC_TRY_COMPILE([  #include <sys/types.h>  #if STDC_HEADERS @@ -310,30 +310,30 @@ AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [  #include <stddef.h>  #endif  #include <signal.h>],[sig_atomic_t i = 0], -	samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)]) -if test x"$samba_cv_sig_atomic_t" = x"yes"; then +	libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)]) +if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then     AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])  fi -AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[ +AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[  AC_TRY_COMPILE([  #include <unistd.h>  #ifdef HAVE_FCNTL_H  #include <fcntl.h>  #endif],  [int fd = open("/dev/null", O_DIRECT);], -samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)]) -if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then +libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)]) +if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then      AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])  fi  dnl Check if the C compiler understands volatile (it should, being ANSI). -AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [ +AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [  	AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0], -		samba_cv_volatile=yes,samba_cv_volatile=no)]) -if test x"$samba_cv_volatile" = x"yes"; then +		libreplace_cv_volatile=yes,libreplace_cv_volatile=no)]) +if test x"$libreplace_cv_volatile" = x"yes"; then  	AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])  fi @@ -344,10 +344,12 @@ m4_include(getpass.m4)  m4_include(strptime.m4)  m4_include(win32.m4)  m4_include(timegm.m4) +m4_include(socket.m4)  m4_include(inet_ntop.m4)  m4_include(inet_pton.m4)  m4_include(getaddrinfo.m4)  m4_include(repdir.m4) +m4_include(getifaddrs.m4)  AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])]) diff --git a/source3/lib/replace/libreplace_ld.m4 b/source3/lib/replace/libreplace_ld.m4 index 08defb091f..f0d10c1e3e 100644 --- a/source3/lib/replace/libreplace_ld.m4 +++ b/source3/lib/replace/libreplace_ld.m4 @@ -246,10 +246,6 @@ AC_DEFUN([AC_LD_SONAMEFLAG],  			# Not supported  			SONAMEFLAG="#"  			;; -		*aix*) -			# Not supported -			SONAMEFLAG="#" -			;;  		esac  ]) diff --git a/source3/lib/replace/replace.h b/source3/lib/replace/replace.h index 1d1cbc2cd2..0d16f4ffd0 100644 --- a/source3/lib/replace/replace.h +++ b/source3/lib/replace/replace.h @@ -340,6 +340,26 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)  /* prototype is in "system/network.h" */  #endif +#ifndef HAVE_CONNECT +#define connect rep_connect +/* prototype is in "system/network.h" */ +#endif + +#ifndef HAVE_GETHOSTBYNAME +#define gethostbyname rep_gethostbyname +/* prototype is in "system/network.h" */ +#endif + +#ifndef HAVE_GETIFADDRS +#define getifaddrs rep_getifaddrs +/* prototype is in "system/network.h" */ +#endif + +#ifndef HAVE_FREEIFADDRS +#define freeifaddrs rep_freeifaddrs +/* prototype is in "system/network.h" */ +#endif +  #ifdef HAVE_LIMITS_H  #include <limits.h>  #endif diff --git a/source3/lib/replace/socket.c b/source3/lib/replace/socket.c new file mode 100644 index 0000000000..35e975fce7 --- /dev/null +++ b/source3/lib/replace/socket.c @@ -0,0 +1,35 @@ +/* + * Unix SMB/CIFS implementation. + * + * Dummy replacements for socket functions. + * + * 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/>. + */ + +#include "replace.h" +#include "system/network.h" + +int rep_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) +{ +	errno = ENOSYS; +	return -1; +} + +struct hostent *rep_gethostbyname(const char *name) +{ +	errno = ENOSYS; +	return NULL; +} diff --git a/source3/lib/replace/socket.m4 b/source3/lib/replace/socket.m4 new file mode 100644 index 0000000000..c0c8f93e81 --- /dev/null +++ b/source3/lib/replace/socket.m4 @@ -0,0 +1,40 @@ +dnl The following test is roughl taken from the cvs sources. +dnl +dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet. +dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has +dnl libsocket.so which has a bad implementation of gethostbyname (it +dnl only looks in /etc/hosts), so we only look for -lsocket if we need +dnl it. +AC_CHECK_FUNCS(connect) +if test x"$ac_cv_func_connect" = x"no"; then +	AC_CHECK_LIB_EXT(nsl_s, SOCKET_LIBS, connect) +	AC_CHECK_LIB_EXT(nsl, SOCKET_LIBS, connect) +	AC_CHECK_LIB_EXT(socket, SOCKET_LIBS, connect) +	AC_CHECK_LIB_EXT(inet, SOCKET_LIBS, connect) +	dnl We can't just call AC_CHECK_FUNCS(connect) here, +	dnl because the value has been cached. +	if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" || +		test x"$ac_cv_lib_ext_nsl_connect" = x"yes" || +		test x"$ac_cv_lib_ext_socket_connect" = x"yes" || +		test x"$ac_cv_lib_ext_inet_connect" = x"yes" +	then +		AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()]) +	fi +fi + +AC_CHECK_FUNCS(gethostbyname) +if test x"$ac_cv_func_gethostbyname" = x"no"; then +	AC_CHECK_LIB_EXT(nsl_s, NSL_LIBS, gethostbyname) +	AC_CHECK_LIB_EXT(nsl, NSL_LIBS, gethostbyname) +	AC_CHECK_LIB_EXT(socket, NSL_LIBS, gethostbyname) +	dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here, +	dnl because the value has been cached. +	if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" || +		test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" || +		test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes" +	then +		AC_DEFINE(HAVE_GETHOSTBYNAME,1, +			  [Whether the system has gethostbyname()]) +	fi +fi + diff --git a/source3/lib/replace/system/config.m4 b/source3/lib/replace/system/config.m4 index 1c05733126..66c2bd652a 100644 --- a/source3/lib/replace/system/config.m4 +++ b/source3/lib/replace/system/config.m4 @@ -18,7 +18,7 @@ AC_CHECK_HEADERS(sys/capability.h)  case "$host_os" in  *linux*) -AC_CACHE_CHECK([for broken RedHat 7.2 system header files],samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[ +AC_CACHE_CHECK([for broken RedHat 7.2 system header files],libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[  AC_TRY_COMPILE([  	#ifdef HAVE_SYS_VFS_H  	#include <sys/vfs.h> @@ -29,14 +29,14 @@ AC_TRY_COMPILE([  	],[  	int i;  	], -	samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no, -	samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes +	libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no, +	libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes  )]) -if test x"$samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then +if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then  	AC_DEFINE(BROKEN_REDHAT_7_SYSTEM_HEADERS,1,[Broken RedHat 7.2 system header files])  fi -AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[ +AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[  AC_TRY_COMPILE([  	#ifdef HAVE_SYS_CAPABILITY_H  	#include <sys/capability.h> @@ -45,10 +45,10 @@ AC_TRY_COMPILE([  	],[  	__s8 i;  	], -	samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no, -	samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes +	libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no, +	libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes  )]) -if test x"$samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then +if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then  	AC_DEFINE(BROKEN_RHEL5_SYS_CAP_HEADER,1,[Broken RHEL5 sys/capability.h])  fi  ;; diff --git a/source3/lib/replace/system/network.h b/source3/lib/replace/system/network.h index aff8a841da..796df2d1da 100644 --- a/source3/lib/replace/system/network.h +++ b/source3/lib/replace/system/network.h @@ -6,6 +6,7 @@     networking system include wrappers     Copyright (C) Andrew Tridgell 2004 +   Copyright (C) Jelmer Vernooij 2007       ** NOTE! The following LGPL license applies to the replace       ** library. This does NOT imply that all of Samba is released @@ -82,6 +83,11 @@  #include <stropts.h>  #endif +#ifndef HAVE_SOCKLEN_T +#define HAVE_SOCKLEN_T +typedef int socklen_t; +#endif +  #ifdef REPLACE_INET_NTOA  /* define is in "replace.h" */  char *rep_inet_ntoa(struct in_addr ip); @@ -97,6 +103,41 @@ int rep_inet_pton(int af, const char *src, void *dst);  const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);  #endif +#ifndef HAVE_CONNECT +/* define is in "replace.h" */ +int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); +#endif + +#ifndef HAVE_GETHOSTBYNAME +/* define is in "replace.h" */ +struct hostent *rep_gethostbyname(const char *name); +#endif + +#ifdef HAVE_IFADDRS_H +#include <ifaddrs.h> +#endif + +#ifndef HAVE_STRUCT_IFADDRS +struct ifaddrs { +	struct ifaddrs   *ifa_next;         /* Pointer to next struct */ +	char             *ifa_name;         /* Interface name */ +	unsigned int     ifa_flags;         /* Interface flags */ +	struct sockaddr  *ifa_addr;         /* Interface address */ +	struct sockaddr  *ifa_netmask;      /* Interface netmask */ +#undef ifa_dstaddr +	struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */ +	void             *ifa_data;         /* Address specific data */ +}; +#endif + +#ifndef HAVE_GETIFADDRS +int rep_getifaddrs(struct ifaddrs **); +#endif + +#ifndef HAVE_FREEIFADDRS +void rep_freeifaddrs(struct ifaddrs *); +#endif +  /*   * Some systems have getaddrinfo but not the   * defines needed to use it. @@ -219,11 +260,6 @@ const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);  #define HOST_NAME_MAX 256  #endif -#ifndef HAVE_SOCKLEN_T -#define HAVE_SOCKLEN_T -typedef int socklen_t; -#endif -  #ifndef HAVE_SA_FAMILY_T  #define HAVE_SA_FAMILY_T  typedef unsigned short int sa_family_t; @@ -269,7 +305,7 @@ struct addrinfo {  /* Needed for some systems that don't define it (Solaris). */  #ifndef ifr_netmask -#define ifr_netmask ifr_addrs +#define ifr_netmask ifr_addr  #endif  #ifdef SOCKET_WRAPPER diff --git a/source3/lib/replace/test/getifaddrs.c b/source3/lib/replace/test/getifaddrs.c new file mode 100644 index 0000000000..8b00ac2f40 --- /dev/null +++ b/source3/lib/replace/test/getifaddrs.c @@ -0,0 +1,100 @@ +/* + * 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); +#ifdef HAVE_STRUCT_SOCKADDR_IN6 +	} else if (addr->sa_family == AF_INET6) { +		result = rep_inet_ntop(AF_INET6, +				       &((struct sockaddr_in6 *)addr)->sin6_addr, +				       addrstring, +				       addrlen); +#endif +	} +	return result; +} + +int getifaddrs_test(void) +{ +	struct ifaddrs *ifs = NULL; +	struct ifaddrs *ifs_head = NULL; +	int ret; + +	ret = getifaddrs(&ifs); +	ifs_head = ifs; +	if (ret != 0) { +		fprintf(stderr, "getifaddrs() failed: %s\n", 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_head); + +	return 0; +} diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 5b95ae395c..b538360365 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -856,6 +856,22 @@ static int test_strptime(void)  	return libreplace_test_strptime();  } +extern int getifaddrs_test(void); + +static int test_getifaddrs(void) +{ + +	printf("test: getifaddrs\n"); + +	if (getifaddrs_test() != 0) { +		printf("failure: getifaddrs\n"); +		return false; +	} + +	printf("success: getifaddrs\n"); +	return true; +} +  struct torture_context;  bool torture_local_replace(struct torture_context *ctx)  { @@ -903,6 +919,7 @@ bool torture_local_replace(struct torture_context *ctx)  	ret &= test_MAX();  	ret &= test_socketpair();  	ret &= test_strptime(); +	ret &= test_getifaddrs();  	return ret;  } | 
