From: Ruediger Meier <ruediger.me...@ga-group.nl> This patch is needed because currently we fail always where both ws2tcpip.h and socklen_t is needed.
Note this patch may discover missing includes on systems where socklen_t is available but the right headers are not included yet. For example on win32 we need #ifdef HAVE_WS2TCPIP_H # include <ws2tcpip.h> #endif Further patches should fix this. Here we do that for sanei/sanei_udp.c only because this seems to be the only affected unit which would compile on win32 anyway. Signed-off-by: Ruediger Meier <ruediger.meier at ga-group.nl> --- ChangeLog | 4 ++++ acinclude.m4 | 3 +++ configure | 46 +++++++++++++++++++++------------------------- configure.in | 19 ++++++++++++------- include/sane/config.h.in | 12 +++++++++--- sanei/sanei_udp.c | 4 ++++ 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2983e24..d169da8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-01-25 Ruediger Meier <sweet_f_a at gmx.de> + * acinclude.m4, configure.in, sanei/sanei_udp.c: + checking for socklen_t more safe + 2012-01-23 Rolf Bensch <rolf at bensch hyphen online dot de> * backend/pixma_mp150, doc/descriptions/pixma.desc, doc/sane-pixma.man: New scanner PIXMA MX880 Series. diff --git a/acinclude.m4 b/acinclude.m4 index d91c733..904a226 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -669,6 +669,9 @@ AH_BOTTOM([ #define _BSDTYPES_DEFINED #endif +#ifndef HAVE_SOCKLEN_T +#define socklen_t int +#endif #ifndef HAVE_U_CHAR #define u_char unsigned char #endif diff --git a/configure b/configure index ba864b0..10c3361 100755 --- a/configure +++ b/configure @@ -8059,12 +8059,13 @@ done fi -for ac_header in winsock2.h +for ac_header in winsock2.h ws2tcpip.h do : - ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default" -if test "x$ac_cv_header_winsock2_h" = xyes; then : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_WINSOCK2_H 1 +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF SOCKET_LIB="-lws2_32" fi @@ -8257,31 +8258,26 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_long_long" >&5 $as_echo "$have_long_long" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for socklen_t in <sys/socket.h>" >&5 -$as_echo_n "checking for socklen_t in <sys/socket.h>... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#include <sys/socket.h> +ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "$ac_includes_default +#ifdef HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif +#ifdef HAVE_WINSOCK2_H +# include <winsock2.h> +#endif +#ifdef HAVE_WS2TCPIP_H +# include <ws2tcpip.h> +#endif +" +if test "x$ac_cv_type_socklen_t" = xyes; then : -int -main () -{ -socklen_t len - ; - return 0; -} +cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKLEN_T 1 _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; }; -$as_echo "#define socklen_t int" >>confdefs.h + fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for union semun in <sys/sem.h>" >&5 $as_echo_n "checking for union semun in <sys/sem.h>... " >&6; } diff --git a/configure.in b/configure.in index 6fac904..3b7d42b 100644 --- a/configure.in +++ b/configure.in @@ -204,7 +204,7 @@ AC_CHECK_HEADERS([asm/io.h],,,[#include <sys/types.h>]) SANE_CHECK_MISSING_HEADERS -AC_CHECK_HEADERS(winsock2.h, SOCKET_LIB="-lws2_32") +AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], SOCKET_LIB="-lws2_32") AC_CHECK_HEADER(resmgr.h,[ AC_CHECK_LIB( @@ -232,12 +232,17 @@ have_long_long=no AC_TRY_COMPILE([], [long long x; x = (long long)0;], AC_DEFINE(HAVE_LONG_LONG, 1, [Define if the long long type is available.]) have_long_long=yes) AC_MSG_RESULT($have_long_long) -AC_MSG_CHECKING([for socklen_t in <sys/socket.h>]) -AC_TRY_COMPILE([ -#include <sys/socket.h> -],[socklen_t len],AC_MSG_RESULT(yes), -[AC_MSG_RESULT(no); AC_DEFINE(socklen_t,int, -[Define socklen_t as \'int\' if necessary.])]) +AC_CHECK_TYPES([socklen_t], [], [], +[[$ac_includes_default +#ifdef HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif +#ifdef HAVE_WINSOCK2_H +# include <winsock2.h> +#endif +#ifdef HAVE_WS2TCPIP_H +# include <ws2tcpip.h> +#endif]]) AC_MSG_CHECKING([for union semun in <sys/sem.h>]) AC_TRY_COMPILE([ diff --git a/include/sane/config.h.in b/include/sane/config.h.in index 00c8669..ec4332b 100644 --- a/include/sane/config.h.in +++ b/include/sane/config.h.in @@ -282,6 +282,9 @@ /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF +/* Define to 1 if the system has the type `socklen_t'. */ +#undef HAVE_SOCKLEN_T + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -441,6 +444,9 @@ /* Define to 1 if you have the <winsock2.h> header file. */ #undef HAVE_WINSOCK2_H +/* Define to 1 if you have the <ws2tcpip.h> header file. */ +#undef HAVE_WS2TCPIP_H + /* Define to 1 if you have the `_portaccess' function. */ #undef HAVE__PORTACCESS @@ -584,9 +590,6 @@ /* Define to `unsigned int' if <sys/types.h> does not define. */ #undef size_t -/* Define socklen_t as \'int\' if necessary. */ -#undef socklen_t - /* Define to `long' if <sys/types.h> does not define. */ #undef ssize_t @@ -602,6 +605,9 @@ #define _BSDTYPES_DEFINED #endif +#ifndef HAVE_SOCKLEN_T +#define socklen_t int +#endif #ifndef HAVE_U_CHAR #define u_char unsigned char #endif diff --git a/sanei/sanei_udp.c b/sanei/sanei_udp.c index ab316ea..3779ab2 100644 --- a/sanei/sanei_udp.c +++ b/sanei/sanei_udp.c @@ -50,6 +50,9 @@ #ifdef HAVE_WINSOCK2_H #include <winsock2.h> #endif +#ifdef HAVE_WS2TCPIP_H +#include <ws2tcpip.h> +#endif #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #include <netinet/in.h> @@ -63,6 +66,7 @@ #include "../include/sane/sanei_debug.h" #include "../include/sane/sanei_udp.h" + static SANE_Status sanei_udp_socket(int *fdp, int broadcast) { -- 1.7.6.1