1994-05-27 05:00:24 +00:00
|
|
|
/*-
|
2017-11-25 17:12:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
1994-09-25 02:12:49 +00:00
|
|
|
* Copyright (c) 1994, Garrett Wollman
|
1994-05-27 05:00:24 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-09-25 02:12:49 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
|
1994-05-27 05:00:24 +00:00
|
|
|
* 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 REGENTS 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.
|
|
|
|
*/
|
|
|
|
|
2002-03-22 21:53:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2003-04-24 18:05:48 +00:00
|
|
|
#include "namespace.h"
|
2005-04-28 18:03:43 +00:00
|
|
|
#include "reentrant.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2005-04-25 17:36:28 +00:00
|
|
|
#include <errno.h>
|
2005-04-28 18:03:43 +00:00
|
|
|
#include <stdlib.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <string.h>
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <nsswitch.h>
|
1996-08-29 20:08:19 +00:00
|
|
|
#include <arpa/nameser.h> /* XXX hack for _res */
|
|
|
|
#include <resolv.h> /* XXX hack for _res */
|
2003-04-24 18:05:48 +00:00
|
|
|
#include "un-namespace.h"
|
2005-04-27 19:12:57 +00:00
|
|
|
#include "netdb_private.h"
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
#include "nscache.h"
|
|
|
|
#endif
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
static int gethostbyname_internal(const char *, int, struct hostent *, char *,
|
|
|
|
size_t, struct hostent **, int *, res_state);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2016-04-30 01:24:24 +00:00
|
|
|
/* Host lookup order if nsswitch.conf is broken or nonexistent */
|
2005-04-25 17:36:28 +00:00
|
|
|
static const ns_src default_src[] = {
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{ NSSRC_FILES, NS_SUCCESS },
|
|
|
|
{ NSSRC_DNS, NS_SUCCESS },
|
|
|
|
{ 0 }
|
1994-08-09 20:23:14 +00:00
|
|
|
};
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static int host_id_func(char *, size_t *, va_list, void *);
|
|
|
|
static int host_marshal_func(char *, size_t *, void *, va_list, void *);
|
|
|
|
static int host_unmarshal_func(char *, size_t, void *, va_list, void *);
|
|
|
|
#endif
|
1994-08-09 20:23:14 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
NETDB_THREAD_ALLOC(hostent)
|
|
|
|
NETDB_THREAD_ALLOC(hostent_data)
|
|
|
|
NETDB_THREAD_ALLOC(hostdata)
|
2005-04-28 18:03:43 +00:00
|
|
|
|
|
|
|
static void
|
2006-04-15 16:20:27 +00:00
|
|
|
hostent_free(void *ptr)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hostent_data_free(void *ptr)
|
2005-04-28 18:03:43 +00:00
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent_data *hed = ptr;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
if (hed == NULL)
|
2005-04-28 18:03:43 +00:00
|
|
|
return;
|
2006-04-15 16:20:27 +00:00
|
|
|
hed->stayopen = 0;
|
|
|
|
_endhosthtent(hed);
|
|
|
|
free(hed);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-04-15 16:20:27 +00:00
|
|
|
hostdata_free(void *ptr)
|
1996-08-29 20:08:19 +00:00
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
free(ptr);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
int
|
|
|
|
__copy_hostent(struct hostent *he, struct hostent *hptr, char *buf,
|
|
|
|
size_t buflen)
|
2005-04-28 18:03:43 +00:00
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
char *cp;
|
|
|
|
char **ptr;
|
|
|
|
int i, n;
|
|
|
|
int nptr, len;
|
|
|
|
|
|
|
|
/* Find out the amount of space required to store the answer. */
|
|
|
|
nptr = 2; /* NULL ptrs */
|
|
|
|
len = (char *)ALIGN(buf) - buf;
|
|
|
|
for (i = 0; he->h_addr_list[i]; i++, nptr++) {
|
|
|
|
len += he->h_length;
|
|
|
|
}
|
|
|
|
for (i = 0; he->h_aliases[i]; i++, nptr++) {
|
|
|
|
len += strlen(he->h_aliases[i]) + 1;
|
|
|
|
}
|
|
|
|
len += strlen(he->h_name) + 1;
|
|
|
|
len += nptr * sizeof(char*);
|
|
|
|
|
|
|
|
if (len > buflen) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return (-1);
|
|
|
|
}
|
2005-04-28 18:03:43 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
/* copy address size and type */
|
|
|
|
hptr->h_addrtype = he->h_addrtype;
|
|
|
|
n = hptr->h_length = he->h_length;
|
|
|
|
|
|
|
|
ptr = (char **)ALIGN(buf);
|
|
|
|
cp = (char *)ALIGN(buf) + nptr * sizeof(char *);
|
|
|
|
|
|
|
|
/* copy address list */
|
|
|
|
hptr->h_addr_list = ptr;
|
|
|
|
for (i = 0; he->h_addr_list[i]; i++ , ptr++) {
|
|
|
|
memcpy(cp, he->h_addr_list[i], n);
|
|
|
|
hptr->h_addr_list[i] = cp;
|
|
|
|
cp += n;
|
|
|
|
}
|
|
|
|
hptr->h_addr_list[i] = NULL;
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* copy official name */
|
|
|
|
n = strlen(he->h_name) + 1;
|
|
|
|
strcpy(cp, he->h_name);
|
|
|
|
hptr->h_name = cp;
|
|
|
|
cp += n;
|
|
|
|
|
|
|
|
/* copy aliases */
|
|
|
|
hptr->h_aliases = ptr;
|
|
|
|
for (i = 0 ; he->h_aliases[i]; i++) {
|
|
|
|
n = strlen(he->h_aliases[i]) + 1;
|
|
|
|
strcpy(cp, he->h_aliases[i]);
|
|
|
|
hptr->h_aliases[i] = cp;
|
|
|
|
cp += n;
|
|
|
|
}
|
|
|
|
hptr->h_aliases[i] = NULL;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static int
|
|
|
|
host_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata)
|
|
|
|
{
|
|
|
|
res_state statp;
|
|
|
|
u_long res_options;
|
|
|
|
|
|
|
|
const int op_id = 1;
|
|
|
|
char *str;
|
2006-05-21 11:27:28 +00:00
|
|
|
void *addr;
|
|
|
|
socklen_t len;
|
|
|
|
int type;
|
2006-04-28 12:03:38 +00:00
|
|
|
|
|
|
|
size_t desired_size, size;
|
|
|
|
enum nss_lookup_type lookup_type;
|
|
|
|
char *p;
|
|
|
|
int res = NS_UNAVAIL;
|
|
|
|
|
|
|
|
statp = __res_state();
|
|
|
|
res_options = statp->options & (RES_RECURSE | RES_DEFNAMES |
|
|
|
|
RES_DNSRCH | RES_NOALIASES | RES_USE_INET6);
|
|
|
|
|
2020-04-15 18:15:58 +00:00
|
|
|
lookup_type = (enum nss_lookup_type)(uintptr_t)cache_mdata;
|
2006-04-28 12:03:38 +00:00
|
|
|
switch (lookup_type) {
|
|
|
|
case nss_lt_name:
|
|
|
|
str = va_arg(ap, char *);
|
|
|
|
type = va_arg(ap, int);
|
|
|
|
|
|
|
|
size = strlen(str);
|
|
|
|
desired_size = sizeof(res_options) + sizeof(int) +
|
|
|
|
sizeof(enum nss_lookup_type) + sizeof(int) + size + 1;
|
|
|
|
|
|
|
|
if (desired_size > *buffer_size) {
|
|
|
|
res = NS_RETURN;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = buffer;
|
|
|
|
|
|
|
|
memcpy(p, &res_options, sizeof(res_options));
|
|
|
|
p += sizeof(res_options);
|
|
|
|
|
|
|
|
memcpy(p, &op_id, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
|
|
|
memcpy(p, &lookup_type, sizeof(enum nss_lookup_type));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
|
|
|
memcpy(p, &type, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
|
|
|
memcpy(p, str, size + 1);
|
|
|
|
|
|
|
|
res = NS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
2006-05-21 11:27:28 +00:00
|
|
|
addr = va_arg(ap, void *);
|
|
|
|
len = va_arg(ap, socklen_t);
|
2006-04-28 12:03:38 +00:00
|
|
|
type = va_arg(ap, int);
|
|
|
|
|
|
|
|
desired_size = sizeof(res_options) + sizeof(int) +
|
2006-05-21 11:27:28 +00:00
|
|
|
sizeof(enum nss_lookup_type) + sizeof(int) +
|
|
|
|
sizeof(socklen_t) + len;
|
2006-04-28 12:03:38 +00:00
|
|
|
|
|
|
|
if (desired_size > *buffer_size) {
|
|
|
|
res = NS_RETURN;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = buffer;
|
|
|
|
memcpy(p, &res_options, sizeof(res_options));
|
|
|
|
p += sizeof(res_options);
|
|
|
|
|
|
|
|
memcpy(p, &op_id, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
|
|
|
memcpy(p, &lookup_type, sizeof(enum nss_lookup_type));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
|
|
|
memcpy(p, &type, sizeof(int));
|
|
|
|
p += sizeof(int);
|
|
|
|
|
2006-05-21 11:27:28 +00:00
|
|
|
memcpy(p, &len, sizeof(socklen_t));
|
|
|
|
p += sizeof(socklen_t);
|
2006-04-28 12:03:38 +00:00
|
|
|
|
2006-05-21 11:27:28 +00:00
|
|
|
memcpy(p, addr, len);
|
2006-04-28 12:03:38 +00:00
|
|
|
|
|
|
|
res = NS_SUCCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
fin:
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
host_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap,
|
|
|
|
void *cache_mdata)
|
|
|
|
{
|
|
|
|
char *str;
|
2006-05-21 11:27:28 +00:00
|
|
|
void *addr;
|
|
|
|
socklen_t len;
|
|
|
|
int type;
|
2006-04-28 12:03:38 +00:00
|
|
|
struct hostent *ht;
|
|
|
|
|
|
|
|
struct hostent new_ht;
|
|
|
|
size_t desired_size, aliases_size, addr_size, size;
|
|
|
|
char *p, **iter;
|
|
|
|
|
2020-04-15 18:15:58 +00:00
|
|
|
switch ((enum nss_lookup_type)(uintptr_t)cache_mdata) {
|
2006-04-28 12:03:38 +00:00
|
|
|
case nss_lt_name:
|
|
|
|
str = va_arg(ap, char *);
|
|
|
|
type = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
2006-05-21 11:27:28 +00:00
|
|
|
addr = va_arg(ap, void *);
|
|
|
|
len = va_arg(ap, socklen_t);
|
2006-04-28 12:03:38 +00:00
|
|
|
type = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
ht = va_arg(ap, struct hostent *);
|
|
|
|
|
|
|
|
desired_size = _ALIGNBYTES + sizeof(struct hostent) + sizeof(char *);
|
|
|
|
if (ht->h_name != NULL)
|
|
|
|
desired_size += strlen(ht->h_name) + 1;
|
|
|
|
|
|
|
|
if (ht->h_aliases != NULL) {
|
|
|
|
aliases_size = 0;
|
|
|
|
for (iter = ht->h_aliases; *iter; ++iter) {
|
|
|
|
desired_size += strlen(*iter) + 1;
|
|
|
|
++aliases_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
desired_size += _ALIGNBYTES +
|
|
|
|
(aliases_size + 1) * sizeof(char *);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ht->h_addr_list != NULL) {
|
|
|
|
addr_size = 0;
|
|
|
|
for (iter = ht->h_addr_list; *iter; ++iter)
|
|
|
|
++addr_size;
|
|
|
|
|
|
|
|
desired_size += addr_size * _ALIGN(ht->h_length);
|
|
|
|
desired_size += _ALIGNBYTES + (addr_size + 1) * sizeof(char *);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desired_size > *buffer_size) {
|
|
|
|
/* this assignment is here for future use */
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
return (NS_RETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&new_ht, ht, sizeof(struct hostent));
|
|
|
|
memset(buffer, 0, desired_size);
|
|
|
|
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
p = buffer + sizeof(struct hostent) + sizeof(char *);
|
|
|
|
memcpy(buffer + sizeof(struct hostent), &p, sizeof(char *));
|
|
|
|
p = (char *)_ALIGN(p);
|
|
|
|
|
|
|
|
if (new_ht.h_name != NULL) {
|
|
|
|
size = strlen(new_ht.h_name);
|
|
|
|
memcpy(p, new_ht.h_name, size);
|
|
|
|
new_ht.h_name = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_ht.h_aliases != NULL) {
|
|
|
|
p = (char *)_ALIGN(p);
|
|
|
|
memcpy(p, new_ht.h_aliases, sizeof(char *) * aliases_size);
|
|
|
|
new_ht.h_aliases = (char **)p;
|
|
|
|
p += sizeof(char *) * (aliases_size + 1);
|
|
|
|
|
|
|
|
for (iter = new_ht.h_aliases; *iter; ++iter) {
|
|
|
|
size = strlen(*iter);
|
|
|
|
memcpy(p, *iter, size);
|
|
|
|
*iter = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_ht.h_addr_list != NULL) {
|
|
|
|
p = (char *)_ALIGN(p);
|
|
|
|
memcpy(p, new_ht.h_addr_list, sizeof(char *) * addr_size);
|
|
|
|
new_ht.h_addr_list = (char **)p;
|
|
|
|
p += sizeof(char *) * (addr_size + 1);
|
|
|
|
|
|
|
|
size = _ALIGN(new_ht.h_length);
|
|
|
|
for (iter = new_ht.h_addr_list; *iter; ++iter) {
|
|
|
|
memcpy(p, *iter, size);
|
|
|
|
*iter = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(buffer, &new_ht, sizeof(struct hostent));
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
host_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap,
|
|
|
|
void *cache_mdata)
|
|
|
|
{
|
|
|
|
char *str;
|
2006-05-21 11:27:28 +00:00
|
|
|
void *addr;
|
|
|
|
socklen_t len;
|
|
|
|
int type;
|
2006-04-28 12:03:38 +00:00
|
|
|
struct hostent *ht;
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
char **iter;
|
|
|
|
char *orig_buf;
|
|
|
|
size_t orig_buf_size;
|
|
|
|
|
2020-04-15 18:15:58 +00:00
|
|
|
switch ((enum nss_lookup_type)(uintptr_t)cache_mdata) {
|
2006-04-28 12:03:38 +00:00
|
|
|
case nss_lt_name:
|
|
|
|
str = va_arg(ap, char *);
|
|
|
|
type = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
2006-05-21 11:27:28 +00:00
|
|
|
addr = va_arg(ap, void *);
|
|
|
|
len = va_arg(ap, socklen_t);
|
2006-04-28 12:03:38 +00:00
|
|
|
type = va_arg(ap, int);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ht = va_arg(ap, struct hostent *);
|
|
|
|
orig_buf = va_arg(ap, char *);
|
|
|
|
orig_buf_size = va_arg(ap, size_t);
|
|
|
|
|
|
|
|
if (orig_buf_size <
|
|
|
|
buffer_size - sizeof(struct hostent) - sizeof(char *)) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return (NS_RETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ht, buffer, sizeof(struct hostent));
|
|
|
|
memcpy(&p, buffer + sizeof(struct hostent), sizeof(char *));
|
|
|
|
|
|
|
|
orig_buf = (char *)_ALIGN(orig_buf);
|
|
|
|
memcpy(orig_buf, buffer + sizeof(struct hostent) + sizeof(char *) +
|
|
|
|
_ALIGN(p) - (size_t)p,
|
|
|
|
buffer_size - sizeof(struct hostent) - sizeof(char *) -
|
|
|
|
_ALIGN(p) + (size_t)p);
|
|
|
|
p = (char *)_ALIGN(p);
|
|
|
|
|
|
|
|
NS_APPLY_OFFSET(ht->h_name, orig_buf, p, char *);
|
|
|
|
if (ht->h_aliases != NULL) {
|
|
|
|
NS_APPLY_OFFSET(ht->h_aliases, orig_buf, p, char **);
|
|
|
|
|
|
|
|
for (iter = ht->h_aliases; *iter; ++iter)
|
|
|
|
NS_APPLY_OFFSET(*iter, orig_buf, p, char *);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ht->h_addr_list != NULL) {
|
|
|
|
NS_APPLY_OFFSET(ht->h_addr_list, orig_buf, p, char **);
|
|
|
|
|
|
|
|
for (iter = ht->h_addr_list; *iter; ++iter)
|
|
|
|
NS_APPLY_OFFSET(*iter, orig_buf, p, char *);
|
|
|
|
}
|
|
|
|
|
|
|
|
*((struct hostent **)retval) = ht;
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
#endif /* NS_CACHING */
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
static int
|
|
|
|
fakeaddr(const char *name, int af, struct hostent *hp, char *buf,
|
2006-04-28 12:03:38 +00:00
|
|
|
size_t buflen, res_state statp)
|
2006-04-15 16:20:27 +00:00
|
|
|
{
|
|
|
|
struct hostent_data *hed;
|
|
|
|
struct hostent he;
|
|
|
|
|
|
|
|
if ((hed = __hostent_data_init()) == NULL) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((af != AF_INET ||
|
|
|
|
inet_aton(name, (struct in_addr *)hed->host_addr) != 1) &&
|
|
|
|
inet_pton(af, name, hed->host_addr) != 1) {
|
|
|
|
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
strncpy(hed->hostbuf, name, MAXDNAME);
|
|
|
|
hed->hostbuf[MAXDNAME] = '\0';
|
|
|
|
if (af == AF_INET && (statp->options & RES_USE_INET6) != 0U) {
|
|
|
|
_map_v4v6_address((char *)hed->host_addr,
|
|
|
|
(char *)hed->host_addr);
|
|
|
|
af = AF_INET6;
|
|
|
|
}
|
|
|
|
he.h_addrtype = af;
|
|
|
|
switch(af) {
|
|
|
|
case AF_INET:
|
|
|
|
he.h_length = NS_INADDRSZ;
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
he.h_length = NS_IN6ADDRSZ;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EAFNOSUPPORT;
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
he.h_name = hed->hostbuf;
|
|
|
|
he.h_aliases = hed->host_aliases;
|
|
|
|
hed->host_aliases[0] = NULL;
|
|
|
|
hed->h_addr_ptrs[0] = (char *)hed->host_addr;
|
|
|
|
hed->h_addr_ptrs[1] = NULL;
|
|
|
|
he.h_addr_list = hed->h_addr_ptrs;
|
2010-08-13 06:39:54 +00:00
|
|
|
if (__copy_hostent(&he, hp, buf, buflen) != 0) {
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-04-15 16:20:27 +00:00
|
|
|
RES_SET_H_ERRNO(statp, NETDB_SUCCESS);
|
2010-08-13 06:39:54 +00:00
|
|
|
return (0);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-04-15 16:20:27 +00:00
|
|
|
gethostbyname_r(const char *name, struct hostent *he, char *buffer,
|
|
|
|
size_t buflen, struct hostent **result, int *h_errnop)
|
2005-04-28 18:03:43 +00:00
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
res_state statp;
|
1996-08-29 20:08:19 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
statp = __res_state();
|
|
|
|
if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) {
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
return (-1);
|
2005-04-25 17:36:28 +00:00
|
|
|
}
|
2006-04-15 16:20:27 +00:00
|
|
|
if (statp->options & RES_USE_INET6) {
|
|
|
|
if (fakeaddr(name, AF_INET, he, buffer, buflen, statp) == 0) {
|
|
|
|
*result = he;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (gethostbyname_internal(name, AF_INET6, he, buffer, buflen,
|
|
|
|
result, h_errnop, statp) == 0)
|
|
|
|
return (0);
|
2000-10-27 12:34:52 +00:00
|
|
|
}
|
2006-04-15 16:20:27 +00:00
|
|
|
return (gethostbyname_internal(name, AF_INET, he, buffer, buflen,
|
|
|
|
result, h_errnop, statp));
|
1996-08-29 20:08:19 +00:00
|
|
|
}
|
|
|
|
|
2005-04-28 18:03:43 +00:00
|
|
|
int
|
2006-04-15 16:20:27 +00:00
|
|
|
gethostbyname2_r(const char *name, int af, struct hostent *he, char *buffer,
|
|
|
|
size_t buflen, struct hostent **result, int *h_errnop)
|
2005-04-25 17:36:28 +00:00
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
res_state statp;
|
|
|
|
|
|
|
|
statp = __res_state();
|
|
|
|
if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) {
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
return (-1);
|
2005-04-25 17:36:28 +00:00
|
|
|
}
|
2006-04-15 16:20:27 +00:00
|
|
|
return (gethostbyname_internal(name, af, he, buffer, buflen, result,
|
|
|
|
h_errnop, statp));
|
2005-04-25 17:36:28 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
int
|
|
|
|
gethostbyname_internal(const char *name, int af, struct hostent *hp, char *buf,
|
|
|
|
size_t buflen, struct hostent **result, int *h_errnop, res_state statp)
|
1994-08-09 20:23:14 +00:00
|
|
|
{
|
2005-04-25 17:36:28 +00:00
|
|
|
const char *cp;
|
2010-08-13 06:39:54 +00:00
|
|
|
int rval, ret_errno = 0;
|
2005-04-25 17:36:28 +00:00
|
|
|
char abuf[MAXDNAME];
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info =
|
|
|
|
NS_COMMON_CACHE_INFO_INITIALIZER(
|
|
|
|
hosts, (void *)nss_lt_name,
|
|
|
|
host_id_func, host_marshal_func, host_unmarshal_func);
|
|
|
|
#endif
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
NS_FILES_CB(_ht_gethostbyname, NULL)
|
|
|
|
{ NSSRC_DNS, _dns_gethostbyname, NULL },
|
|
|
|
NS_NIS_CB(_nis_gethostbyname, NULL) /* force -DHESIOD */
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{ 0 }
|
2005-04-25 17:36:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
|
|
|
case AF_INET6:
|
|
|
|
break;
|
|
|
|
default:
|
2006-04-15 16:20:27 +00:00
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
*h_errnop = statp->res_h_errno;
|
2005-04-25 17:36:28 +00:00
|
|
|
errno = EAFNOSUPPORT;
|
2006-04-15 16:20:27 +00:00
|
|
|
return (-1);
|
2005-04-25 17:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if there aren't any dots, it could be a user-level alias.
|
|
|
|
* this is also done in res_query() since we are not the only
|
|
|
|
* function that looks up host names.
|
|
|
|
*/
|
|
|
|
if (!strchr(name, '.') &&
|
2006-04-15 16:20:27 +00:00
|
|
|
(cp = res_hostalias(statp, name, abuf, sizeof abuf)))
|
2005-04-25 17:36:28 +00:00
|
|
|
name = cp;
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
if (fakeaddr(name, af, hp, buf, buflen, statp) == 0) {
|
|
|
|
*result = hp;
|
|
|
|
return (0);
|
|
|
|
}
|
2005-04-25 17:36:28 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
rval = _nsdispatch((void *)result, dtab, NSDB_HOSTS,
|
|
|
|
"gethostbyname2_r", default_src, name, af, hp, buf, buflen,
|
|
|
|
&ret_errno, h_errnop);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2010-08-13 06:39:54 +00:00
|
|
|
if (rval != NS_SUCCESS) {
|
|
|
|
errno = ret_errno;
|
|
|
|
return ((ret_errno != 0) ? ret_errno : -1);
|
|
|
|
}
|
|
|
|
return (0);
|
1994-08-09 20:23:14 +00:00
|
|
|
}
|
|
|
|
|
2005-04-28 18:03:43 +00:00
|
|
|
int
|
2006-05-21 11:27:28 +00:00
|
|
|
gethostbyaddr_r(const void *addr, socklen_t len, int af, struct hostent *hp,
|
|
|
|
char *buf, size_t buflen, struct hostent **result, int *h_errnop)
|
1994-08-09 20:23:14 +00:00
|
|
|
{
|
2005-04-29 19:55:23 +00:00
|
|
|
const u_char *uaddr = (const u_char *)addr;
|
|
|
|
const struct in6_addr *addr6;
|
|
|
|
socklen_t size;
|
2010-08-13 06:39:54 +00:00
|
|
|
int rval, ret_errno = 0;
|
2006-04-15 16:20:27 +00:00
|
|
|
res_state statp;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info =
|
|
|
|
NS_COMMON_CACHE_INFO_INITIALIZER(
|
|
|
|
hosts, (void *)nss_lt_id,
|
|
|
|
host_id_func, host_marshal_func, host_unmarshal_func);
|
|
|
|
#endif
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
NS_FILES_CB(_ht_gethostbyaddr, NULL)
|
|
|
|
{ NSSRC_DNS, _dns_gethostbyaddr, NULL },
|
|
|
|
NS_NIS_CB(_nis_gethostbyaddr, NULL) /* force -DHESIOD */
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{ 0 }
|
2005-04-28 18:03:43 +00:00
|
|
|
};
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
statp = __res_state();
|
|
|
|
if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) {
|
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
*h_errnop = statp->res_h_errno;
|
|
|
|
return (-1);
|
2005-04-30 20:07:01 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
if (af == AF_INET6 && len == NS_IN6ADDRSZ) {
|
2006-05-12 15:37:23 +00:00
|
|
|
addr6 = (const struct in6_addr *)addr;
|
2005-04-29 19:55:23 +00:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(addr6)) {
|
2006-04-15 16:20:27 +00:00
|
|
|
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
|
|
|
|
*h_errnop = statp->res_h_errno;
|
|
|
|
return (-1);
|
2005-04-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(addr6) ||
|
|
|
|
IN6_IS_ADDR_V4COMPAT(addr6)) {
|
|
|
|
/* Unmap. */
|
2006-04-15 16:20:27 +00:00
|
|
|
uaddr += NS_IN6ADDRSZ - NS_INADDRSZ;
|
2005-04-29 19:55:23 +00:00
|
|
|
af = AF_INET;
|
2006-04-15 16:20:27 +00:00
|
|
|
len = NS_INADDRSZ;
|
2005-04-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
2006-04-15 16:20:27 +00:00
|
|
|
size = NS_INADDRSZ;
|
2005-04-29 19:55:23 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2006-04-15 16:20:27 +00:00
|
|
|
size = NS_IN6ADDRSZ;
|
2005-04-29 19:55:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EAFNOSUPPORT;
|
2006-04-15 16:20:27 +00:00
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
*h_errnop = statp->res_h_errno;
|
|
|
|
return (-1);
|
2005-04-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
if (size != len) {
|
|
|
|
errno = EINVAL;
|
2006-04-15 16:20:27 +00:00
|
|
|
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
|
|
|
|
*h_errnop = statp->res_h_errno;
|
|
|
|
return (-1);
|
2005-04-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
rval = _nsdispatch((void *)result, dtab, NSDB_HOSTS,
|
|
|
|
"gethostbyaddr_r", default_src, uaddr, len, af, hp, buf, buflen,
|
|
|
|
&ret_errno, h_errnop);
|
1994-09-25 02:12:49 +00:00
|
|
|
|
2010-08-13 06:39:54 +00:00
|
|
|
if (rval != NS_SUCCESS) {
|
|
|
|
errno = ret_errno;
|
|
|
|
return ((ret_errno != 0) ? ret_errno : -1);
|
|
|
|
}
|
|
|
|
return (0);
|
1994-09-25 02:12:49 +00:00
|
|
|
}
|
2005-04-28 18:03:43 +00:00
|
|
|
|
|
|
|
struct hostent *
|
|
|
|
gethostbyname(const char *name)
|
|
|
|
{
|
|
|
|
struct hostdata *hd;
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent *rval;
|
|
|
|
int ret_h_errno;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
|
|
|
if ((hd = __hostdata_init()) == NULL)
|
2006-04-15 16:20:27 +00:00
|
|
|
return (NULL);
|
|
|
|
if (gethostbyname_r(name, &hd->host, hd->data, sizeof(hd->data), &rval,
|
|
|
|
&ret_h_errno) != 0)
|
|
|
|
return (NULL);
|
|
|
|
return (rval);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hostent *
|
|
|
|
gethostbyname2(const char *name, int af)
|
|
|
|
{
|
|
|
|
struct hostdata *hd;
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent *rval;
|
|
|
|
int ret_h_errno;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
|
|
|
if ((hd = __hostdata_init()) == NULL)
|
2006-04-15 16:20:27 +00:00
|
|
|
return (NULL);
|
|
|
|
if (gethostbyname2_r(name, af, &hd->host, hd->data, sizeof(hd->data),
|
|
|
|
&rval, &ret_h_errno) != 0)
|
|
|
|
return (NULL);
|
|
|
|
return (rval);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hostent *
|
2006-05-12 15:37:23 +00:00
|
|
|
gethostbyaddr(const void *addr, socklen_t len, int af)
|
2005-04-28 18:03:43 +00:00
|
|
|
{
|
|
|
|
struct hostdata *hd;
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent *rval;
|
|
|
|
int ret_h_errno;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
|
|
|
if ((hd = __hostdata_init()) == NULL)
|
2006-04-15 16:20:27 +00:00
|
|
|
return (NULL);
|
|
|
|
if (gethostbyaddr_r(addr, len, af, &hd->host, hd->data,
|
|
|
|
sizeof(hd->data), &rval, &ret_h_errno) != 0)
|
|
|
|
return (NULL);
|
|
|
|
return (rval);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sethostent(int stayopen)
|
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent_data *hed;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
if ((hed = __hostent_data_init()) == NULL)
|
2005-04-28 18:03:43 +00:00
|
|
|
return;
|
2006-04-15 16:20:27 +00:00
|
|
|
_sethosthtent(stayopen, hed);
|
|
|
|
_sethostdnsent(stayopen);
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endhostent(void)
|
|
|
|
{
|
2006-04-15 16:20:27 +00:00
|
|
|
struct hostent_data *hed;
|
2005-04-28 18:03:43 +00:00
|
|
|
|
2006-04-15 16:20:27 +00:00
|
|
|
if ((hed = __hostent_data_init()) == NULL)
|
2005-04-28 18:03:43 +00:00
|
|
|
return;
|
2006-04-15 16:20:27 +00:00
|
|
|
_endhosthtent(hed);
|
|
|
|
_endhostdnsent();
|
2005-04-28 18:03:43 +00:00
|
|
|
}
|