From d4397af4d8115315ca37ddb6890bff07e31af271 Mon Sep 17 00:00:00 2001 From: agc Date: Mon, 6 Mar 2006 20:52:32 +0000 Subject: [PATCH] One more off the TODO list, although I hadn't realised it was going to be as painful as it was. Teach GNU autoconf to recognise socklen_t, and use it in the code. --- dist/iscsi/include/config.h | 3 ++ dist/iscsi/include/config.h.in | 3 ++ dist/iscsi/include/util.h | 4 ++ dist/iscsi/src/TODO | 2 +- dist/iscsi/src/configure | 81 ++++++++++++++++++++++++++++++++++ dist/iscsi/src/configure.ac | 7 +++ dist/iscsi/src/target.c | 16 +++---- dist/iscsi/src/util.c | 3 +- 8 files changed, 108 insertions(+), 11 deletions(-) diff --git a/dist/iscsi/include/config.h b/dist/iscsi/include/config.h index 821b2c437175..877a803d35ff 100644 --- a/dist/iscsi/include/config.h +++ b/dist/iscsi/include/config.h @@ -64,6 +64,9 @@ /* Define to 1 if you have the `snprintf' function. */ #define HAVE_SNPRINTF 1 +/* Define to 1 if the system has the type `socklen_t'. */ +#define HAVE_SOCKLEN_T 1 + /* Define to 1 if you have the header file. */ #define HAVE_STDARG_H 1 diff --git a/dist/iscsi/include/config.h.in b/dist/iscsi/include/config.h.in index ef6151597783..f9b91d8b957b 100644 --- a/dist/iscsi/include/config.h.in +++ b/dist/iscsi/include/config.h.in @@ -63,6 +63,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 header file. */ #undef HAVE_STDARG_H diff --git a/dist/iscsi/include/util.h b/dist/iscsi/include/util.h index a826a86e900e..e156288540f6 100644 --- a/dist/iscsi/include/util.h +++ b/dist/iscsi/include/util.h @@ -250,6 +250,10 @@ void set_debug(const char *); #define ISCSI_GETPID getpid() #endif +#ifndef HAVE_SOCKLEN_T +typedef int socklen_t; +#endif + /* * Sleeping */ diff --git a/dist/iscsi/src/TODO b/dist/iscsi/src/TODO index 81d4f2ec6d9e..33d9ebea030d 100644 --- a/dist/iscsi/src/TODO +++ b/dist/iscsi/src/TODO @@ -1,6 +1,5 @@ To do ===== -add socklen_t awareness cmdline fs or fsmmap add ability to add a target in, take one out (if !busy) @@ -31,3 +30,4 @@ get port from cmd line raid0 add discovery masking clean up IPv6 +add socklen_t awareness diff --git a/dist/iscsi/src/configure b/dist/iscsi/src/configure index 4e6c33234210..c306cf4e0cb0 100755 --- a/dist/iscsi/src/configure +++ b/dist/iscsi/src/configure @@ -3703,6 +3703,75 @@ cat >>confdefs.h <<_ACEOF #define size_t unsigned _ACEOF +fi + +echo "$as_me:$LINENO: checking for socklen_t" >&5 +echo $ECHO_N "checking for socklen_t... $ECHO_C" >&6 +if test "${ac_cv_type_socklen_t+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. */ + +#include +#include + + +int +main () +{ +if ((socklen_t *) 0) + return 0; +if (sizeof (socklen_t)) + 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_type_socklen_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_socklen_t=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_socklen_t" >&5 +echo "${ECHO_T}$ac_cv_type_socklen_t" >&6 +if test $ac_cv_type_socklen_t = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKLEN_T 1 +_ACEOF + + fi echo "$as_me:$LINENO: checking for long long" >&5 @@ -3834,6 +3903,18 @@ _ACEOF fi +cat >>confdefs.h <<_ACEOF +#define HAVE_SOCKLEN_T $ac_cv_type_socklen_t +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define HAVE_LONG_LONG $ac_cv_type_long_long +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define HAVE_UNSIGNED_LONG_LONG $ac_cv_type_unsigned_long_long +_ACEOF + diff --git a/dist/iscsi/src/configure.ac b/dist/iscsi/src/configure.ac index 82c809d6e183..06158e8005f5 100644 --- a/dist/iscsi/src/configure.ac +++ b/dist/iscsi/src/configure.ac @@ -19,7 +19,14 @@ AC_CHECK_HEADERS(ctype.h errno.h fcntl.h pthread.h pwd.h signal.h stdlib.h syslo dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T +AC_CHECK_TYPES(socklen_t,,,[ +#include +#include +]) AC_CHECK_TYPES([long long, unsigned long long]) +AC_DEFINE_UNQUOTED(HAVE_SOCKLEN_T, $ac_cv_type_socklen_t) +AC_DEFINE_UNQUOTED(HAVE_LONG_LONG, $ac_cv_type_long_long) +AC_DEFINE_UNQUOTED(HAVE_UNSIGNED_LONG_LONG, $ac_cv_type_unsigned_long_long) dnl Check for functionality AC_CHECK_FUNCS(asprintf asnprintf bswap64 snprintf strlcpy strtoll daemon vasprintf vasnprintf vsnprintf) diff --git a/dist/iscsi/src/target.c b/dist/iscsi/src/target.c index 0d426f40c4fb..0532d94a3395 100644 --- a/dist/iscsi/src/target.c +++ b/dist/iscsi/src/target.c @@ -1526,14 +1526,14 @@ target_shutdown(globals_t *gp) int target_listen(globals_t *gp) { - target_session_t *sess; - int one = 1; - int localAddrLen; - struct sockaddr_in localAddrStorage; - int remoteAddrLen; - struct sockaddr_in remoteAddrStorage; - char local[1024]; - char remote[1024]; + struct sockaddr_in remoteAddrStorage; + struct sockaddr_in localAddrStorage; + target_session_t *sess; + socklen_t remoteAddrLen; + socklen_t localAddrLen; + char remote[1024]; + char local[1024]; + int one = 1; ISCSI_THREAD_START("listen_thread"); gp->listener_pid = ISCSI_GETPID; diff --git a/dist/iscsi/src/util.c b/dist/iscsi/src/util.c index e5f7865ada9a..c574baeb7dcf 100644 --- a/dist/iscsi/src/util.c +++ b/dist/iscsi/src/util.c @@ -474,8 +474,7 @@ int iscsi_sock_accept(iscsi_socket_t sock, iscsi_socket_t * newsock) { struct sockaddr_in remoteAddr; - int remoteAddrLen; - /* XXX - socklen_t */ + socklen_t remoteAddrLen; remoteAddrLen = sizeof(remoteAddr); (void) memset(&remoteAddr, 0, sizeof(remoteAddr));