From 2b79ff2c489db770d0e2c91392bc3554ed06e766 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 3 Aug 1999 20:02:44 +0000 Subject: [PATCH] Initial inet_aton() detection. --- build/openldap.m4 | 27 ++++++++++++ configure | 91 ++++++++++++++++++++++++++++++--------- configure.in | 2 + include/ac/socket.h | 6 +++ include/portable.h.in | 3 ++ libraries/libldap/os-ip.c | 15 +++---- servers/slapd/daemon.c | 13 +----- 7 files changed, 114 insertions(+), 43 deletions(-) diff --git a/build/openldap.m4 b/build/openldap.m4 index 8909837c7b..a676e1b4fe 100644 --- a/build/openldap.m4 +++ b/build/openldap.m4 @@ -773,6 +773,33 @@ AC_DEFUN(OL_TYPE_SOCKLEN_T, ])dnl dnl dnl ==================================================================== +dnl Define inet_aton is available +AC_DEFUN(OL_FUNC_INET_ATON, + [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton, + [AC_TRY_COMPILE([ +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_SOCKET_H +# include +# ifdef HAVE_SYS_SELECT_H +# include +# endif +# include +# ifdef HAVE_ARPA_INET_H +# include +# endif +#endif +], [struct in_addr in; +int rc = inet_aton( "255.255.255.255", &in );], + ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)]) + if test $ol_cv_func_inet_aton != no; then + AC_DEFINE(HAVE_INET_ATON, 1, + [define to you inet_aton(3) is available]) + fi + ])dnl +dnl +dnl ==================================================================== dnl check no of arguments for ctime_r AC_DEFUN(OL_FUNC_CTIME_R_NARGS, [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs, diff --git a/configure b/configure index 40a2a636d9..3862a2559f 100755 --- a/configure +++ b/configure @@ -12109,13 +12109,62 @@ fi fi +echo $ac_n "checking for inet_aton()""... $ac_c" 1>&6 +echo "configure:12114: checking for inet_aton()" >&5 +if eval "test \"\${ol_cv_func_inet_aton+set}\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +#endif +#ifdef HAVE_SYS_SOCKET_H +# include +# ifdef HAVE_SYS_SELECT_H +# include +# endif +# include +# ifdef HAVE_ARPA_INET_H +# include +# endif +#endif + +int main() { +struct in_addr in; +int rc = inet_aton( "255.255.255.255", &in ); +; return 0; } +EOF +if { (eval echo configure:12141: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ol_cv_func_inet_aton=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ol_cv_func_inet_aton=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ol_cv_func_inet_aton" 1>&6 + if test $ol_cv_func_inet_aton != no; then + cat >> confdefs.h <<\EOF +#define HAVE_INET_ATON 1 +EOF + + fi + + echo $ac_n "checking for vprintf""... $ac_c" 1>&6 -echo "configure:12114: checking for vprintf" >&5 +echo "configure:12163: checking for vprintf" >&5 if eval "test \"\${ac_cv_func_vprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12192: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_vprintf=yes" else @@ -12163,12 +12212,12 @@ fi if test "$ac_cv_func_vprintf" != yes; then echo $ac_n "checking for _doprnt""... $ac_c" 1>&6 -echo "configure:12167: checking for _doprnt" >&5 +echo "configure:12216: checking for _doprnt" >&5 if eval "test \"\${ac_cv_func__doprnt+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12245: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__doprnt=yes" else @@ -12221,12 +12270,12 @@ if test $ac_cv_func_vprintf = yes ; then for ac_func in vsnprintf vsprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:12225: checking for $ac_func" >&5 +echo "configure:12274: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12303: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -12325,12 +12374,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:12329: checking for $ac_func" >&5 +echo "configure:12378: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12407: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -12382,12 +12431,12 @@ done for ac_func in getopt tempnam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:12386: checking for $ac_func" >&5 +echo "configure:12435: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12464: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -12440,13 +12489,13 @@ done # Check Configuration echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 -echo "configure:12444: checking declaration of sys_errlist" >&5 +echo "configure:12493: checking declaration of sys_errlist" >&5 if eval "test \"\${ol_cv_dcl_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -12456,7 +12505,7 @@ int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:12460: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:12509: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_dcl_sys_errlist=yes ol_cv_have_sys_errlist=yes @@ -12479,20 +12528,20 @@ EOF echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 -echo "configure:12483: checking existence of sys_errlist" >&5 +echo "configure:12532: checking existence of sys_errlist" >&5 if eval "test \"\${ol_cv_have_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:12496: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:12545: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ol_cv_have_sys_errlist=yes else diff --git a/configure.in b/configure.in index 6cce7a6648..fedac7e78e 100644 --- a/configure.in +++ b/configure.in @@ -1798,6 +1798,8 @@ dnl AM_FUNC_MKTIME dnl checks for sys/time.h and unistd.h AC_FUNC_STRFTIME dnl AM_FUNC_STRTOD +OL_FUNC_INET_ATON + dnl we should use vfork instead of fork in a number of places... dnl AC_FUNC_VFORK AC_FUNC_VPRINTF diff --git a/include/ac/socket.h b/include/ac/socket.h index bef8a2ac2f..bd1805a782 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -101,6 +101,12 @@ # define AC_SOCKET_INVALID (-1) #endif +#if !defined( HAVE_INET_ATON ) && !defined( inet_aton ) +#define inet_aton ldap_pvt_inet_aton +struct in_addr; +int ldap_pvt_inet_aton( const char *, struct in_addr * ); +#endif + #if defined(__WIN32) && defined(_ALPHA) /* NT on Alpha is hosed. */ #define AC_HTONL( l ) \ diff --git a/include/portable.h.in b/include/portable.h.in index f8a74c960c..a00599db0c 100644 --- a/include/portable.h.in +++ b/include/portable.h.in @@ -738,6 +738,9 @@ /* define if cross compiling */ #undef CROSS_COMPILING +/* define to you inet_aton(3) is available */ +#undef HAVE_INET_ATON + /* define if sys_errlist is not declared in stdio.h or errno.h */ #undef DECL_SYS_ERRLIST diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 140f333e74..eba57bee27 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -257,23 +257,18 @@ ldap_pvt_connect(LDAP *ld, int s, struct sockaddr_in *sin, int async) return ( -1 ); } -static int -ldap_pvt_inet_aton( LDAP *ld, const char *host, struct in_addr *in) -{ -#ifdef notyet -/* #ifdef HAVE_INET_ATON */ - return inet_aton( host, in ); -#else +#ifndef HAVE_INET_ATON +int +ldap_pvt_inet_aton( const char *host, struct in_addr *in) { unsigned long u = inet_addr( host ); if ( u != 0xffffffff || u != (unsigned long) -1 ) { in->s_addr = u; return 1; } -} -#endif return 0; } +#endif int @@ -291,7 +286,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, const char *host, osip_debug(ld, "ldap_connect_to_host\n",0,0,0); if (host != NULL) { - if (! ldap_pvt_inet_aton( ld, host, &in) ) { + if (! inet_aton( host, &in) ) { rc = ldap_pvt_gethostbyname_a(host, &he_buf, &ha_buf, &hp, &local_h_errno); diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 548bbf3d12..e937ca9158 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -251,13 +251,7 @@ open_listener( } else { /* host or address was specified */ - -#ifdef HAVE_WINSOCK - if((l.sl_addr.sin_addr.S_un.S_addr = inet_addr(lud->lud_host)) == INADDR_NONE) -#else - if(!inet_aton(lud->lud_host, &l.sl_addr.sin_addr)) -#endif - { + if( !inet_aton( lud->lud_host, &l.sl_addr.sin_addr ) ) { struct hostent *he = gethostbyname( lud->lud_host ); if( he == NULL ) { Debug( LDAP_DEBUG_ANY, "invalid host (%s) in URL: %s", @@ -266,13 +260,8 @@ open_listener( return NULL; } -#ifdef HAVE_WINSOCK - memcpy( &l.sl_addr.sin_addr.S_un.S_addr, he->h_addr, - sizeof( l.sl_addr.sin_addr.S_un.S_addr ) ); -#else memcpy( &l.sl_addr.sin_addr, he->h_addr, sizeof( l.sl_addr.sin_addr ) ); -#endif } } -- 2.39.5