From 3da59cd0072b20be9464c3f0afe83579fc83909c Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Fri, 12 May 2006 15:37:23 +0000 Subject: [PATCH] Fix gethostbyaddr() prototype to conform to IEEE Std 1003.1: http://www.opengroup.org/onlinepubs/009695399/functions/gethostbyaddr.html gethostbyaddr_r() is changed as well. It breaks ABI backward compatibility on 64 bit arch. So, we fix it on 32 bit arch only for now. Reported by: Rostislav Krasny --- include/netdb.h | 11 +++++++++-- lib/libc/net/gethostbydns.c | 11 +++++++---- lib/libc/net/gethostbyht.c | 9 +++++---- lib/libc/net/gethostbyname.3 | 4 ++-- lib/libc/net/gethostbynis.c | 14 +++++++------- lib/libc/net/gethostnamadr.c | 18 ++++++++++++++---- lib/libc/net/netdb_private.h | 2 +- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/include/netdb.h b/include/netdb.h index 218bee3f79d4..6e7d8189695a 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -63,6 +63,7 @@ #include #include +#include #ifndef _SIZE_T_DECLARED typedef __size_t size_t; @@ -220,9 +221,15 @@ void endnetgrent(void); void endprotoent(void); void endservent(void); void freehostent(struct hostent *); -struct hostent *gethostbyaddr(const char *, int, int); -int gethostbyaddr_r(const char *, int, int, struct hostent *, +#if __LONG_BIT == 64 +struct hostent *gethostbyaddr(const void *, int, int); +int gethostbyaddr_r(const void *, int, int, struct hostent *, char *, size_t, struct hostent **, int *); +#else +struct hostent *gethostbyaddr(const void *, socklen_t, int); +int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, + char *, size_t, struct hostent **, int *); +#endif struct hostent *gethostbyname(const char *); int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c index 8558513b397d..b19dc799f6b4 100644 --- a/lib/libc/net/gethostbydns.c +++ b/lib/libc/net/gethostbydns.c @@ -550,11 +550,13 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) int _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) { - const u_char *uaddr; - int len, af; + const void *addr; + socklen_t len; + int af; char *buffer; size_t buflen; int *errnop, *h_errnop; + const u_char *uaddr; struct hostent *hptr, he; struct hostent_data *hed; int n; @@ -570,14 +572,15 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) int ret_h_error; #endif /*SUNSECURITY*/ - uaddr = va_arg(ap, const u_char *); - len = va_arg(ap, int); + addr = va_arg(ap, const void *); + len = va_arg(ap, socklen_t); af = va_arg(ap, int); hptr = va_arg(ap, struct hostent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *); + uaddr = (const u_char *)addr; *((struct hostent **)rval) = NULL; diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index 0782518b10c3..cb5009d1dcdf 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -282,8 +282,9 @@ _ht_gethostbyname(void *rval, void *cb_data, va_list ap) int _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) { - const char *addr; - int len, af; + const void *addr; + socklen_t len; + int af; char *buffer; size_t buflen; int *errnop, *h_errnop; @@ -292,8 +293,8 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) res_state statp; int error; - addr = va_arg(ap, const char *); - len = va_arg(ap, int); + addr = va_arg(ap, const void *); + len = va_arg(ap, socklen_t); af = va_arg(ap, int); hptr = va_arg(ap, struct hostent *); buffer = va_arg(ap, char *); diff --git a/lib/libc/net/gethostbyname.3 b/lib/libc/net/gethostbyname.3 index 6f9ee0dce1f1..7c83d0270afd 100644 --- a/lib/libc/net/gethostbyname.3 +++ b/lib/libc/net/gethostbyname.3 @@ -55,7 +55,7 @@ .Ft struct hostent * .Fn gethostbyname2 "const char *name" "int af" .Ft struct hostent * -.Fn gethostbyaddr "const char *addr" "int len" "int type" +.Fn gethostbyaddr "const void *addr" "socklen_t len" "int type" .Ft struct hostent * .Fn gethostent void .Ft void @@ -246,7 +246,7 @@ struct hostent *hp; if (!inet_aton(ipstr, &ip)) errx(1, "can't parse IP address %s", ipstr); -if ((hp = gethostbyaddr((const char *)&ip, +if ((hp = gethostbyaddr((const void *)&ip, sizeof ip, AF_INET)) == NULL) errx(1, "no name associated with %s", ipstr); diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c index 5ce60972ec80..7921ced71946 100644 --- a/lib/libc/net/gethostbynis.c +++ b/lib/libc/net/gethostbynis.c @@ -178,8 +178,8 @@ _gethostbynisname_r(const char *name, int af, struct hostent *he, } static int -_gethostbynisaddr_r(const char *addr, int len, int af, struct hostent *he, - struct hostent_data *hed) +_gethostbynisaddr_r(const void *addr, socklen_t len, int af, + struct hostent *he, struct hostent_data *hed) { char *map; char numaddr[46]; @@ -227,7 +227,7 @@ _gethostbynisname(const char *name, int af) } struct hostent * -_gethostbynisaddr(const char *addr, int len, int af) +_gethostbynisaddr(const void *addr, socklen_t len, int af) { #ifdef YP struct hostent *he; @@ -303,8 +303,8 @@ int _nis_gethostbyaddr(void *rval, void *cb_data, va_list ap) { #ifdef YP - const char *addr; - int len; + const void *addr; + socklen_t len; int af; char *buffer; size_t buflen; @@ -313,8 +313,8 @@ _nis_gethostbyaddr(void *rval, void *cb_data, va_list ap) struct hostent_data *hed; res_state statp; - addr = va_arg(ap, const char *); - len = va_arg(ap, int); + addr = va_arg(ap, const void *); + len = va_arg(ap, socklen_t); af = va_arg(ap, int); hptr = va_arg(ap, struct hostent *); buffer = va_arg(ap, char *); diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 965af6642b9b..7ff3500ba0e0 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -573,8 +573,14 @@ gethostbyname_internal(const char *name, int af, struct hostent *hp, char *buf, } int -gethostbyaddr_r(const char *addr, int len, int af, struct hostent *hp, - char *buf, size_t buflen, struct hostent **result, int *h_errnop) +gethostbyaddr_r(const void *addr, +#if __LONG_BIT == 64 + int len, +#else + socklen_t len, +#endif + int af, struct hostent *hp, char *buf, size_t buflen, + struct hostent **result, int *h_errnop) { const u_char *uaddr = (const u_char *)addr; const struct in6_addr *addr6; @@ -606,7 +612,7 @@ gethostbyaddr_r(const char *addr, int len, int af, struct hostent *hp, } if (af == AF_INET6 && len == NS_IN6ADDRSZ) { - addr6 = (const struct in6_addr *)(const void *)uaddr; + addr6 = (const struct in6_addr *)addr; if (IN6_IS_ADDR_LINKLOCAL(addr6)) { RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); *h_errnop = statp->res_h_errno; @@ -678,7 +684,11 @@ gethostbyname2(const char *name, int af) } struct hostent * -gethostbyaddr(const char *addr, int len, int af) +#if __LONG_BIT == 64 +gethostbyaddr(const void *addr, int len, int af) +#else +gethostbyaddr(const void *addr, socklen_t len, int af) +#endif { struct hostdata *hd; struct hostent *rval; diff --git a/lib/libc/net/netdb_private.h b/lib/libc/net/netdb_private.h index e5535f68da1a..b48dd7be6d07 100644 --- a/lib/libc/net/netdb_private.h +++ b/lib/libc/net/netdb_private.h @@ -133,7 +133,7 @@ void _endhostdnsent(void); void _endhosthtent(struct hostent_data *); void _endnetdnsent(void); void _endnethtent(struct netent_data *); -struct hostent *_gethostbynisaddr(const char *, int, int); +struct hostent *_gethostbynisaddr(const void *, socklen_t, int); struct hostent *_gethostbynisname(const char *, int); void _map_v4v6_address(const char *, char *); void _map_v4v6_hostent(struct hostent *, char **, char *);