PERFORCE change 124443 for review
Peter Wemm
peter at FreeBSD.org
Wed Aug 1 00:25:24 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124443
Change 124443 by peter at peter_daintree on 2007/08/01 00:25:11
IFC @124442
Affected files ...
.. //depot/projects/hammer/etc/rc.d/nscd#1 branch
.. //depot/projects/hammer/lib/libarchive/test/main.c#7 integrate
.. //depot/projects/hammer/lib/libc/net/name6.c#24 integrate
.. //depot/projects/hammer/release/doc/en_US.ISO8859-1/relnotes/article.sgml#14 integrate
.. //depot/projects/hammer/share/man/man4/lagg.4#2 integrate
.. //depot/projects/hammer/sys/arm/arm/trap.c#21 integrate
.. //depot/projects/hammer/sys/arm/at91/at91rm92reg.h#5 integrate
.. //depot/projects/hammer/sys/arm/at91/kb920x_machdep.c#8 integrate
.. //depot/projects/hammer/sys/arm/at91/ohci_atmelarm.c#3 integrate
.. //depot/projects/hammer/sys/arm/conf/KB920X#5 integrate
.. //depot/projects/hammer/sys/conf/kern.pre.mk#49 integrate
.. //depot/projects/hammer/sys/conf/options.ia64#13 integrate
.. //depot/projects/hammer/sys/dev/acpica/acpi_hpet.c#8 integrate
.. //depot/projects/hammer/sys/dev/acpica/acpi_timer.c#17 integrate
.. //depot/projects/hammer/sys/dev/aic7xxx/aic7xxx.c#21 integrate
.. //depot/projects/hammer/sys/dev/aic7xxx/aic_osm_lib.c#5 integrate
.. //depot/projects/hammer/sys/dev/arcmsr/arcmsr.c#13 integrate
.. //depot/projects/hammer/sys/dev/bce/if_bce.c#9 integrate
.. //depot/projects/hammer/sys/dev/bce/if_bcefw.h#4 integrate
.. //depot/projects/hammer/sys/dev/bce/if_bcereg.h#8 integrate
.. //depot/projects/hammer/sys/dev/usb/umodem.c#15 integrate
.. //depot/projects/hammer/sys/ia64/ia64/db_machdep.c#4 integrate
.. //depot/projects/hammer/sys/ia64/ia64/exception.S#10 integrate
.. //depot/projects/hammer/sys/ia64/ia64/interrupt.c#26 integrate
.. //depot/projects/hammer/sys/ia64/ia64/machdep.c#62 integrate
.. //depot/projects/hammer/sys/ia64/ia64/mp_machdep.c#19 integrate
.. //depot/projects/hammer/sys/ia64/ia64/nexus.c#13 integrate
.. //depot/projects/hammer/sys/ia64/ia64/pmap.c#60 integrate
.. //depot/projects/hammer/sys/ia64/ia64/sapic.c#7 integrate
.. //depot/projects/hammer/sys/ia64/include/atomic.h#5 integrate
.. //depot/projects/hammer/sys/ia64/include/intr.h#4 integrate
.. //depot/projects/hammer/sys/ia64/include/md_var.h#15 integrate
.. //depot/projects/hammer/sys/ia64/include/sapicvar.h#4 integrate
.. //depot/projects/hammer/sys/net/if_lagg.c#6 integrate
.. //depot/projects/hammer/sys/net/if_lagg.h#5 integrate
.. //depot/projects/hammer/sys/netinet/tcp_fsm.h#6 integrate
.. //depot/projects/hammer/sys/netinet/tcp_input.c#78 integrate
.. //depot/projects/hammer/sys/netinet/tcp_subr.c#71 integrate
.. //depot/projects/hammer/sys/netinet/tcp_syncache.c#47 integrate
.. //depot/projects/hammer/sys/netinet/tcp_timer.h#13 integrate
.. //depot/projects/hammer/sys/netinet/tcp_usrreq.c#48 integrate
.. //depot/projects/hammer/sys/netipx/spx_debug.c#6 integrate
.. //depot/projects/hammer/sys/netipx/spx_debug.h#5 integrate
.. //depot/projects/hammer/sys/pc98/cbus/clock.c#11 integrate
.. //depot/projects/hammer/sys/powerpc/powerpc/trap.c#23 integrate
.. //depot/projects/hammer/usr.bin/netstat/ipx.c#7 integrate
.. //depot/projects/hammer/usr.sbin/nscd/Makefile#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agent.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agent.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/Makefile.inc#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/group.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/group.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/passwd.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/passwd.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/services.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/agents/services.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/cachelib.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/cachelib.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/cacheplcs.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/cacheplcs.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/config.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/config.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/debug.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/debug.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/hashtable.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/log.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/log.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/mp_rs_query.#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/mp_rs_query.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/mp_ws_query.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/mp_ws_query.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/nscd.8#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/nscd.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/nscd.conf.5#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/nscdcli.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/nscdcli.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/parser.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/parser.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/protocol.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/protocol.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/query.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/query.h#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/singletons.c#1 branch
.. //depot/projects/hammer/usr.sbin/nscd/singletons.h#1 branch
Differences ...
==== //depot/projects/hammer/lib/libarchive/test/main.c#7 (text+ko) ====
@@ -32,7 +32,13 @@
#include <time.h>
#include "test.h"
-__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.7 2007/07/14 17:52:01 kientzle Exp $");
+__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.8 2007/07/31 05:03:27 kientzle Exp $");
+
+/* Interix doesn't define these in a standard header. */
+#if __INTERIX__
+extern char *optarg;
+extern int optind;
+#endif
/* Default is to crash and try to force a core dump on failure. */
static int dump_on_failure = 1;
@@ -101,6 +107,7 @@
static int skipped_line;
void skipping_setup(const char *filename, int line)
{
+ skipped_filename = filename;
skipped_line = line;
}
void
==== //depot/projects/hammer/lib/libc/net/name6.c#24 (text+ko) ====
@@ -88,7 +88,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/name6.c,v 1.61 2006/07/26 08:35:46 yar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/net/name6.c,v 1.62 2007/07/31 16:09:41 bushman Exp $");
#include "namespace.h"
#include <sys/param.h>
@@ -118,16 +118,8 @@
#include <unistd.h>
#include "un-namespace.h"
#include "netdb_private.h"
-#include "res_config.h"
#include "res_private.h"
-#ifdef NS_CACHING
-#include "nscache.h"
-#endif
-#ifndef _PATH_HOSTS
-#define _PATH_HOSTS "/etc/hosts"
-#endif
-
#ifndef MAXALIASES
#define MAXALIASES 10
#endif
@@ -153,7 +145,7 @@
} while (0)
#define MAPADDRENABLED(flags) \
(((flags) & AI_V4MAPPED) || \
- (((flags) & AI_V4MAPPED_CFG) && _mapped_addr_enabled()))
+ (((flags) & AI_V4MAPPED_CFG)))
union inx_addr {
struct in_addr in_addr;
@@ -202,14 +194,11 @@
static struct hostent *_hpcopy(struct hostent *, int *);
static struct hostent *_hpaddr(int, const char *, void *, int *);
+#ifdef INET6
static struct hostent *_hpmerge(struct hostent *, struct hostent *, int *);
-#ifdef INET6
static struct hostent *_hpmapv6(struct hostent *, int *);
#endif
static struct hostent *_hpsort(struct hostent *, res_state);
-static struct hostent *_ghbyname(const char *, int, int, int *);
-static char *_hgetword(char **);
-static int _mapped_addr_enabled(void);
static struct hostent *_hpreorder(struct hostent *);
static int get_addrselectpolicy(struct policyhead *);
@@ -221,325 +210,30 @@
static int comp_dst(const void *, const void *);
static int gai_addr2scopetype(struct sockaddr *);
-static FILE *_files_open(int *);
-static int _files_ghbyname(void *, void *, va_list);
-static int _files_ghbyaddr(void *, void *, va_list);
-#ifdef YP
-static int _nis_ghbyname(void *, void *, va_list);
-static int _nis_ghbyaddr(void *, void *, va_list);
-#endif
-static int _dns_ghbyname(void *, void *, va_list);
-static int _dns_ghbyaddr(void *, void *, va_list);
-static void _dns_shent(int) __unused;
-static void _dns_ehent(void) __unused;
-#ifdef ICMPNL
-static int _icmp_ghbyaddr(void *, void *, va_list);
-#endif /* ICMPNL */
-#ifdef NS_CACHING
-static int ipnode_id_func(char *, size_t *, va_list, void *);
-static int ipnode_marshal_func(char *, size_t *, void *, va_list, void *);
-static int ipnode_unmarshal_func(char *, size_t, void *, va_list, void *);
-#endif
-
-/* Host lookup order if nsswitch.conf is broken or nonexistant */
-static const ns_src default_src[] = {
- { NSSRC_FILES, NS_SUCCESS },
- { NSSRC_DNS, NS_SUCCESS },
-#ifdef ICMPNL
-#define NSSRC_ICMP "icmp"
- { NSSRC_ICMP, NS_SUCCESS },
-#endif
- { 0 }
-};
-
/*
- * Check if kernel supports mapped address.
- * implementation dependent
+ * Functions defined in RFC2553
+ * getipnodebyname, getipnodebyaddr, freehostent
*/
-#ifdef __KAME__
-#include <sys/sysctl.h>
-#endif /* __KAME__ */
-static int
-_mapped_addr_enabled(void)
+struct hostent *
+getipnodebyname(const char *name, int af, int flags, int *errp)
{
- /* implementation dependent check */
-#if defined(__KAME__) && defined(IPV6CTL_MAPPED_ADDR)
- int mib[4];
- size_t len;
- int val;
-
- mib[0] = CTL_NET;
- mib[1] = PF_INET6;
- mib[2] = IPPROTO_IPV6;
- mib[3] = IPV6CTL_MAPPED_ADDR;
- len = sizeof(val);
- if (sysctl(mib, 4, &val, &len, 0, 0) == 0 && val != 0)
- return 1;
-#endif /* __KAME__ && IPV6CTL_MAPPED_ADDR */
- return 0;
-}
-
-#ifdef NS_CACHING
-static int
-ipnode_id_func(char *buffer, size_t *buffer_size, va_list ap,
- void *cache_mdata)
-{
+ struct hostent *hp;
+ union inx_addr addrbuf;
res_state statp;
- u_long res_options;
+ u_long options;
- const int op_id = 2;
- char *name;
- int af;
- size_t len;
- void *src;
-
- char *p;
- size_t desired_size, size;
- enum nss_lookup_type lookup_type;
- int res = NS_UNAVAIL;
-
- statp = __res_state();
- res_options = statp->options & (RES_RECURSE | RES_DEFNAMES |
- RES_DNSRCH | RES_NOALIASES | RES_USE_INET6);
-
- lookup_type = (enum nss_lookup_type)cache_mdata;
- switch (lookup_type) {
- case nss_lt_name:
- name = va_arg(ap, char *);
- af = va_arg(ap, int);
-
- size = strlen(name);
- 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(enum nss_lookup_type);
-
- memcpy(p, &af, sizeof(int));
- p += sizeof(int);
-
- memcpy(p, name, size + 1);
-
- res = NS_SUCCESS;
+ switch (af) {
+ case AF_INET:
+#ifdef INET6
+ case AF_INET6:
+#endif
break;
- case nss_lt_id:
- src = va_arg(ap, void *);
- len = va_arg(ap, size_t);
- af = va_arg(ap, int);
-
- desired_size = sizeof(res_options) + sizeof(int) +
- sizeof(enum nss_lookup_type) + sizeof(int) +
- sizeof(size_t) + len;
-
- 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(enum nss_lookup_type);
-
- memcpy(p, &af, sizeof(int));
- p += sizeof(int);
-
- memcpy(p, &len, sizeof(size_t));
- p += sizeof(size_t);
-
- memcpy(p, src, len);
-
- res = NS_SUCCESS;
- break;
default:
- /* should be unreachable */
- return (NS_UNAVAIL);
- }
-
-fin:
- *buffer_size = desired_size;
- return (res);
-}
-
-static int
-ipnode_marshal_func(char *buffer, size_t *buffer_size, void *retval,
- va_list ap, void *cache_mdata)
-{
- struct hostent *ht;
-
- struct hostent new_ht;
- size_t desired_size, aliases_size, addr_size, size;
- char *p, **iter;
-
- ht = *((struct hostent **)retval);
-
- 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;
- }
+ *errp = NO_RECOVERY;
+ return NULL;
}
- memcpy(buffer, &new_ht, sizeof(struct hostent));
- return (NS_SUCCESS);
-}
-static int
-ipnode_unmarshal_func(char *buffer, size_t buffer_size, void *retval,
- va_list ap, void *cache_mdata)
-{
- struct hostent new_ht;
- struct hostent *ht;
-
- char *p;
- char **iter;
- char *orig_buf;
- int err;
-
- ht = &new_ht;
-
- memcpy(ht, buffer, sizeof(struct hostent));
- memcpy(&p, buffer + sizeof(struct hostent), sizeof(char *));
-
- orig_buf = buffer + 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 *);
- }
-
- ht = _hpcopy(ht, &err);
- if (ht == NULL)
- return (NS_UNAVAIL);
-
- *((struct hostent **)retval) = ht;
- return (NS_SUCCESS);
-}
-#endif
-
-/*
- * Functions defined in RFC2553
- * getipnodebyname, getipnodebyaddr, freehostent
- */
-
-static struct hostent *
-_ghbyname(const char *name, int af, int flags, int *errp)
-{
- struct hostent *hp;
- int rval;
-
-#ifdef NS_CACHING
- static const nss_cache_info cache_info =
- NS_COMMON_CACHE_INFO_INITIALIZER(
- hosts, (void *)nss_lt_name,
- ipnode_id_func, ipnode_marshal_func, ipnode_unmarshal_func);
-#endif
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_files_ghbyname, NULL)
- { NSSRC_DNS, _dns_ghbyname, NULL },
- NS_NIS_CB(_nis_ghbyname, NULL)
-#ifdef NS_CACHING
- NS_CACHE_CB(&cache_info)
-#endif
- { 0 }
- };
-
if (flags & AI_ADDRCONFIG) {
int s;
@@ -554,31 +248,8 @@
*/
_close(s);
}
-
- rval = _nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyname", default_src,
- name, af, errp);
- return (rval == NS_SUCCESS) ? hp : NULL;
-}
-
-struct hostent *
-getipnodebyname(const char *name, int af, int flags, int *errp)
-{
- struct hostent *hp;
- union inx_addr addrbuf;
- res_state statp;
-
- switch (af) {
- case AF_INET:
+
#ifdef INET6
- case AF_INET6:
-#endif
- break;
- default:
- *errp = NO_RECOVERY;
- return NULL;
- }
-
-#ifdef INET6
/* special case for literal address */
if (inet_pton(AF_INET6, name, &addrbuf) == 1) {
if (af != AF_INET6) {
@@ -600,6 +271,7 @@
return _hpaddr(af, name, &addrbuf, errp);
}
+
statp = __res_state();
if ((statp->options & RES_INIT) == 0) {
if (res_ninit(statp) < 0) {
@@ -607,25 +279,36 @@
return NULL;
}
}
+
+ options = statp->options;
+ statp->options &= ~RES_USE_INET6;
+
+ hp = gethostbyname2(name, af);
+ hp = _hpcopy(hp, errp);
- *errp = HOST_NOT_FOUND;
- hp = _ghbyname(name, af, flags, errp);
-
#ifdef INET6
if (af == AF_INET6 && ((flags & AI_ALL) || hp == NULL) &&
MAPADDRENABLED(flags)) {
- struct hostent *hp2 = _ghbyname(name, AF_INET, flags, errp);
+ struct hostent *hp2 = gethostbyname2(name, AF_INET);
if (hp == NULL)
- hp = _hpmapv6(hp2, errp);
+ if (hp2 == NULL)
+ *errp = statp->res_h_errno;
+ else
+ hp = _hpmapv6(hp2, errp);
else {
- if (hp2 && strcmp(hp->h_name, hp2->h_name) != 0) {
- freehostent(hp2);
- hp2 = NULL;
+ if (hp2 && strcmp(hp->h_name, hp2->h_name) == 0) {
+ struct hostent *hpb = hp;
+ hp = _hpmerge(hpb, hp2, errp);
+ freehostent(hpb);
}
- hp = _hpmerge(hp, hp2, errp);
}
}
#endif
+
+ if (hp == NULL)
+ *errp = statp->res_h_errno;
+
+ statp->options = options;
return _hpreorder(_hpsort(hp, statp));
}
@@ -633,34 +316,15 @@
getipnodebyaddr(const void *src, size_t len, int af, int *errp)
{
struct hostent *hp;
- int rval;
+ res_state statp;
+ u_long options;
+
#ifdef INET6
struct in6_addr addrbuf;
#else
struct in_addr addrbuf;
#endif
-
-#ifdef NS_CACHING
- static const nss_cache_info cache_info =
- NS_COMMON_CACHE_INFO_INITIALIZER(
- hosts, (void *)nss_lt_id,
- ipnode_id_func, ipnode_marshal_func, ipnode_unmarshal_func);
-#endif
- static const ns_dtab dtab[] = {
- NS_FILES_CB(_files_ghbyaddr, NULL)
- { NSSRC_DNS, _dns_ghbyaddr, NULL },
- NS_NIS_CB(_nis_ghbyaddr, NULL)
-#ifdef ICMPNL
- { NSSRC_ICMP, _icmp_ghbyaddr, NULL },
-#endif
-#ifdef NS_CACHING
- NS_CACHE_CB(&cache_info)
-#endif
- { 0 }
- };
-
- *errp = HOST_NOT_FOUND;
-
+
switch (af) {
case AF_INET:
if (len != sizeof(struct in_addr)) {
@@ -700,9 +364,23 @@
return NULL;
}
- rval = _nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyaddr", default_src,
- src, len, af, errp);
- return (rval == NS_SUCCESS) ? hp : NULL;
+ statp = __res_state();
+ if ((statp->options & RES_INIT) == 0) {
+ if (res_ninit(statp) < 0) {
+ RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
+ return NULL;
+ }
+ }
+
+ options = statp->options;
+ statp->options &= ~RES_USE_INET6;
+
+ hp = gethostbyaddr(src, len, af);
+ if (hp == NULL)
+ *errp = statp->res_h_errno;
+
+ statp->options = options;
+ return (_hpcopy(hp, errp));
}
void
@@ -811,9 +489,10 @@
hp->h_addr_list = addrs;
addrs[0] = (char *)addr;
addrs[1] = NULL;
- return _hpcopy(hp, errp);
+ return (_hpcopy(hp, errp));
}
+#ifdef INET6
/*
* _hpmerge: merge 2 hostent structure, arguments will be freed
*/
@@ -828,9 +507,9 @@
union inx_addr addrbuf[MAXADDRS];
if (hp1 == NULL)
- return hp2;
+ return _hpcopy(hp2, errp);
if (hp2 == NULL)
- return hp1;
+ return _hpcopy(hp1, errp);
#define HP(i) (i == 1 ? hp1 : hp2)
hp = &hpbuf;
@@ -850,17 +529,14 @@
}
}
aliases[nalias] = NULL;
-#ifdef INET6
if (hp1->h_length != hp2->h_length) {
hp->h_addrtype = AF_INET6;
hp->h_length = sizeof(struct in6_addr);
} else {
-#endif
hp->h_addrtype = hp1->h_addrtype;
hp->h_length = hp1->h_length;
-#ifdef INET6
}
-#endif
+
hp->h_addr_list = addrs;
naddr = 0;
for (i = 1; i <= 2; i++) {
@@ -879,11 +555,9 @@
}
}
addrs[naddr] = NULL;
- hp = _hpcopy(hp, errp);
- freehostent(hp1);
- freehostent(hp2);
- return hp;
+ return (_hpcopy(hp, errp));
}
+#endif
/*
* _hpmapv6: convert IPv4 hostent into IPv4-mapped IPv6 addresses
@@ -892,24 +566,17 @@
static struct hostent *
_hpmapv6(struct hostent *hp, int *errp)
{
- struct hostent *hp6;
+ struct hostent hp6;
if (hp == NULL)
return NULL;
if (hp->h_addrtype == AF_INET6)
- return hp;
+ return _hpcopy(hp, errp);
- /* make dummy hostent to convert IPv6 address */
- if ((hp6 = (struct hostent *)malloc(sizeof(struct hostent))) == NULL) {
- *errp = TRY_AGAIN;
- return NULL;
- }
- hp6->h_name = NULL;
- hp6->h_aliases = NULL;
- hp6->h_addrtype = AF_INET6;
- hp6->h_length = sizeof(struct in6_addr);
- hp6->h_addr_list = NULL;
- return _hpmerge(hp6, hp, errp);
+ memset(&hp6, 0, sizeof(struct hostent));
+ hp6.h_addrtype = AF_INET6;
+ hp6.h_length = sizeof(struct in6_addr);
+ return _hpmerge(&hp6, hp, errp);
}
#endif
@@ -965,37 +632,6 @@
return hp;
}
-static char *
-_hgetword(char **pp)
-{
- char c, *p, *ret;
- const char *sp;
- static const char sep[] = "# \t\n";
-
- ret = NULL;
- for (p = *pp; (c = *p) != '\0'; p++) {
- for (sp = sep; *sp != '\0'; sp++) {
- if (c == *sp)
- break;
- }
- if (c == '#')
- p[1] = '\0'; /* ignore rest of line */
- if (ret == NULL) {
- if (*sp == '\0')
- ret = p;
- } else {
- if (*sp != '\0') {
- *p++ = '\0';
- break;
- }
- }
- }
- *pp = p;
- if (ret == NULL || *ret == '\0')
- return NULL;
- return ret;
-}
-
/*
* _hpreorder: sort address by default address selection
*/
@@ -1475,954 +1111,3 @@
return(-1);
}
}
-
-/*
- * FILES (/etc/hosts)
- */
-
-static FILE *
-_files_open(int *errp)
-{
- FILE *fp;
- fp = fopen(_PATH_HOSTS, "r");
- if (fp == NULL)
- *errp = NO_RECOVERY;
- return fp;
-}
-
-static int
-_files_ghbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- int *errp;
- int match, nalias;
- char *p, *line, *addrstr, *cname;
- FILE *fp;
- struct hostent *rethp, *hp, hpbuf;
- char *aliases[MAXALIASES + 1], *addrs[2];
- union inx_addr addrbuf;
- char buf[BUFSIZ];
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- *(struct hostent **)rval = NULL;
-
- if ((fp = _files_open(errp)) == NULL)
- return NS_UNAVAIL;
- rethp = hp = NULL;
-
- while (fgets(buf, sizeof(buf), fp)) {
- line = buf;
- if ((addrstr = _hgetword(&line)) == NULL
- || (cname = _hgetword(&line)) == NULL)
- continue;
- match = (strcasecmp(cname, name) == 0);
- nalias = 0;
- while ((p = _hgetword(&line)) != NULL) {
- if (!match)
- match = (strcasecmp(p, name) == 0);
- if (nalias < MAXALIASES)
- aliases[nalias++] = p;
- }
- if (!match)
- continue;
- switch (af) {
- case AF_INET:
- if (inet_aton(addrstr, (struct in_addr *)&addrbuf)
- != 1) {
- *errp = NO_DATA; /* name found */
- continue;
- }
- break;
-#ifdef INET6
- case AF_INET6:
- if (inet_pton(af, addrstr, &addrbuf) != 1) {
- *errp = NO_DATA; /* name found */
- continue;
- }
- break;
-#endif
- }
- hp = &hpbuf;
- hp->h_name = cname;
- hp->h_aliases = aliases;
- aliases[nalias] = NULL;
- hp->h_addrtype = af;
- hp->h_length = ADDRLEN(af);
- hp->h_addr_list = addrs;
- addrs[0] = (char *)&addrbuf;
- addrs[1] = NULL;
- hp = _hpcopy(hp, errp);
- rethp = _hpmerge(rethp, hp, errp);
- }
- fclose(fp);
- *(struct hostent **)rval = rethp;
- return (rethp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-static int
-_files_ghbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const void *addr;
- int addrlen;
- int af;
- int *errp;
- int nalias;
- char *p, *line;
- FILE *fp;
- struct hostent *hp, hpbuf;
- char *aliases[MAXALIASES + 1], *addrs[2];
- union inx_addr addrbuf;
- char buf[BUFSIZ];
-
- addr = va_arg(ap, const void *);
- addrlen = va_arg(ap, int);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- *(struct hostent**)rval = NULL;
-
- if ((fp = _files_open(errp)) == NULL)
- return NS_UNAVAIL;
- hp = NULL;
- while (fgets(buf, sizeof(buf), fp)) {
- line = buf;
- if ((p = _hgetword(&line)) == NULL
- || (af == AF_INET
- ? inet_aton(p, (struct in_addr *)&addrbuf)
- : inet_pton(af, p, &addrbuf)) != 1
- || memcmp(addr, &addrbuf, addrlen) != 0
- || (p = _hgetword(&line)) == NULL)
- continue;
- hp = &hpbuf;
- hp->h_name = p;
- hp->h_aliases = aliases;
- nalias = 0;
- while ((p = _hgetword(&line)) != NULL) {
- if (nalias < MAXALIASES)
- aliases[nalias++] = p;
- }
- aliases[nalias] = NULL;
- hp->h_addrtype = af;
- hp->h_length = addrlen;
- hp->h_addr_list = addrs;
- addrs[0] = (char *)&addrbuf;
- addrs[1] = NULL;
- hp = _hpcopy(hp, errp);
- break;
- }
- fclose(fp);
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-#ifdef YP
-/*
- * NIS
- *
- * XXX actually a hack.
- */
-static int
-_nis_ghbyname(void *rval, void *cb_data, va_list ap)
-{
- const char *name;
- int af;
- int *errp;
- struct hostent *hp = NULL;
-
- name = va_arg(ap, const char *);
- af = va_arg(ap, int);
- errp = va_arg(ap, int *);
-
- hp = _gethostbynisname(name, af);
- if (hp != NULL)
- hp = _hpcopy(hp, errp);
-
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-
-static int
-_nis_ghbyaddr(void *rval, void *cb_data, va_list ap)
-{
- const void *addr;
- int addrlen;
- int af;
- int *errp;
- struct hostent *hp = NULL;
-
- addr = va_arg(ap, const void *);
- addrlen = va_arg(ap, int);
- af = va_arg(ap, int);
-
- hp = _gethostbynisaddr(addr, addrlen, af);
- if (hp != NULL)
- hp = _hpcopy(hp, errp);
- *(struct hostent **)rval = hp;
- return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND;
-}
-#endif
-
-#define MAXPACKET (64*1024)
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-static struct hostent *getanswer(const querybuf *, int, const char *, int,
- struct hostent *, int *);
-
-/*
- * we don't need to take care about sorting, nor IPv4 mapped address here.
- */
-static struct hostent *
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list