[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-test-2659-g77b7d7c

Michael Adam obnox at samba.org
Fri Feb 29 08:36:26 GMT 2008


The branch, v3-2-test has been updated
       via  77b7d7c0417e498340d1c9364fbbb8671c175477 (commit)
       via  1ff0b616a9cb029040031f797b52112d4973e1eb (commit)
       via  34d906ef44d1a5c3452097a9cac438d721fe35c1 (commit)
       via  0906120a6e4fe0eb66f3c3fd99c625b30672cb2b (commit)
       via  3c1843f931b896dd3bb142346ecb44c0fb9202d6 (commit)
       via  1d906d346ed90b87895772a64c7613324ef8b682 (commit)
       via  650cc1da4b4404880389c583dbb07ce86df48576 (commit)
       via  c5932414fdf0b568cbfe6cdefaec41c8afc8ca6b (commit)
       via  52d79ad4872a20cf55f31aba97629c2561bfc16c (commit)
      from  405ef74d7e9ef614ea39b7cfd1d57307d9490545 (commit)

http://gitweb.samba.org/?samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 77b7d7c0417e498340d1c9364fbbb8671c175477
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 02:46:14 2008 +0100

    libreplace: add snprintf.c to test code for getifaddrs - needed on some systems.
    
    Michael
    (cherry picked from commit 0aff54a12e20d5e91fcdec7aaec103fb9a371a23)

commit 1ff0b616a9cb029040031f797b52112d4973e1eb
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 02:43:24 2008 +0100

    libreplace: ifdef out ip6 code if unsupported.
    
    Michael
    (cherry picked from commit 54cc0df4dbf6d63a9b94e1ac6af4ec7f7803bc30)

commit 34d906ef44d1a5c3452097a9cac438d721fe35c1
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 02:23:29 2008 +0100

    libreplace: fix rep_freeifaddrs to not segfault on NULL input.
    
    Michael
    (cherry picked from commit 0cbb87453beb52c6b0bc3a48791f49678f4030c5)

commit 0906120a6e4fe0eb66f3c3fd99c625b30672cb2b
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 02:22:02 2008 +0100

    libreplace: fix silly crashbug in getifaddrs_test().
    
    Michael
    (cherry picked from commit 523626908d25f974fd1ae6d7306b1d4bc8414162)

commit 3c1843f931b896dd3bb142346ecb44c0fb9202d6
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 01:49:30 2008 +0100

    libreplace: add missing newline in output of getifaddrs test.
    
    Michael
    (cherry picked from commit f8243cfc47c7414bab7f249d0e5d1c85e8ca7d64)

commit 1d906d346ed90b87895772a64c7613324ef8b682
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 01:25:54 2008 +0100

    libreplace: add missing semicolon to getifaddrs.
    
    Michael
    (cherry picked from commit 29818a07de826fd687003ff25865d77939ecaa9a)

commit 650cc1da4b4404880389c583dbb07ce86df48576
Author: Michael Adam <obnox at samba.org>
Date:   Fri Feb 29 00:06:55 2008 +0100

    libreplace: try and fix rep_getifaddrs() for Tru64.
    
    Don't fail when there is no address assigned to the interface.
    Put NULL into the ifaddrs structure instead.
    
    Michael
    (cherry picked from commit ee170c85e0e76411bd752de5fe51db6940dab929)

commit c5932414fdf0b568cbfe6cdefaec41c8afc8ca6b
Author: Michael Adam <obnox at samba.org>
Date:   Thu Feb 28 21:44:31 2008 +0100

    libreplace: use the new getifaddrs test also for autoconf.
    
    Michael
    (cherry picked from commit a2a506ff0eae2a64ebe2ddbb81a6c2a5fa7fe3da)

commit 52d79ad4872a20cf55f31aba97629c2561bfc16c
Author: Michael Adam <obnox at samba.org>
Date:   Thu Feb 28 21:43:06 2008 +0100

    libreplace: add extended getifaddrs test that prints out the interfaces.
    
    Michael
    
    cherry-picked from libreplace-part of 9d2bab09aac22c00fe23f1e1265a2dbd0901e9ce
    and adapted replacetort creation

-----------------------------------------------------------------------

Summary of changes:
 source/lib/replace/Makefile.in       |    2 +-
 source/lib/replace/getifaddrs.c      |   79 ++++++++-------------------
 source/lib/replace/getifaddrs.m4     |   24 +++++++--
 source/lib/replace/test/getifaddrs.c |  100 ++++++++++++++++++++++++++++++++++
 source/lib/replace/test/testsuite.c  |    9 +--
 5 files changed, 147 insertions(+), 67 deletions(-)
 create mode 100644 source/lib/replace/test/getifaddrs.c


Changeset truncated at 500 lines:

diff --git a/source/lib/replace/Makefile.in b/source/lib/replace/Makefile.in
index af9522f..c989835 100644
--- a/source/lib/replace/Makefile.in
+++ b/source/lib/replace/Makefile.in
@@ -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)
diff --git a/source/lib/replace/getifaddrs.c b/source/lib/replace/getifaddrs.c
index 0536574..f6f0ec0 100644
--- a/source/lib/replace/getifaddrs.c
+++ b/source/lib/replace/getifaddrs.c
@@ -44,13 +44,14 @@
 
 void rep_freeifaddrs(struct ifaddrs *ifp)
 {
-	free(ifp->ifa_name);
-	free(ifp->ifa_addr);
-	free(ifp->ifa_netmask);
-	free(ifp->ifa_dstaddr);
-	if (ifp->ifa_next != NULL)
+	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);
+		free(ifp);
+	}
 }
 
 static struct sockaddr *sockaddr_dup(struct sockaddr *sa)
@@ -109,38 +110,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));
-		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_flags = ifr[i].ifr_flags;
 		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_addr = NULL;
+		if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) {
+			curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
+		}
 
-		curif->ifa_netmask = 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;
 	}
 
@@ -363,32 +359,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
diff --git a/source/lib/replace/getifaddrs.m4 b/source/lib/replace/getifaddrs.m4
index 767797e..6cca155 100644
--- a/source/lib/replace/getifaddrs.m4
+++ b/source/lib/replace/getifaddrs.m4
@@ -49,7 +49,11 @@ 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/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])
@@ -67,7 +71,11 @@ 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/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])
@@ -84,7 +92,11 @@ 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/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])
@@ -100,7 +112,11 @@ 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/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])
diff --git a/source/lib/replace/test/getifaddrs.c b/source/lib/replace/test/getifaddrs.c
new file mode 100644
index 0000000..8b00ac2
--- /dev/null
+++ b/source/lib/replace/test/getifaddrs.c
@@ -0,0 +1,100 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * libreplace getifaddrs test
+ *
+ * Copyright (C) Michael Adam <obnox at 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/source/lib/replace/test/testsuite.c b/source/lib/replace/test/testsuite.c
index c9f3301..b538360 100644
--- a/source/lib/replace/test/testsuite.c
+++ b/source/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;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list