Add not advertised reentrant functions: {get,set,end}hostent_r,

gethostbyname{,2}_r, gethostbyaddr_r. Make getnameinfo(3) use
gethostbyaddr_r(3) so it is re-entrant (ahem __ypdomain). These
are not being advertised because there is a bunch of different
implementation of them that have a variety of type signatures.

If people want to follow someone's implementation, it is now easy.
This commit is contained in:
christos 2013-08-16 15:27:12 +00:00
parent 91eced933f
commit 02dd244775
4 changed files with 615 additions and 420 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $ */
/* $NetBSD: getnameinfo.c,v 1.54 2013/08/16 15:27:12 christos Exp $ */
/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
/*
@ -47,7 +47,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $");
__RCSID("$NetBSD: getnameinfo.c,v 1.54 2013/08/16 15:27:12 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -70,6 +70,7 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $");
#include <string.h>
#include "servent.h"
#include "hostent.h"
#ifdef __weak_alias
__weak_alias(getnameinfo,_getnameinfo)
@ -375,7 +376,11 @@ getnameinfo_inet(const struct sockaddr *sa, socklen_t salen,
break;
}
} else {
hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
struct hostent hent;
char hbuf[4096];
int he;
hp = gethostbyaddr_r(addr, afd->a_addrlen, afd->a_af, &hent,
hbuf, sizeof(hbuf), &he);
if (hp) {
#if 0

77
lib/libc/net/hostent.h Normal file
View File

@ -0,0 +1,77 @@
/* $NetBSD: hostent.h,v 1.1 2013/08/16 15:27:12 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <netdb.h>
#include <stdarg.h>
/*
* These are not being advertised because the interfaces are non-standard.
* There are versions by linux, aix, qnx, sun, etc. Our versions are used
* internally to provide thread safety; they mostly resemble qnx.
*/
void sethostent_r(FILE **);
struct hostent *gethostent_r(FILE *, struct hostent *, char *, size_t, int *);
void endhostent_r(FILE **);
struct hostent *gethostbyname_r(const char *, struct hostent *, char *, size_t,
int *);
struct hostent *gethostbyname2_r(const char *, int, struct hostent *, char *,
size_t, int *);
struct hostent *gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
char *, size_t, int *);
extern FILE *_h_file;
/*
* The following are internal API's and are used only for testing.
*/
struct getnamaddr {
struct hostent *hp;
char *buf;
size_t buflen;
int *he;
};
/* /etc/hosts lookup */
void _hf_sethostsfile(const char *);
int _hf_gethtbyaddr(void *, void *, va_list);
int _hf_gethtbyname(void *, void *, va_list);
/* DNS lookup */
int _dns_gethtbyaddr(void *, void *, va_list);
int _dns_gethtbyname(void *, void *, va_list);
#ifdef YP
/* NIS lookup */
int _yp_gethtbyaddr(void *, void *, va_list);
int _yp_gethtbyname(void *, void *, va_list);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: sethostent.c,v 1.17 2012/03/20 17:44:18 matt Exp $ */
/* $NetBSD: sethostent.c,v 1.18 2013/08/16 15:27:12 christos Exp $ */
/*
* Copyright (c) 1985, 1993
@ -35,7 +35,7 @@
static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "Id: sethostent.c,v 8.5 1996/09/28 06:51:07 vixie Exp ";
#else
__RCSID("$NetBSD: sethostent.c,v 1.17 2012/03/20 17:44:18 matt Exp $");
__RCSID("$NetBSD: sethostent.c,v 1.18 2013/08/16 15:27:12 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -46,16 +46,16 @@ __RCSID("$NetBSD: sethostent.c,v 1.17 2012/03/20 17:44:18 matt Exp $");
#include <netdb.h>
#include <resolv.h>
#include "hostent.h"
#ifdef __weak_alias
__weak_alias(sethostent,_sethostent)
__weak_alias(endhostent,_endhostent)
#endif
void _endhtent(void);
#ifndef _REENTRANT
void res_close(void);
#endif
void _sethtent(int);
void
/*ARGSUSED*/
@ -67,7 +67,7 @@ sethostent(int stayopen)
if (stayopen)
_res.options |= RES_STAYOPEN | RES_USEVC;
#endif
_sethtent(stayopen);
sethostent_r(&_h_file);
}
void
@ -77,5 +77,5 @@ endhostent(void)
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
res_close();
#endif
_endhtent();
endhostent_r(&_h_file);
}