From 41dadaedb7f1ea5620366be99c15be61689f6370 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 7 Aug 2009 00:11:57 +0000 Subject: [PATCH] Use socklen_t as the type in arguments to getsockname and getsockopt to avoid a "pointer targets differ in signedness" warning. Add a check for socklen_t in configure.in; if it's not present, typedef it to int. --- libdnet-stripped/NMAP_MODIFICATIONS | 4 + libdnet-stripped/acconfig.h | 4 + libdnet-stripped/configure | 105 +++++++++++++++++++++++++++ libdnet-stripped/configure.in | 1 + libdnet-stripped/include/config.h.in | 7 ++ libdnet-stripped/src/intf.c | 2 +- libdnet-stripped/src/ip.c | 3 +- 7 files changed, 124 insertions(+), 2 deletions(-) diff --git a/libdnet-stripped/NMAP_MODIFICATIONS b/libdnet-stripped/NMAP_MODIFICATIONS index f44555632..cf16c74d9 100644 --- a/libdnet-stripped/NMAP_MODIFICATIONS +++ b/libdnet-stripped/NMAP_MODIFICATIONS @@ -31,6 +31,10 @@ o Added libdnet-stripped.vcproj -- A Visual Studio.Net project file o Regenerated build files with Autoconf 2.63, Automake 1.10.1, and libtool 2.2.6. +o Added a check for socklen_t in configure.in and used socklen_t when + calling getsockname and getsockopt to avoid a "pointer targets differ + in signedness" warning on platforms where socklen_t is unsigned. + o Made some code changes to intf.c (the patch below). This does the following: o Preserve the alias qualifier from interface name in more cases diff --git a/libdnet-stripped/acconfig.h b/libdnet-stripped/acconfig.h index c4b61230d..cf76546d8 100644 --- a/libdnet-stripped/acconfig.h +++ b/libdnet-stripped/acconfig.h @@ -30,3 +30,7 @@ int strlcpy(char *, const char *, int); #ifndef HAVE_STRSEP char *strsep(char **, const char *); #endif + +#ifndef HAVE_SOCKLEN_T +typedef socklen_t int +#endif diff --git a/libdnet-stripped/configure b/libdnet-stripped/configure index 91feb5e76..9b784f4e2 100755 --- a/libdnet-stripped/configure +++ b/libdnet-stripped/configure @@ -14021,6 +14021,111 @@ fi if test "$GCC" = yes ; then CFLAGS="$CFLAGS -Wall" fi +{ $as_echo "$as_me:$LINENO: checking for socklen_t" >&5 +$as_echo_n "checking for socklen_t... " >&6; } +if test "${ac_cv_type_socklen_t+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_cv_type_socklen_t=no +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +int +main () +{ +if (sizeof (socklen_t)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +int +main () +{ +if (sizeof ((socklen_t))) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + : +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_socklen_t=yes +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_socklen_t" >&5 +$as_echo "$ac_cv_type_socklen_t" >&6; } +if test "x$ac_cv_type_socklen_t" = x""yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKLEN_T 1 +_ACEOF + + +fi + { $as_echo "$as_me:$LINENO: checking for working memcmp" >&5 $as_echo_n "checking for working memcmp... " >&6; } diff --git a/libdnet-stripped/configure.in b/libdnet-stripped/configure.in index 90d1f63f3..403623add 100644 --- a/libdnet-stripped/configure.in +++ b/libdnet-stripped/configure.in @@ -194,6 +194,7 @@ AC_PROG_GCC_TRADITIONAL if test "$GCC" = yes ; then CFLAGS="$CFLAGS -Wall" fi +AC_CHECK_TYPES([socklen_t], [], [], [#include ]) dnl Checks for library functions. AC_FUNC_MEMCMP diff --git a/libdnet-stripped/include/config.h.in b/libdnet-stripped/include/config.h.in index 72e280c0c..7d5cbbaf6 100644 --- a/libdnet-stripped/include/config.h.in +++ b/libdnet-stripped/include/config.h.in @@ -142,6 +142,9 @@ /* Define if sockaddr struct has sa_len. */ #undef HAVE_SOCKADDR_SA_LEN +/* Define to 1 if the system has the type `socklen_t'. */ +#undef HAVE_SOCKLEN_T + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H @@ -296,3 +299,7 @@ int strlcpy(char *, const char *, int); #ifndef HAVE_STRSEP char *strsep(char **, const char *); #endif + +#ifndef HAVE_SOCKLEN_T +typedef socklen_t int +#endif diff --git a/libdnet-stripped/src/intf.c b/libdnet-stripped/src/intf.c index ebb3d92cd..57b14eed3 100644 --- a/libdnet-stripped/src/intf.c +++ b/libdnet-stripped/src/intf.c @@ -634,7 +634,7 @@ int intf_get_dst(intf_t *intf, struct intf_entry *entry, struct addr *dst) { struct sockaddr_in sin; - int n; + socklen_t n; if (dst->addr_type != ADDR_TYPE_IP) { errno = EINVAL; diff --git a/libdnet-stripped/src/ip.c b/libdnet-stripped/src/ip.c index d377d4003..6b513ce5b 100644 --- a/libdnet-stripped/src/ip.c +++ b/libdnet-stripped/src/ip.c @@ -26,7 +26,8 @@ ip_t * ip_open(void) { ip_t *i; - int n, len; + int n; + socklen_t len; if ((i = calloc(1, sizeof(*i))) == NULL) return (NULL);