From fa4bfbc45c934a9431f40588c519085eff9e8ae6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 20 Sep 2002 22:23:13 +0000 Subject: [PATCH] Improve check for type of socket length (socklen_t). --- comstack/tcpip.c | 16 +++++----------- comstack/unix.c | 14 ++++---------- configure.in | 50 ++++++++++++++++---------------------------------- 3 files changed, 25 insertions(+), 55 deletions(-) diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 2d56db1..a7d33d2 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.48 2002-09-10 20:56:34 adam Exp $ + * $Id: tcpip.c,v 1.49 2002-09-20 22:23:13 adam Exp $ */ #include @@ -53,14 +53,8 @@ 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 +#ifndef YAZ_SOCKLEN_T +#define YAZ_SOCKLEN_T int #endif /* this state is used for both SSL and straight TCP/IP */ @@ -459,7 +453,7 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_in addr; - NET_LEN_T len = sizeof(addr); + YAZ_SOCKLEN_T len = sizeof(addr); TRC(fprintf(stderr, "tcpip_listen pid=%d\n", getpid())); if (h->state != CS_ST_IDLE) @@ -974,7 +968,7 @@ char *tcpip_addrstr(COMSTACK h) struct sockaddr_in addr; tcpip_state *sp = (struct tcpip_state *)h->cprivate; char *r, *buf = sp->buf; - NET_LEN_T len; + YAZ_SOCKLEN_T len; struct hostent *host; len = sizeof(addr); diff --git a/comstack/unix.c b/comstack/unix.c index edfa830..0cccf5f 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.5 2002-09-10 20:56:34 adam Exp $ + * $Id: unix.c,v 1.6 2002-09-20 22:23:13 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -26,14 +26,8 @@ /* 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 +#ifndef YAZ_SOCKLEN_T +#define YAZ_SOCKLEN_T int #endif int unix_close(COMSTACK h); @@ -315,7 +309,7 @@ int unix_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_un addr; - NET_LEN_T len = SUN_LEN(&addr); + YAZ_SOCKLEN_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 f849147..55076ad 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.90 2002-09-18 20:55:54 adam Exp $ +dnl $Id: configure.in,v 1.91 2002-09-20 22:23:13 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.9.1) dnl @@ -179,40 +179,22 @@ if test "$ac_cv_func_poll" = "yes"; then AC_CHECK_HEADERS(sys/poll.h) fi dnl ------ socklen_t -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) -else - 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_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 -], - [size_t mylen; getpeername(0, (struct sockaddr *)NULL, &mylen);], - 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 -fi + #include + #include + extern accept(int, struct sockaddr *, socklen_t *); + ],,[ac_cv_check_socklen_t=socklen_t],[ + AC_TRY_COMPILE([ + #include + #include + extern accept(int, struct sockaddr *, size_t t *); + ],,[ac_cv_check_socklen_t=size_t],[ac_cv_check_socklen_t=int]) + ]) +]) +AC_MSG_RESULT($ac_cv_check_socklen_t) +AC_DEFINE_UNQUOTED(YAZ_SOCKLEN_T,$ac_cv_check_socklen_t) dnl dnl ------ tcpd AC_ARG_ENABLE(tcpd,[ --enable-tcpd[=PREFIX] enable TCP wrapper for server if available]) -- 1.7.10.4