From: Jarkko Hietaniemi Date: Tue, 18 Nov 1997 19:08:19 +0000 (+0200) Subject: Let Configure sort out get{host,net}byaddr* prototypes: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3fd537d4b944bc7adc1d238aecc5aea20a099af7;hp=c277df42229d99fecbc76f5da53793a409ac66e1;p=p5sagit%2Fp5-mst-13.2.git Let Configure sort out get{host,net}byaddr* prototypes: Subject: [PATCH] 5.004_54: little something for get{hos,ne}tbyaddr protos (Configure, config_h.SH, pp_sys.c) p4raw-id: //depot/perl@268 --- diff --git a/Configure b/Configure index 20b4b35..97dc199 100755 --- a/Configure +++ b/Configure @@ -314,6 +314,11 @@ d_Gconvert='' d_getgrps='' d_setgrps='' d_gethent='' +d_gethbadd='' +gethbadd_addr_type='' +gethbadd_alen_type='' +d_getnbadd='' +getnbadd_net_type='' aphostname='' d_gethname='' d_phostname='' @@ -482,6 +487,7 @@ i_malloc='' i_math='' i_memory='' i_ndbm='' +i_netdb='' i_neterrno='' i_niin='' i_sysin='' @@ -6624,6 +6630,14 @@ eval $inlibc set fsetpos d_fsetpos eval $inlibc +: see if gethostbyaddr exists +set gethostbyaddr d_gethbadd +eval $inlibc + +: see if getnetbyaddr exists +set getnetbyaddr d_getnbadd +eval $inlibc + : see if gethostent exists set gethostent d_gethent eval $inlibc @@ -9223,6 +9237,148 @@ EOM fi $rm -f ssize ssize.[co] ssize.out +: see if this is a netdb.h system +set netdb.h i_netdb +eval $inhdr + +: check for type of arguments to gethostbyaddr. This will only really +: work if the system supports prototypes and provides one for +: gethostbyaddr. +case "$d_gethbadd" in +$define) + if test "X$gethbadd_addr_type" = X -o "X$gethbadd_alen_type" = X; then + $cat <try.c < +#$i_niin I_NIIN +#$i_netdb I_NETDB +#$i_unistd I_UNISTD +#$d_socket HAS_SOCKET +#$d_socket HAS_SOCKET +#ifdef HAS_SOCKET +#include /* Might include */ +#endif +#ifdef I_NIIN +#include +#endif +#ifdef I_NETDB +#include +#endif +#ifdef I_UNISTD +#include +#endif +#define Size_t $sizetype +main() +{ + Gethbadd_addr_t addr; + Gethbadd_alen_t alen; + struct hostent* hent; + + extern struct hostent *gethostbyaddr(const Gethbadd_addr_t, Gethbadd_alen_t, int); + + alen = sizeof(struct in_addr); + addr = (Gethbadd_addr_t)malloc(alen); + /* We do not execute this so the contents of the addr matter not. */ + hent = gethostbyaddr(addr, alen, AF_INET); + + exit(0); +} +EOCP + for xxx in "void *" "char *"; do + for yyy in Size_t int; do + if $cc $ccflags -c -DGethbadd_addr_t="$xxx" -DGethbadd_alen_t="$yyy" try.c >/dev/null 2>&1 ; then + gethbadd_addr_type="$xxx" + gethbadd_alen_type="$yyy" + echo "Your system uses $xxx for the 1st argument to gethostbyaddr." >&4 + echo "and the the 2nd argument to gethostbyaddr is $yyy." >&4 + break + fi + done + test "X$gethbadd_addr_type" != X && break + done + if test "X$gethbadd_addr_type" = X; then + rp='What is the type for the 1st argument to gethostbyaddr?' + dflt="void *" + . ./myread + gethbadd_addr_type="$ans" + + # Remove the "const" if needed. + gethbadd_addr_type=`echo $gethbadd_addr_type | sed 's/^const //'` + + rp='What is the type for the 2nd argument to gethostbyaddr ?' + dflt="Size_t" + . ./myread + gethbadd_alen_type="$ans" + fi + $rm -f try.[co] + fi + ;; +*) gethbadd_addr_type='void *' + gethbadd_alen_type='Size_t' + ;; +esac + +: check for type of arguments to getnetbyaddr. This will only really +: work if the system supports prototypes and provides one for +: getnetbyaddr. +case "$d_getnbadd" in +$define) + if test "X$getnbadd_addr_type" = X -o "X$getnbadd_alen_type" = X; then + $cat <try.c < +#ifdef HAS_SOCKET +#include /* Might include */ +#endif +#ifdef I_NIIN +#include +#endif +#ifdef I_NETDB +#include +#endif +main() +{ + Getnbadd_net_t net; + struct netent* nent; + + extern struct netent *getnetbyaddr(Getnbadd_net_t, int); + + /* We do not execute this so the contents of the net matter not. */ + nent = getnetbyaddr(net, AF_INET); + + exit(0); +} +EOCP + for xxx in in_addr_t long int; do + if $cc $ccflags -c -DGetnbadd_net_t="$xxx" try.c >/dev/null 2>&1 ; then + getnbadd_net_type="$xxx" + echo "Your system uses $xxx for the 1st argument to getnetbyaddr." >&4 + break + fi + done + if test "X$getnbadd_net_type" = X; then + rp='What is the type for the 1st argument to getnetbyaddr?' + dflt="long" + . ./myread + getnbadd_net_type="$ans" + fi + $rm -f try.[co] + fi + ;; +*) getnbadd_net_type='long' + ;; +esac + : see what type of char stdio uses. echo " " if $contains 'unsigned.*char.*_ptr;' `./findhdr stdio.h` >/dev/null 2>&1 ; then @@ -10089,9 +10245,14 @@ d_fsetpos='$d_fsetpos' d_ftime='$d_ftime' d_getgrps='$d_getgrps' d_setgrps='$d_setgrps' +d_gethbadd='$d_gethbadd' +gethbadd_addr_type='$gethbadd_addr_type' +gethbadd_alen_type='$gethbadd_alen_type' d_gethent='$d_gethent' d_gethname='$d_gethname' d_getlogin='$d_getlogin' +d_getnbadd='$d_getnbadd' +getnbadd_net_type='$getnbadd_net_type' d_getpgid='$d_getpgid' d_getpgrp2='$d_getpgrp2' d_getpgrp='$d_getpgrp' @@ -10273,6 +10434,7 @@ i_malloc='$i_malloc' i_math='$i_math' i_memory='$i_memory' i_ndbm='$i_ndbm' +i_netdb='$i_netdb' i_neterrno='$i_neterrno' i_niin='$i_niin' i_pwd='$i_pwd' diff --git a/config_h.SH b/config_h.SH index cfae03a..7575143 100644 --- a/config_h.SH +++ b/config_h.SH @@ -329,6 +329,36 @@ sed <config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un- */ #$d_gethent HAS_GETHOSTENT /**/ +/* HAS_GETHBADD: + * This symbol, if defined, indicates that the gethostbyaddr routine is + * available to lookup host names by their IP addresses. + */ +#$d_gethbadd HAS_GETHBADD /**/ + +/* Gethbadd_addr_t: + * This symbol holds the type used for the 1st argument + * to gethostbyaddr(). + */ +#define Gethbadd_addr_t $gethbadd_addr_type + +/* Gethbadd_alen_t: + * This symbol holds the type used for the 2nd argument + * to gethostbyaddr(). + */ +#define Gethbadd_alen_t $gethbadd_alen_type + +/* HAS_GETNBADD: + * This symbol, if defined, indicates that the getnetbyaddr routine is + * available to lookup networks by their IP addresses. + */ +#$d_getnbadd HAS_GETNBADD /**/ + +/* Gethbadd_net_t: + * This symbol holds the type used for the 1st argument + * to getnetbyaddr(). + */ +#define Getnbadd_net_t $getnbadd_net_type + /* HAS_UNAME: * This symbol, if defined, indicates that the C program may use the * uname() routine to derive the host name. See also HAS_GETHOSTNAME @@ -1117,6 +1147,12 @@ sed <config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un- */ #$i_niin I_NETINET_IN /**/ +/* I_NETDB: + * This symbol, if defined, indicates that exists and + * should be included. + */ +#$i_netdb I_NETDB /**/ + /* I_PWD: * This symbol, if defined, indicates to the C program that it should * include . diff --git a/pp_sys.c b/pp_sys.c index 041539c..9dc6201 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -38,7 +38,9 @@ extern "C" int syscall(unsigned long,...); #if defined(HAS_SOCKET) && !defined(VMS) /* VMS handles sockets via vmsish.h */ # include -# include +# ifdef I_NETDB +# include +# endif # ifndef ENOTSOCK # ifdef I_NET_ERRNO # include @@ -3638,7 +3640,7 @@ PP(pp_ghostent) register SV *sv; #if defined(HAS_GETHOSTENT) && !defined(DONT_DECLARE_STD) struct hostent *gethostbyname(const char *); - struct hostent *gethostbyaddr(const char *, int, int); + struct hostent *gethostbyaddr(const Gethbadd_addr_t, Gethbadd_alen_t, int); struct hostent *gethostent(void); #endif struct hostent *hent; @@ -3652,9 +3654,9 @@ PP(pp_ghostent) int addrtype = POPi; SV *addrsv = POPs; STRLEN addrlen; - char *addr = SvPV(addrsv, addrlen); + Gethbadd_addr_t addr = (Gethbadd_addr_t) SvPV(addrsv, addrlen); - hent = gethostbyaddr(addr, addrlen, addrtype); + hent = gethostbyaddr(addr, (Gethbadd_alen_t) addrlen, addrtype); } else #ifdef HAS_GETHOSTENT @@ -3743,7 +3745,7 @@ PP(pp_gnetent) * long is wrong for getnetbyadddr (e.g. on Alpha). POSIX.1g says * in_addr_t but then such systems don't have broken netdb.h anyway. */ - struct netent *getnetbyaddr(long int, int); + struct netent *getnetbyaddr(Getnbadd_net_t, int); struct netent *getnetent(void); #endif struct netent *nent; @@ -3752,8 +3754,8 @@ PP(pp_gnetent) nent = getnetbyname(POPp); else if (which == OP_GNBYADDR) { int addrtype = POPi; - unsigned long addr = U_L(POPn); - nent = getnetbyaddr((long)addr, addrtype); + Getnbadd_net_t addr = (Getnbadd_net_t) U_L(POPn); + nent = getnetbyaddr(addr, addrtype); } else nent = getnetent();