socklen_t in accept() co
I've been looking at the socklen_t mess - systems define it but do not use it, use void*length instead of socklen_t*length, and so on. Just how messy is this - is there even any point in trying to cover enough possibilities that configure can fail if it doesn't find the correct type? The following code comes from examining just 4 systems - Linux, HP-UX, Solaris, OSF1. Googling around I found tests that check for more intger types as well: unsigned, long, unsigned long in addition to socklen_t, int and size_t. Which systems need these? Also, do systems use the same type (or at least a type of the same size) for getsockopt()'s and accept()'s last arg, or do I need a separate getsockopt() test? AC_CHECK_TYPE([socklen_t],,, [$ac_includes_default #ifdef HAVE_SYS_SOCKET_H #include sys/socket.h #endif]) dnl accept() sockaddr-length type. Notes: dnl - The system might define socklen_t without actually using it. dnl POSIX has moved from int to size_t to socklen_t, and at dnl least HP-UX now has switches to select which version to use. dnl - Look for the length type in the connect() prototype if we dnl encounter accept(..., void *length). Happens on Solaris, dnl even though their accept() manpage says socklen_t *length. dnl - If we do not find the type, but socklen_t, int and size_t dnl have the same size, we can likely use either if it compiles. dnl With a chaos like this, such a fallback seems prudent. dnl - Hopefully we do not need separate types for getsockopt(). AC_CACHE_CHECK([for accept() sockaddr-length type],ol_cv_type_lber_socklen_t,[ vtype=void sltype=socklen_t ; test $ac_cv_type_socklen_t = yes || sltype= step2=2 ; test $ac_cv_sizeof_int = $ac_cv_sizeof_long || step2= for step in 0 1 $step2 ; do test $step = 2 vtype= for lentype in $sltype int size_t ; do for addrtype in struct sockaddr $vtype ; do AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$ac_includes_default #ifdef HAVE_SYS_SOCKET_H #include sys/socket.h #endif #if $step == 0 extern int accept(int s, $addrtype *ap, $lentype *lp); #elif $step == 1 /* Solaris hack */ extern int accept(int s, $addrtype *ap, void *lp); extern int connect(int s, const $addrtype *ap, $lentype l); #else /* $step == 2: default if candidate types have the same size. */ enum { Check = sizeof($lentype)==sizeof(int) sizeof(int)==sizeof(size_t) }; struct { int d: Check ? 1 : -1; } dummy[Check ? 1 : -1]; /* error if !Check */ #endif /* $step */ ], [ static struct sockaddr *addrp; static $lentype len; accept(0, addrp, len); ])], [ol_cv_type_lber_socklen_t=$lentype; break 3]) done done done]) if test -z $ol_cv_type_lber_socklen_t ; then AC_MSG_FAILURE([accept() sockaddr-length type not found]) fi AC_DEFINE_UNQUOTED(LBER_SOCKLEN_T, $ol_cv_type_lber_socklen_t, [define to sockaddr-length type used by accept()]) -- Regards, Hallvard ___ Autoconf mailing list Autoconf@gnu.org http://lists.gnu.org/mailman/listinfo/autoconf
Re: AC_CHECK_TYPE for socklen_t
On Fri, Feb 10, 2006 at 03:34:47PM -0800, Claudio Fontana wrote: my goal is to portably check for socklen_t in configure.ac. What I do now is: AC_CHECK_TYPE([socklen_t],,[int], [ #ifdef HAVE_SYS_SOCKET_H #include sys/socket.h #endif ]) with prior header checks for sys/socket.h, and in the code I use socklen_t. Is this correct (and portable to most unices)? See m4/socklen.m4 from the gnulib project. -- albert chin ([EMAIL PROTECTED]) ___ Autoconf mailing list Autoconf@gnu.org http://lists.gnu.org/mailman/listinfo/autoconf
AC_CHECK_TYPE for socklen_t
Hello, my goal is to portably check for socklen_t in configure.ac. What I do now is: AC_CHECK_TYPE([socklen_t],,[int], [ #ifdef HAVE_SYS_SOCKET_H #include sys/socket.h #endif ]) with prior header checks for sys/socket.h, and in the code I use socklen_t. Is this correct (and portable to most unices)? Thanks CLaudio ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it ___ Autoconf mailing list Autoconf@gnu.org http://lists.gnu.org/mailman/listinfo/autoconf
socklen_t
Functions like accept are known to have THREE different prototypes: int accept (int, struct sockaddr *, socklen_t *); /* Linux, Unix98 */ int accept (int, struct sockaddr *, size_t *); /* Solaris 2.6 */ int accept (int, struct sockaddr *, int *); /* DEC OSF 4.0e */ I think autoconf should have a AC_TYPE_SOCKLEN_T with obvious semantics. I include this start: dnl check for socklen_t (in Unix98) AC_MSG_CHECKING(for socklen_t) AC_TRY_COMPILE([#include sys/socket.h socklen_t x; ],[],[AC_MSG_RESULT(yes)],[ AC_TRY_COMPILE([#include sys/socket.h int accept (int, struct sockaddr *, size_t *); ],[],[ AC_MSG_RESULT(size_t) AC_DEFINE(socklen_t,size_t)], [ AC_MSG_RESULT(int) AC_DEFINE(socklen_t,int)])]) ObLegal: I hereby place this message in the public domain.
Re: socklen_t
Martin Buchholz [EMAIL PROTECTED] writes: Functions like accept are known to have THREE different prototypes: int accept (int, struct sockaddr *, socklen_t *); /* Linux, Unix98 */ int accept (int, struct sockaddr *, size_t *); /* Solaris 2.6 */ int accept (int, struct sockaddr *, int *); /* DEC OSF 4.0e */ I think autoconf should have a AC_TYPE_SOCKLEN_T with obvious semantics. I include this start: dnl check for socklen_t (in Unix98) AC_MSG_CHECKING(for socklen_t) AC_TRY_COMPILE([#include sys/socket.h socklen_t x; ],[],[AC_MSG_RESULT(yes)],[ AC_TRY_COMPILE([#include sys/socket.h int accept (int, struct sockaddr *, size_t *); ],[],[ AC_MSG_RESULT(size_t) AC_DEFINE(socklen_t,size_t)], [ AC_MSG_RESULT(int) AC_DEFINE(socklen_t,int)])]) For comparision, this is what I use in an application of mine. I haven't heard any complaints from Solaris users, but I guess they have just ignored any compilations warnings. dnl HTTPTUNNEL_TYPE_SOCKLEN_T dnl Check for the existance of type socklen_t. AC_DEFUN(HTTPTUNNEL_TYPE_SOCKLEN_T, [AC_CACHE_CHECK([for socklen_t], ac_cv_httptunnel_type_socklen_t, [ AC_TRY_COMPILE( [#include sys/types.h #include sys/socket.h], [socklen_t len = 42; return 0;], ac_cv_httptunnel_type_socklen_t=yes, ac_cv_httptunnel_type_socklen_t=no) ]) if test $ac_cv_httptunnel_type_socklen_t != yes; then AC_DEFINE(socklen_t, int) fi ])
Re: socklen_t
"lb" == lars brinkhoff [EMAIL PROTECTED] writes: lb For comparision, this is what I use in an application of mine. I lb haven't heard any complaints from Solaris users, but I guess they have lb just ignored any compilations warnings. I don't include sys/types.h. The standard says I shouldn't have to. But autoconf is about the real world as much as it is about standards... I don't use caches. See previous thread on this mailing list "config.cache considered harmful". I think checking for size_t as well as int is useful, since they may indeed be different sizes, which will affect correctness, as well as compilation warnings. Obviously, both our examples need improvement to be incorporated into autoconf. I'll leave that to the hard-working autoconf maintainers. lb dnl HTTPTUNNEL_TYPE_SOCKLEN_T lb dnl Check for the existance of type socklen_t. lb AC_DEFUN(HTTPTUNNEL_TYPE_SOCKLEN_T, lb [AC_CACHE_CHECK([for socklen_t], ac_cv_httptunnel_type_socklen_t, lb [ lb AC_TRY_COMPILE( lb [#include sys/types.h lb#include sys/socket.h], lb [socklen_t len = 42; return 0;], lb ac_cv_httptunnel_type_socklen_t=yes, lb ac_cv_httptunnel_type_socklen_t=no) lb ]) lb if test $ac_cv_httptunnel_type_socklen_t != yes; then lb AC_DEFINE(socklen_t, int) lb fi lb ])