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 <rosti.bsd@gmail.com>
This commit is contained in:
Hajimu UMEMOTO 2006-05-12 15:37:23 +00:00
parent b484e04bf9
commit 3da59cd007
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158477
7 changed files with 45 additions and 24 deletions

View File

@ -63,6 +63,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/_types.h> #include <sys/_types.h>
#include <machine/_limits.h>
#ifndef _SIZE_T_DECLARED #ifndef _SIZE_T_DECLARED
typedef __size_t size_t; typedef __size_t size_t;
@ -220,9 +221,15 @@ void endnetgrent(void);
void endprotoent(void); void endprotoent(void);
void endservent(void); void endservent(void);
void freehostent(struct hostent *); void freehostent(struct hostent *);
struct hostent *gethostbyaddr(const char *, int, int); #if __LONG_BIT == 64
int gethostbyaddr_r(const char *, int, int, struct hostent *, struct hostent *gethostbyaddr(const void *, int, int);
int gethostbyaddr_r(const void *, int, int, struct hostent *,
char *, size_t, struct hostent **, int *); 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 *); struct hostent *gethostbyname(const char *);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, int gethostbyname_r(const char *, struct hostent *, char *, size_t,
struct hostent **, int *); struct hostent **, int *);

View File

@ -550,11 +550,13 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap)
int int
_dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap)
{ {
const u_char *uaddr; const void *addr;
int len, af; socklen_t len;
int af;
char *buffer; char *buffer;
size_t buflen; size_t buflen;
int *errnop, *h_errnop; int *errnop, *h_errnop;
const u_char *uaddr;
struct hostent *hptr, he; struct hostent *hptr, he;
struct hostent_data *hed; struct hostent_data *hed;
int n; int n;
@ -570,14 +572,15 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap)
int ret_h_error; int ret_h_error;
#endif /*SUNSECURITY*/ #endif /*SUNSECURITY*/
uaddr = va_arg(ap, const u_char *); addr = va_arg(ap, const void *);
len = va_arg(ap, int); len = va_arg(ap, socklen_t);
af = va_arg(ap, int); af = va_arg(ap, int);
hptr = va_arg(ap, struct hostent *); hptr = va_arg(ap, struct hostent *);
buffer = va_arg(ap, char *); buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t); buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *); errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *);
uaddr = (const u_char *)addr;
*((struct hostent **)rval) = NULL; *((struct hostent **)rval) = NULL;

View File

@ -282,8 +282,9 @@ _ht_gethostbyname(void *rval, void *cb_data, va_list ap)
int int
_ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
{ {
const char *addr; const void *addr;
int len, af; socklen_t len;
int af;
char *buffer; char *buffer;
size_t buflen; size_t buflen;
int *errnop, *h_errnop; int *errnop, *h_errnop;
@ -292,8 +293,8 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
res_state statp; res_state statp;
int error; int error;
addr = va_arg(ap, const char *); addr = va_arg(ap, const void *);
len = va_arg(ap, int); len = va_arg(ap, socklen_t);
af = va_arg(ap, int); af = va_arg(ap, int);
hptr = va_arg(ap, struct hostent *); hptr = va_arg(ap, struct hostent *);
buffer = va_arg(ap, char *); buffer = va_arg(ap, char *);

View File

@ -55,7 +55,7 @@
.Ft struct hostent * .Ft struct hostent *
.Fn gethostbyname2 "const char *name" "int af" .Fn gethostbyname2 "const char *name" "int af"
.Ft struct hostent * .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 * .Ft struct hostent *
.Fn gethostent void .Fn gethostent void
.Ft void .Ft void
@ -246,7 +246,7 @@ struct hostent *hp;
if (!inet_aton(ipstr, &ip)) if (!inet_aton(ipstr, &ip))
errx(1, "can't parse IP address %s", ipstr); 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) sizeof ip, AF_INET)) == NULL)
errx(1, "no name associated with %s", ipstr); errx(1, "no name associated with %s", ipstr);

View File

@ -178,8 +178,8 @@ _gethostbynisname_r(const char *name, int af, struct hostent *he,
} }
static int static int
_gethostbynisaddr_r(const char *addr, int len, int af, struct hostent *he, _gethostbynisaddr_r(const void *addr, socklen_t len, int af,
struct hostent_data *hed) struct hostent *he, struct hostent_data *hed)
{ {
char *map; char *map;
char numaddr[46]; char numaddr[46];
@ -227,7 +227,7 @@ _gethostbynisname(const char *name, int af)
} }
struct hostent * struct hostent *
_gethostbynisaddr(const char *addr, int len, int af) _gethostbynisaddr(const void *addr, socklen_t len, int af)
{ {
#ifdef YP #ifdef YP
struct hostent *he; struct hostent *he;
@ -303,8 +303,8 @@ int
_nis_gethostbyaddr(void *rval, void *cb_data, va_list ap) _nis_gethostbyaddr(void *rval, void *cb_data, va_list ap)
{ {
#ifdef YP #ifdef YP
const char *addr; const void *addr;
int len; socklen_t len;
int af; int af;
char *buffer; char *buffer;
size_t buflen; size_t buflen;
@ -313,8 +313,8 @@ _nis_gethostbyaddr(void *rval, void *cb_data, va_list ap)
struct hostent_data *hed; struct hostent_data *hed;
res_state statp; res_state statp;
addr = va_arg(ap, const char *); addr = va_arg(ap, const void *);
len = va_arg(ap, int); len = va_arg(ap, socklen_t);
af = va_arg(ap, int); af = va_arg(ap, int);
hptr = va_arg(ap, struct hostent *); hptr = va_arg(ap, struct hostent *);
buffer = va_arg(ap, char *); buffer = va_arg(ap, char *);

View File

@ -573,8 +573,14 @@ gethostbyname_internal(const char *name, int af, struct hostent *hp, char *buf,
} }
int int
gethostbyaddr_r(const char *addr, int len, int af, struct hostent *hp, gethostbyaddr_r(const void *addr,
char *buf, size_t buflen, struct hostent **result, int *h_errnop) #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 u_char *uaddr = (const u_char *)addr;
const struct in6_addr *addr6; 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) { 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)) { if (IN6_IS_ADDR_LINKLOCAL(addr6)) {
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
*h_errnop = statp->res_h_errno; *h_errnop = statp->res_h_errno;
@ -678,7 +684,11 @@ gethostbyname2(const char *name, int af)
} }
struct hostent * 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 hostdata *hd;
struct hostent *rval; struct hostent *rval;

View File

@ -133,7 +133,7 @@ void _endhostdnsent(void);
void _endhosthtent(struct hostent_data *); void _endhosthtent(struct hostent_data *);
void _endnetdnsent(void); void _endnetdnsent(void);
void _endnethtent(struct netent_data *); 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); struct hostent *_gethostbynisname(const char *, int);
void _map_v4v6_address(const char *, char *); void _map_v4v6_address(const char *, char *);
void _map_v4v6_hostent(struct hostent *, char **, char *); void _map_v4v6_hostent(struct hostent *, char **, char *);