[kaffe] CVS kaffe (guilhem): Ifaddrs replacement fixes for BSD systems.

Kaffe CVS cvs-commits at kaffe.org
Sun Dec 18 03:17:05 PST 2005


PatchSet 7009 
Date: 2005/12/18 11:09:12
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Ifaddrs replacement fixes for BSD systems.

2005-12-18  Guilhem Lavaux  <guilhem at kaffe.org>

        * configure.ac: Check whether struct sockaddr has a sa_len member.

        * replace/ifaddrs_bsd.c: Fixed the parsing of the ifreq array.

        * configure, config/config.h.in: Regenerated.

Members: 
	ChangeLog:1.4529->1.4530 
	configure:1.514->1.515 
	configure.ac:1.193->1.194 
	config/config.h.in:1.157->1.158 
	replace/ifaddrs_bsd.c:1.3->1.4 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4529 kaffe/ChangeLog:1.4530
--- kaffe/ChangeLog:1.4529	Sun Dec 18 10:39:48 2005
+++ kaffe/ChangeLog	Sun Dec 18 11:09:12 2005
@@ -1,4 +1,12 @@
-2005-12-17  Guilhem Lavaux  <guilhem at kaffe.org>
+2005-12-18  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* configure.ac: Check whether struct sockaddr has a sa_len member.
+
+	* replace/ifaddrs_bsd.c: Fixed the parsing of the ifreq array.
+
+	* configure, config/config.h.in: Regenerated.
+	
+2005-12-18  Guilhem Lavaux  <guilhem at kaffe.org>
 
 	* kaffe/kaffevm/classPool.c
 	(classMappingSearch): If we are asking again the same class while
Index: kaffe/configure
diff -u kaffe/configure:1.514 kaffe/configure:1.515
--- kaffe/configure:1.514	Sun Dec 11 03:20:27 2005
+++ kaffe/configure	Sun Dec 18 11:09:14 2005
@@ -42971,6 +42971,132 @@
 _ACEOF
 
 fi
+echo "$as_me:$LINENO: checking for struct sockaddr.sa_len" >&5
+echo $ECHO_N "checking for struct sockaddr.sa_len... $ECHO_C" >&6
+if test "${ac_cv_member_struct_sockaddr_sa_len+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#if defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+#if defined(HAVE_SYS_SOCKET_H)
+#include <sys/socket.h>
+#endif
+
+
+int
+main ()
+{
+static struct sockaddr ac_aggr;
+if (ac_aggr.sa_len)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_member_struct_sockaddr_sa_len=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#if defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+#if defined(HAVE_SYS_SOCKET_H)
+#include <sys/socket.h>
+#endif
+
+
+int
+main ()
+{
+static struct sockaddr ac_aggr;
+if (sizeof ac_aggr.sa_len)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_member_struct_sockaddr_sa_len=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_member_struct_sockaddr_sa_len=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_member_struct_sockaddr_sa_len" >&5
+echo "${ECHO_T}$ac_cv_member_struct_sockaddr_sa_len" >&6
+if test $ac_cv_member_struct_sockaddr_sa_len = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SOCKADDR_SA_LEN 1
+_ACEOF
+
+
+fi
+
 
 echo "$as_me:$LINENO: checking for struct sockaddr_in6.sin6_flowinfo" >&5
 echo $ECHO_N "checking for struct sockaddr_in6.sin6_flowinfo... $ECHO_C" >&6
Index: kaffe/configure.ac
diff -u kaffe/configure.ac:1.193 kaffe/configure.ac:1.194
--- kaffe/configure.ac:1.193	Sun Dec 11 03:20:28 2005
+++ kaffe/configure.ac	Sun Dec 18 11:09:22 2005
@@ -1469,6 +1469,17 @@
 AC_DECL_IN6ADDR_ANY
 AC_DECL_IN6ADDR_LOOPBACK
 AC_TYPE_SA_FAMILY_T
+AC_CHECK_MEMBER([struct sockaddr.sa_len],
+		[AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
+		           [Defined if we have found sa_len in sockaddr])
+		],,[
+#if defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+#if defined(HAVE_SYS_SOCKET_H)
+#include <sys/socket.h>
+#endif
+])
 
 dnl some Linux IPv6 stacks don't have sin6_flowinfo and sin6_scope_id
 dnl in their struct sockaddr_in6
Index: kaffe/config/config.h.in
diff -u kaffe/config/config.h.in:1.157 kaffe/config/config.h.in:1.158
--- kaffe/config/config.h.in:1.157	Sun Dec 11 00:59:17 2005
+++ kaffe/config/config.h.in	Sun Dec 18 11:09:22 2005
@@ -515,6 +515,9 @@
 /* Define to 1 if you have the `snprintf' function. */
 #undef HAVE_SNPRINTF
 
+/* Defined if we have found sa_len in sockaddr */
+#undef HAVE_SOCKADDR_SA_LEN
+
 /* Define to 1 if you have the `socket' function. */
 #undef HAVE_SOCKET
 
Index: kaffe/replace/ifaddrs_bsd.c
diff -u kaffe/replace/ifaddrs_bsd.c:1.3 kaffe/replace/ifaddrs_bsd.c:1.4
--- kaffe/replace/ifaddrs_bsd.c:1.3	Fri Aug 19 18:40:47 2005
+++ kaffe/replace/ifaddrs_bsd.c	Sun Dec 18 11:09:23 2005
@@ -93,7 +93,17 @@
     }
   while (isFull);
 
-  numberOfIfaces = ifc.ifc_len / (sizeof(struct sockaddr) + sizeof(ifr->ifr_name));
+  for (ptr = buf, numberOfIfaces = 0; ptr < buf + ifc.ifc_len; numberOfIfaces++)
+  {
+    ifr = (struct ifreq *) ptr;
+#if defined(HAVE_SOCKADDR_SA_LEN) || defined(__FreeBSD__)
+    len = ifr->ifr_addr.sa_len;	/* length may be greater than sizeof(sockaddr). */
+#else
+    len = getSockAddrLen(&ifr->ifr_addr);
+#endif
+
+    ptr += sizeof(*ifr) - sizeof(struct sockaddr) + len;
+  }
   
   allIfaces = (struct ifaddrs *)malloc(numberOfIfaces * sizeof(struct ifaddrs));
 
@@ -103,22 +113,21 @@
     
     allIfaces[i].ifa_name = strdup(ifr->ifr_name);
 #if defined(HAVE_SOCKADDR_SA_LEN) || defined(__FreeBSD__)
-    if (ifr->ifr_addr.sa_len > len)
-      len = ifr->ifr_addr.sa_len;	/* length > 16 */
-    else
+    len = ifr->ifr_addr.sa_len;	/* length may be greater than sizeof(sockaddr). */
+#else
+    len = getSockAddrLen(&ifr->ifr_addr);
 #endif
-      len = getSockAddrLen(&ifr->ifr_addr);
 
     allIfaces[i].ifa_addr = (struct sockaddr *)malloc(len);
     allIfaces[i].ifa_next = &allIfaces[i+1];
     
     memcpy(allIfaces[i].ifa_addr, &ifr->ifr_addr, len);
     
-    ptr += sizeof(ifr->ifr_name) + len;
+    ptr += sizeof(*ifr) - sizeof(struct sockaddr) + len;
   }
   allIfaces[i-1].ifa_next = NULL;
   
-  free(ptr);
+  free(buf);
   close(sockfd);
 
   *ifap = allIfaces;




More information about the kaffe mailing list