From ca4948d9b8ea1e4d73d25a25b1da3a4de121ca73 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Sep 2002 20:56:34 +0000 Subject: [PATCH] Check for socklen_t type for accept, getpeername --- comstack/tcpip.c | 20 +++++++++++++------- comstack/unix.c | 18 ++++++++++++------ configure.in | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/comstack/tcpip.c b/comstack/tcpip.c index cb24279..2d56db1 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.47 2002-06-12 19:42:38 adam Exp $ + * $Id: tcpip.c,v 1.48 2002-09-10 20:56:34 adam Exp $ */ #include @@ -53,6 +53,16 @@ void *tcpip_straddr(COMSTACK h, const char *str); #define TRC(X) #endif +#if HAVE_SOCKLEN_T +#define NET_LEN_T socklen_t +#else +#if GETPEERNAME_ACCEPTS_SIZE_T_FOR_THIRD_ARGUMENT +#define NET_LEN_T size_t +#else +#define NET_LEN_T int +#endif +#endif + /* this state is used for both SSL and straight TCP/IP */ typedef struct tcpip_state { @@ -449,11 +459,7 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_in addr; -#ifdef __cplusplus - socklen_t len = sizeof(addr); -#else - int len = sizeof(addr); -#endif + NET_LEN_T len = sizeof(addr); TRC(fprintf(stderr, "tcpip_listen pid=%d\n", getpid())); if (h->state != CS_ST_IDLE) @@ -968,7 +974,7 @@ char *tcpip_addrstr(COMSTACK h) struct sockaddr_in addr; tcpip_state *sp = (struct tcpip_state *)h->cprivate; char *r, *buf = sp->buf; - size_t len; + NET_LEN_T len; struct hostent *host; len = sizeof(addr); diff --git a/comstack/unix.c b/comstack/unix.c index 222817e..edfa830 100644 --- a/comstack/unix.c +++ b/comstack/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.4 2002-07-22 23:16:10 adam Exp $ + * $Id: unix.c,v 1.5 2002-09-10 20:56:34 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -26,6 +26,16 @@ /* Chas added the following, so we get the definition of completeBER */ #include +#if HAVE_SOCKLEN_T +#define NET_LEN_T socklen_t +#else +#if GETPEERNAME_ACCEPTS_SIZE_T_FOR_THIRD_ARGUMENT +#define NET_LEN_T size_t +#else +#define NET_LEN_T int +#endif +#endif + int unix_close(COMSTACK h); int unix_put(COMSTACK h, char *buf, int size); int unix_get(COMSTACK h, char **buf, int *bufsize); @@ -305,11 +315,7 @@ int unix_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_un addr; -#ifdef __cplusplus - socklen_t len = SUN_LEN(&addr); -#else - int len = SUN_LEN(&addr); -#endif + NET_LEN_T len = SUN_LEN(&addr); TRC(fprintf(stderr, "unix_listen pid=%d\n", getpid())); if (h->state != CS_ST_IDLE) diff --git a/configure.in b/configure.in index bed7c5b..cabeb56 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2002 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.84 2002-09-10 18:43:02 adam Exp $ +dnl $Id: configure.in,v 1.85 2002-09-10 20:56:34 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.9.1) dnl @@ -145,6 +145,39 @@ AC_CHECK_FUNCS(vsnprintf gettimeofday poll) if test "$ac_cv_func_poll" = "yes"; then AC_CHECK_HEADERS(sys/poll.h) fi +dnl AC_CHECK_TYPES(socklen_t) +AC_MSG_CHECKING(for socklen_t) +AC_CACHE_VAL(ac_cv_check_socklen_t, +[ac_cv_check_socklen_t='' +AC_TRY_COMPILE([ +#include +#include +#include +#include +], + [socklen_t len;], + ac_cv_check_socklen_t=yes, + ac_cv_check_socklen_t=no)]) +AC_MSG_RESULT($ac_cv_check_socklen_t) +if test "$ac_cv_check_socklen_t" = "yes"; then + AC_DEFINE(HAVE_SOCKLEN_T) +fi +AC_MSG_CHECKING(whether net size is of type size_t) +AC_CACHE_VAL(ac_cv_check_getpeername_accepts_size_t, +[ac_cv_check_getpeername_accepts_size_t='' +AC_TRY_COMPILE([ +#include +#include +#include +#include +], + [getpeername(0, (struct sockaddr *)NULL, (size_t *)0);], + ac_cv_check_getpeername_accepts_size_t=yes, + ac_cv_check_getpeername_accepts_size_t=no)]) +AC_MSG_RESULT($ac_cv_check_getpeername_accepts_size_t) +if test "$ac_cv_check_getpeername_accepts_size_t" = yes; then + AC_DEFINE(GETPEERNAME_ACCEPTS_SIZE_T_FOR_THIRD_ARGUMENT) +fi dnl dnl ------ tcpd AC_ARG_ENABLE(tcpd,[ --enable-tcpd[=PREFIX] enable TCP wrapper for server if available]) -- 1.7.10.4