[Midnightbsd-cvs] src: libc/net: Merge changes.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu Oct 30 17:04:15 EDT 2008


Log Message:
-----------
Merge changes.

Modified Files:
--------------
    src/lib/libc/net:
        getaddrinfo.c (r1.2 -> r1.3)
        inet_net.3 (r1.2 -> r1.3)

Removed Files:
-------------
    src/lib/libc/net:
        addr2ascii.3
        addr2ascii.c
        ascii2addr.c
        getservbyname.c
        getservbyport.c
        herror.c
        inet_addr.c
        inet_lnaof.c
        inet_makeaddr.c
        inet_net_ntop.c
        inet_net_pton.c
        inet_neta.c
        inet_netof.c
        inet_network.c
        inet_ntoa.c
        inet_ntop.c
        inet_pton.c
        ns_name.c
        ns_netint.c
        ns_parse.c
        ns_print.c
        ns_ttl.c
        nsap_addr.c
        res_comp.c
        res_data.c
        res_debug.c
        res_init.c
        res_mkquery.c
        res_mkupdate.c
        res_query.c
        res_send.c
        res_send_private.h
        res_update.c

-------------- next part --------------
--- lib/libc/net/res_debug.c
+++ /dev/null
@@ -1,992 +0,0 @@
-/*
- * Copyright (c) 1985
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_debug.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_debug.c,v 1.21 2003/02/18 13:39:52 nectar Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#define SPRINTF(x) sprintf x
-
-extern const char *_res_opcodes[];
-extern const char *_res_resultcodes[];
-extern const char *_res_sectioncodes[];
-
-/*
- * Print the current options.
- */
-void
-fp_resstat(struct __res_state *statp, FILE *file) {
-	u_long mask;
-
-	fprintf(file, ";; res options:");
-	if (!statp)
-		statp = &_res;
-	for (mask = 1;  mask != 0;  mask <<= 1)
-		if (statp->options & mask)
-			fprintf(file, " %s", p_option(mask));
-	putc('\n', file);
-}
-
-static void
-do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
-	int n, sflag, rrnum;
-	char buf[2048];	/* XXX need to malloc */
-	ns_opcode opcode;
-	ns_rr rr;
-
-	/*
-	 * Print answer records.
-	 */
-	sflag = (_res.pfcode & pflag);
-	if (_res.pfcode && !sflag)
-		return;
-
-	opcode = ns_msg_getflag(*handle, ns_f_opcode);
-	rrnum = 0;
-	for (;;) {
-		if (ns_parserr(handle, section, rrnum, &rr)) {
-			if (errno != ENODEV)
-				fprintf(file, ";; ns_parserr: %s\n",
-					strerror(errno));
-			else if (rrnum > 0 && sflag != 0 &&
-				 (_res.pfcode & RES_PRF_HEAD1))
-				putc('\n', file);
-			return;
-		}
-		if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
-			fprintf(file, ";; %s SECTION:\n",
-				p_section(section, opcode));
-		if (section == ns_s_qd)
-			fprintf(file, ";;\t%s, type = %s, class = %s\n",
-				ns_rr_name(rr),
-				p_type(ns_rr_type(rr)),
-				p_class(ns_rr_class(rr)));
-		else {
-			n = ns_sprintrr(handle, &rr, NULL, NULL,
-					buf, sizeof buf);
-			if (n < 0) {
-				fprintf(file, ";; ns_sprintrr: %s\n",
-					strerror(errno));
-				return;
-			}
-			fputs(buf, file);
-			fputc('\n', file);
-		}
-		rrnum++;
-	}
-}
-
-void
-p_query(const u_char *msg) {
-	fp_query(msg, stdout);
-}
-
-void
-fp_query(const u_char *msg, FILE *file) {
-	fp_nquery(msg, PACKETSZ, file);
-}
-
-/*
- * Print the contents of a query.
- * This is intended to be primarily a debugging routine.
- */
-void
-fp_nquery(const u_char *msg, int len, FILE *file) {
-	ns_msg handle;
-	int qdcount, ancount, nscount, arcount;
-	u_int opcode, rcode, id;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1)
-		return;
-
-	if (ns_initparse(msg, len, &handle) < 0) {
-		fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
-		return;
-	}
-	opcode = ns_msg_getflag(handle, ns_f_opcode);
-	rcode = ns_msg_getflag(handle, ns_f_rcode);
-	id = ns_msg_id(handle);
-	qdcount = ns_msg_count(handle, ns_s_qd);
-	ancount = ns_msg_count(handle, ns_s_an);
-	nscount = ns_msg_count(handle, ns_s_ns);
-	arcount = ns_msg_count(handle, ns_s_ar);
-
-	/*
-	 * Print header fields.
-	 */
-	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
-		fprintf(file,
-			";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
-			_res_opcodes[opcode], _res_resultcodes[rcode], id);
-	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
-		putc(';', file);
-	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
-		fprintf(file, "; flags:");
-		if (ns_msg_getflag(handle, ns_f_qr))
-			fprintf(file, " qr");
-		if (ns_msg_getflag(handle, ns_f_aa))
-			fprintf(file, " aa");
-		if (ns_msg_getflag(handle, ns_f_tc))
-			fprintf(file, " tc");
-		if (ns_msg_getflag(handle, ns_f_rd))
-			fprintf(file, " rd");
-		if (ns_msg_getflag(handle, ns_f_ra))
-			fprintf(file, " ra");
-		if (ns_msg_getflag(handle, ns_f_z))
-			fprintf(file, " ??");
-		if (ns_msg_getflag(handle, ns_f_ad))
-			fprintf(file, " ad");
-		if (ns_msg_getflag(handle, ns_f_cd))
-			fprintf(file, " cd");
-	}
-	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
-		fprintf(file, "; %s: %d",
-			p_section(ns_s_qd, opcode), qdcount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_an, opcode), ancount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_ns, opcode), nscount);
-		fprintf(file, ", %s: %d",
-			p_section(ns_s_ar, opcode), arcount);
-	}
-	if ((!_res.pfcode) || (_res.pfcode & 
-		(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
-		putc('\n',file);
-	}
-	/*
-	 * Print the various sections.
-	 */
-	do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
-	do_section(&handle, ns_s_an, RES_PRF_ANS, file);
-	do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
-	do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
-	if (qdcount == 0 && ancount == 0 &&
-	    nscount == 0 && arcount == 0)
-		putc('\n', file);
-}
-
-const u_char *
-p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
-	char name[MAXDNAME];
-	int n;
-
-	if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
-		return (NULL);
-	if (name[0] == '\0')
-		putc('.', file);
-	else
-		fputs(name, file);
-	return (cp + n);
-}
-
-const u_char *
-p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
-	return (p_cdnname(cp, msg, PACKETSZ, file));
-}
-
-/* Return a fully-qualified domain name from a compressed name (with
-   length supplied).  */
-
-const u_char *
-p_fqnname(cp, msg, msglen, name, namelen)
-	const u_char *cp, *msg;
-	int msglen;
-	char *name;
-	int namelen;
-{
-	int n, newlen;
-
-	if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
-		return (NULL);
-	newlen = strlen(name);
-	if (newlen == 0 || name[newlen - 1] != '.') {
-		if (newlen + 1 >= namelen)	/* Lack space for final dot */
-			return (NULL);
-		else
-			strcpy(name + newlen, ".");
-	}
-	return (cp + n);
-}
-
-/* XXX:	the rest of these functions need to become length-limited, too. */
-
-const u_char *
-p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
-	char name[MAXDNAME];
-	const u_char *n;
-
-	n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
-	if (n == NULL)
-		return (NULL);
-	fputs(name, file);
-	return (n);
-}
-
-/*
- * Names of RR classes and qclasses.  Classes and qclasses are the same, except
- * that C_ANY is a qclass but not a class.  (You can ask for records of class
- * C_ANY, but you can't have any records of that class in the database.)
- */
-const struct res_sym __p_class_syms[] = {
-	{C_IN,		"IN"},
-	{C_CHAOS,	"CHAOS"},
-	{C_HS,		"HS"},
-	{C_HS,		"HESIOD"},
-	{C_ANY,		"ANY"},
-	{C_NONE,	"NONE"},
-	{C_IN, 		(char *)0}
-};
-
-/*
- * Names of message sections.
- */
-const struct res_sym __p_default_section_syms[] = {
-	{ns_s_qd,	"QUERY"},
-	{ns_s_an,	"ANSWER"},
-	{ns_s_ns,	"AUTHORITY"},
-	{ns_s_ar,	"ADDITIONAL"},
-	{0,             (char *)0}
-};
-
-const struct res_sym __p_update_section_syms[] = {
-	{S_ZONE,	"ZONE"},
-	{S_PREREQ,	"PREREQUISITE"},
-	{S_UPDATE,	"UPDATE"},
-	{S_ADDT,	"ADDITIONAL"},
-	{0,             (char *)0}
-};
-
-/*
- * Names of RR types and qtypes.  Types and qtypes are the same, except
- * that T_ANY is a qtype but not a type.  (You can ask for records of type
- * T_ANY, but you can't have any records of that type in the database.)
- */
-const struct res_sym __p_type_syms[] = {
-	{T_A,		"A",		"address"},
-	{T_NS,		"NS",		"name server"},
-	{T_MD,		"MD",		"mail destination (deprecated)"},
-	{T_MF,		"MF",		"mail forwarder (deprecated)"},
-	{T_CNAME,	"CNAME",	"canonical name"},
-	{T_SOA,		"SOA",		"start of authority"},
-	{T_MB,		"MB",		"mailbox"},
-	{T_MG,		"MG",		"mail group member"},
-	{T_MR,		"MR",		"mail rename"},
-	{T_NULL,	"NULL",		"null"},
-	{T_WKS,		"WKS",		"well-known service (deprecated)"},
-	{T_PTR,		"PTR",		"domain name pointer"},
-	{T_HINFO,	"HINFO",	"host information"},
-	{T_MINFO,	"MINFO",	"mailbox information"},
-	{T_MX,		"MX",		"mail exchanger"},
-	{T_TXT,		"TXT",		"text"},
-	{T_RP,		"RP",		"responsible person"},
-	{T_AFSDB,	"AFSDB",	"DCE or AFS server"},
-	{T_X25,		"X25",		"X25 address"},
-	{T_ISDN,	"ISDN",		"ISDN address"},
-	{T_RT,		"RT",		"router"},
-	{T_NSAP,	"NSAP",		"nsap address"},
-	{T_NSAP_PTR,	"NSAP_PTR",	"domain name pointer"},
-	{T_SIG,		"SIG",		"signature"},
-	{T_KEY,		"KEY",		"key"},
-	{T_PX,		"PX",		"mapping information"},
-	{T_GPOS,	"GPOS",		"geographical position (withdrawn)"},
-	{T_AAAA,	"AAAA",		"IPv6 address"},
-	{T_LOC,		"LOC",		"location"},
-	{T_NXT,		"NXT",		"next valid name (unimplemented)"},
-	{T_EID,		"EID",		"endpoint identifier (unimplemented)"},
-	{T_NIMLOC,	"NIMLOC",	"NIMROD locator (unimplemented)"},
-	{T_SRV,		"SRV",		"server selection"},
-	{T_ATMA,	"ATMA",		"ATM address (unimplemented)"},
-	{T_IXFR,	"IXFR",		"incremental zone transfer"},
-	{T_AXFR,	"AXFR",		"zone transfer"},
-	{T_MAILB,	"MAILB",	"mailbox-related data (deprecated)"},
-	{T_MAILA,	"MAILA",	"mail agent (deprecated)"},
-	{T_NAPTR,	"NAPTR",	"URN Naming Authority"},
-	{T_ANY,		"ANY",		"\"any\""},
-	{0, 		NULL,		NULL}
-};
-
-int
-sym_ston(const struct res_sym *syms, const char *name, int *success) {
-	for ((void)NULL; syms->name != 0; syms++) {
-		if (strcasecmp (name, syms->name) == 0) {
-			if (success)
-				*success = 1;
-			return (syms->number);
-		}
-	}
-	if (success)
-		*success = 0;
-	return (syms->number);		/* The default value. */
-}
-
-const char *
-sym_ntos(const struct res_sym *syms, int number, int *success) {
-	static char unname[20];
-
-	for ((void)NULL; syms->name != 0; syms++) {
-		if (number == syms->number) {
-			if (success)
-				*success = 1;
-			return (syms->name);
-		}
-	}
-
-	sprintf(unname, "%d", number);
-	if (success)
-		*success = 0;
-	return (unname);
-}
-
-const char *
-sym_ntop(const struct res_sym *syms, int number, int *success) {
-	static char unname[20];
-
-	for ((void)NULL; syms->name != 0; syms++) {
-		if (number == syms->number) {
-			if (success)
-				*success = 1;
-			return (syms->humanname);
-		}
-	}
-	sprintf(unname, "%d", number);
-	if (success)
-		*success = 0;
-	return (unname);
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_type(int type) {
-	return (sym_ntos(__p_type_syms, type, (int *)0));
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_section(int section, int opcode) {
-	const struct res_sym *symbols;
-
-	switch (opcode) {
-	case ns_o_update:
-		symbols = __p_update_section_syms;
-		break;
-	default:
-		symbols = __p_default_section_syms;
-		break;
-	}
-	return (sym_ntos(symbols, section, (int *)0));
-}
-
-/*
- * Return a mnemonic for class.
- */
-const char *
-p_class(int class) {
-	return (sym_ntos(__p_class_syms, class, (int *)0));
-}
-
-/*
- * Return a mnemonic for an option
- */
-const char *
-p_option(u_long option) {
-	static char nbuf[40];
-
-	switch (option) {
-	case RES_INIT:		return "init";
-	case RES_DEBUG:		return "debug";
-	case RES_AAONLY:	return "aaonly(unimpl)";
-	case RES_USEVC:		return "usevc";
-	case RES_PRIMARY:	return "primry(unimpl)";
-	case RES_IGNTC:		return "igntc";
-	case RES_RECURSE:	return "recurs";
-	case RES_DEFNAMES:	return "defnam";
-	case RES_STAYOPEN:	return "styopn";
-	case RES_DNSRCH:	return "dnsrch";
-	case RES_INSECURE1:	return "insecure1";
-	case RES_INSECURE2:	return "insecure2";
-	case RES_NOALIASES:	return "noaliases";
-	case RES_USE_INET6:	return "inet6";
-	case RES_NOTLDQUERY:	return "no-tld-query";
-	case RES_USE_EDNS0:	return "edns0";
-	default:		sprintf(nbuf, "?0x%lx?", (u_long)option);
-				return (nbuf);
-	}
-}
-
-/*
- * Return a mnemonic for a time to live.
- */
-const char *
-p_time(u_int32_t value) {
-	static char nbuf[40];
-
-	if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
-		sprintf(nbuf, "%u", value);
-	return (nbuf);
-}
-
-
-/*
- * routines to convert between on-the-wire RR format and zone file format.
- * Does not contain conversion to/from decimal degrees; divide or multiply
- * by 60*60*1000 for that.
- */
-
-static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
-				      1000000,10000000,100000000,1000000000};
-
-/* takes an XeY precision/size value, returns a string representation. */
-static const char *
-precsize_ntoa(prec)
-	u_int8_t prec;
-{
-	static char retbuf[sizeof "90000000.00"];
-	unsigned long val;
-	int mantissa, exponent;
-
-	mantissa = (int)((prec >> 4) & 0x0f) % 10;
-	exponent = (int)((prec >> 0) & 0x0f) % 10;
-
-	val = mantissa * poweroften[exponent];
-
-	(void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
-	return (retbuf);
-}
-
-/* converts ascii size/precision X * 10**Y(cm) to 0xXY.  moves pointer. */
-static u_int8_t
-precsize_aton(strptr)
-	char **strptr;
-{
-	unsigned int mval = 0, cmval = 0;
-	u_int8_t retval = 0;
-	char *cp;
-	int exponent;
-	int mantissa;
-
-	cp = *strptr;
-
-	while (isdigit((unsigned char)*cp))
-		mval = mval * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* centimeters */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			cmval = (*cp++ - '0') * 10;
-			if (isdigit((unsigned char)*cp)) {
-				cmval += (*cp++ - '0');
-			}
-		}
-	}
-	cmval = (mval * 100) + cmval;
-
-	for (exponent = 0; exponent < 9; exponent++)
-		if (cmval < poweroften[exponent+1])
-			break;
-
-	mantissa = cmval / poweroften[exponent];
-	if (mantissa > 9)
-		mantissa = 9;
-
-	retval = (mantissa << 4) | exponent;
-
-	*strptr = cp;
-
-	return (retval);
-}
-
-/* converts ascii lat/lon to unsigned encoded 32-bit number.  moves pointer. */
-static u_int32_t
-latlon2ul(latlonstrptr,which)
-	char **latlonstrptr;
-	int *which;
-{
-	char *cp;
-	u_int32_t retval;
-	int deg = 0, min = 0, secs = 0, secsfrac = 0;
-
-	cp = *latlonstrptr;
-
-	while (isdigit((unsigned char)*cp))
-		deg = deg * 10 + (*cp++ - '0');
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
-	if (!(isdigit((unsigned char)*cp)))
-		goto fndhemi;
-
-	while (isdigit((unsigned char)*cp))
-		min = min * 10 + (*cp++ - '0');
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
-	if (!(isdigit((unsigned char)*cp)))
-		goto fndhemi;
-
-	while (isdigit((unsigned char)*cp))
-		secs = secs * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* decimal seconds */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			secsfrac = (*cp++ - '0') * 100;
-			if (isdigit((unsigned char)*cp)) {
-				secsfrac += (*cp++ - '0') * 10;
-				if (isdigit((unsigned char)*cp)) {
-					secsfrac += (*cp++ - '0');
-				}
-			}
-		}
-	}
-
-	while (!isspace((unsigned char)*cp))   /* if any trailing garbage */
-		cp++;
-
-	while (isspace((unsigned char)*cp))
-		cp++;
-
- fndhemi:
-	switch (*cp) {
-	case 'N': case 'n':
-	case 'E': case 'e':
-		retval = ((unsigned)1<<31)
-			+ (((((deg * 60) + min) * 60) + secs) * 1000)
-			+ secsfrac;
-		break;
-	case 'S': case 's':
-	case 'W': case 'w':
-		retval = ((unsigned)1<<31)
-			- (((((deg * 60) + min) * 60) + secs) * 1000)
-			- secsfrac;
-		break;
-	default:
-		retval = 0;	/* invalid value -- indicates error */
-		break;
-	}
-
-	switch (*cp) {
-	case 'N': case 'n':
-	case 'S': case 's':
-		*which = 1;	/* latitude */
-		break;
-	case 'E': case 'e':
-	case 'W': case 'w':
-		*which = 2;	/* longitude */
-		break;
-	default:
-		*which = 0;	/* error */
-		break;
-	}
-
-	cp++;			/* skip the hemisphere */
-
-	while (!isspace((unsigned char)*cp))   /* if any trailing garbage */
-		cp++;
-
-	while (isspace((unsigned char)*cp))    /* move to next field */
-		cp++;
-
-	*latlonstrptr = cp;
-
-	return (retval);
-}
-
-/* converts a zone file representation in a string to an RDATA on-the-wire
- * representation. */
-int
-loc_aton(ascii, binary)
-	const char *ascii;
-	u_char *binary;
-{
-	const char *cp, *maxcp;
-	u_char *bcp;
-
-	u_int32_t latit = 0, longit = 0, alt = 0;
-	u_int32_t lltemp1 = 0, lltemp2 = 0;
-	int altmeters = 0, altfrac = 0, altsign = 1;
-	u_int8_t hp = 0x16;	/* default = 1e6 cm = 10000.00m = 10km */
-	u_int8_t vp = 0x13;	/* default = 1e3 cm = 10.00m */
-	u_int8_t siz = 0x12;	/* default = 1e2 cm = 1.00m */
-	int which1 = 0, which2 = 0;
-
-	cp = ascii;
-	maxcp = cp + strlen(ascii);
-
-	lltemp1 = latlon2ul(&cp, &which1);
-
-	lltemp2 = latlon2ul(&cp, &which2);
-
-	switch (which1 + which2) {
-	case 3:			/* 1 + 2, the only valid combination */
-		if ((which1 == 1) && (which2 == 2)) { /* normal case */
-			latit = lltemp1;
-			longit = lltemp2;
-		} else if ((which1 == 2) && (which2 == 1)) { /* reversed */
-			longit = lltemp1;
-			latit = lltemp2;
-		} else {	/* some kind of brokenness */
-			return (0);
-		}
-		break;
-	default:		/* we didn't get one of each */
-		return (0);
-	}
-
-	/* altitude */
-	if (*cp == '-') {
-		altsign = -1;
-		cp++;
-	}
-    
-	if (*cp == '+')
-		cp++;
-
-	while (isdigit((unsigned char)*cp))
-		altmeters = altmeters * 10 + (*cp++ - '0');
-
-	if (*cp == '.') {		/* decimal meters */
-		cp++;
-		if (isdigit((unsigned char)*cp)) {
-			altfrac = (*cp++ - '0') * 10;
-			if (isdigit((unsigned char)*cp)) {
-				altfrac += (*cp++ - '0');
-			}
-		}
-	}
-
-	alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
-
-	while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	siz = precsize_aton(&cp);
-	
-	while (!isspace((unsigned char)*cp) && (cp < maxcp))   /* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	hp = precsize_aton(&cp);
-
-	while (!isspace((unsigned char)*cp) && (cp < maxcp))   /* if trailing garbage or m */
-		cp++;
-
-	while (isspace((unsigned char)*cp) && (cp < maxcp))
-		cp++;
-
-	if (cp >= maxcp)
-		goto defaults;
-
-	vp = precsize_aton(&cp);
-
- defaults:
-
-	bcp = binary;
-	*bcp++ = (u_int8_t) 0;	/* version byte */
-	*bcp++ = siz;
-	*bcp++ = hp;
-	*bcp++ = vp;
-	PUTLONG(latit,bcp);
-	PUTLONG(longit,bcp);
-	PUTLONG(alt,bcp);
-    
-	return (16);		/* size of RR in octets */
-}
-
-/* takes an on-the-wire LOC RR and formats it in a human readable format. */
-const char *
-loc_ntoa(binary, ascii)
-	const u_char *binary;
-	char *ascii;
-{
-	static char *error = "?";
-	const u_char *cp = binary;
-
-	int latdeg, latmin, latsec, latsecfrac;
-	int longdeg, longmin, longsec, longsecfrac;
-	char northsouth, eastwest;
-	int altmeters, altfrac, altsign;
-
-	const u_int32_t referencealt = 100000 * 100;
-
-	int32_t latval, longval, altval;
-	u_int32_t templ;
-	u_int8_t sizeval, hpval, vpval, versionval;
-    
-	char *sizestr, *hpstr, *vpstr;
-
-	versionval = *cp++;
-
-	if (versionval) {
-		(void) sprintf(ascii, "; error: unknown LOC RR version");
-		return (ascii);
-	}
-
-	sizeval = *cp++;
-
-	hpval = *cp++;
-	vpval = *cp++;
-
-	GETLONG(templ, cp);
-	latval = (templ - ((unsigned)1<<31));
-
-	GETLONG(templ, cp);
-	longval = (templ - ((unsigned)1<<31));
-
-	GETLONG(templ, cp);
-	if (templ < referencealt) { /* below WGS 84 spheroid */
-		altval = referencealt - templ;
-		altsign = -1;
-	} else {
-		altval = templ - referencealt;
-		altsign = 1;
-	}
-
-	if (latval < 0) {
-		northsouth = 'S';
-		latval = -latval;
-	} else
-		northsouth = 'N';
-
-	latsecfrac = latval % 1000;
-	latval = latval / 1000;
-	latsec = latval % 60;
-	latval = latval / 60;
-	latmin = latval % 60;
-	latval = latval / 60;
-	latdeg = latval;
-
-	if (longval < 0) {
-		eastwest = 'W';
-		longval = -longval;
-	} else
-		eastwest = 'E';
-
-	longsecfrac = longval % 1000;
-	longval = longval / 1000;
-	longsec = longval % 60;
-	longval = longval / 60;
-	longmin = longval % 60;
-	longval = longval / 60;
-	longdeg = longval;
-
-	altfrac = altval % 100;
-	altmeters = (altval / 100) * altsign;
-
-	if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
-		sizestr = error;
-	if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
-		hpstr = error;
-	if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
-		vpstr = error;
-
-	sprintf(ascii,
-	      "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
-		latdeg, latmin, latsec, latsecfrac, northsouth,
-		longdeg, longmin, longsec, longsecfrac, eastwest,
-		altmeters, altfrac, sizestr, hpstr, vpstr);
-
-	if (sizestr != error)
-		free(sizestr);
-	if (hpstr != error)
-		free(hpstr);
-	if (vpstr != error)
-		free(vpstr);
-
-	return (ascii);
-}
-
-
-/* Return the number of DNS hierarchy levels in the name. */
-int
-dn_count_labels(const char *name) {
-	int i, len, count;
-
-	len = strlen(name);
-	for (i = 0, count = 0; i < len; i++) {
-		/* XXX need to check for \. or use named's nlabels(). */
-		if (name[i] == '.')
-			count++;
-	}
-
-	/* don't count initial wildcard */
-	if (name[0] == '*')
-		if (count)
-			count--;
-
-	/* don't count the null label for root. */
-	/* if terminating '.' not found, must adjust */
-	/* count to include last label */
-	if (len > 0 && name[len-1] != '.')
-		count++;
-	return (count);
-}
-
-
-/* 
- * Make dates expressed in seconds-since-Jan-1-1970 easy to read.  
- * SIG records are required to be printed like this, by the Secure DNS RFC.
- */
-char *
-p_secstodate (u_long secs) {
-	static char output[15];		/* YYYYMMDDHHMMSS and null */
-	time_t clock = secs;
-	struct tm *time;
-	
-	time = gmtime(&clock);
-	time->tm_year += 1900;
-	time->tm_mon += 1;
-	sprintf(output, "%04d%02d%02d%02d%02d%02d",
-		time->tm_year, time->tm_mon, time->tm_mday,
-		time->tm_hour, time->tm_min, time->tm_sec);
-	return (output);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef fp_resstat
-__weak_reference(__fp_resstat, fp_resstat);
-#undef p_query
-__weak_reference(__p_query, p_query);
-#undef p_fqnname
-__weak_reference(__p_fqnname, p_fqnname);
-#undef sym_ston
-__weak_reference(__sym_ston, sym_ston);
-#undef sym_ntos
-__weak_reference(__sym_ntos, sym_ntos);
-#undef sym_ntop
-__weak_reference(__sym_ntop, sym_ntop);
-#undef dn_count_labels
-__weak_reference(__dn_count_labels, dn_count_labels);
-#undef p_secstodate
-__weak_reference(__p_secstodate, p_secstodate);
--- lib/libc/net/res_update.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais at ccm.fm.intel.com>
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_update.c,v 1.7 2002/09/15 16:51:09 nectar Exp $");
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <limits.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/*
- * Separate a linked list of records into groups so that all records
- * in a group will belong to a single zone on the nameserver.
- * Create a dynamic update packet for each zone and send it to the
- * nameservers for that zone, and await answer.
- * Abort if error occurs in updating any zone.
- * Return the number of zones updated on success, < 0 on error.
- *
- * On error, caller must deal with the unsynchronized zones
- * eg. an A record might have been successfully added to the forward
- * zone but the corresponding PTR record would be missing if error
- * was encountered while updating the reverse zone.
- */
-
-#define NSMAX 16
-
-struct ns1 {
-	char nsname[MAXDNAME];
-	struct in_addr nsaddr1;
-};
-
-struct zonegrp {
-	char 		z_origin[MAXDNAME];
-	int16_t		z_class;
-	char		z_soardata[MAXDNAME + 5 * INT32SZ];
-	struct ns1 	z_ns[NSMAX];
-	int		z_nscount;
-	ns_updrec *	z_rr;
-	struct zonegrp *z_next;
-};
-
-
-int
-res_update(ns_updrec *rrecp_in) {
-	ns_updrec *rrecp, *tmprrecp;
-	u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
-	char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
-	     mailaddr[MAXDNAME];
-	u_char soardata[2*MAXCDNAME+5*INT32SZ];
-	char *dname, *svdname, *cp1, *target;
-	u_char *cp, *eom;
-	HEADER *hp = (HEADER *) answer;
-	struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
-	int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
-	    newgroup, done, myzone, seen_before, numzones = 0;
-	u_int16_t dlen, class, qclass, type, qtype;
-	u_int32_t ttl;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-
-	for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
-		dname = rrecp->r_dname;
-		n = strlen(dname);
-		if (dname[n-1] == '.')
-			dname[n-1] = '\0';
-		qtype = T_SOA;
-		qclass = rrecp->r_class;
-		done = 0;
-		seen_before = 0;
-
-		while (!done && dname) {
-		    if (qtype == T_SOA) {
-			for (tmpzptr = zgrp_start;
-			     tmpzptr && !seen_before;
-			     tmpzptr = tmpzptr->z_next) {
-				if (strcasecmp(dname,
-					       tmpzptr->z_origin) == 0 &&
-				    tmpzptr->z_class == qclass)
-					seen_before++;
-				for (tmprrecp = tmpzptr->z_rr;
-				     tmprrecp && !seen_before;
-				     tmprrecp = tmprrecp->r_grpnext)
-				if (strcasecmp(dname, tmprrecp->r_dname) == 0
-				    && tmprrecp->r_class == qclass) {
-					seen_before++;
-					break;
-				}
-				if (seen_before) {
-					/*
-					 * Append to the end of
-					 * current group.
-					 */
-					for (tmprrecp = tmpzptr->z_rr;
-					     tmprrecp->r_grpnext;
-					     tmprrecp = tmprrecp->r_grpnext)
-						(void)NULL;
-					tmprrecp->r_grpnext = rrecp;
-					rrecp->r_grpnext = NULL;
-					done = 1;
-					break;
-				}
-			}
-		} else if (qtype == T_A) {
-		    for (tmpzptr = zgrp_start;
-			 tmpzptr && !done;
-			 tmpzptr = tmpzptr->z_next)
-			    for (i = 0; i < tmpzptr->z_nscount; i++)
-				if (tmpzptr->z_class == qclass &&
-				    strcasecmp(tmpzptr->z_ns[i].nsname,
-					       dname) == 0 &&
-				    tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
-					zptr->z_ns[k].nsaddr1.s_addr =
-					 tmpzptr->z_ns[i].nsaddr1.s_addr;
-					done = 1;
-					break;
-				}
-		}
-		if (done)
-		    break;
-		n = res_mkquery(QUERY, dname, qclass, qtype, NULL,
-				0, NULL, buf, sizeof buf);
-		if (n <= 0) {
-		    fprintf(stderr, "res_update: mkquery failed\n");
-		    return (n);
-		}
-		n = res_send(buf, n, answer, sizeof answer);
-		if (n < 0) {
-		    fprintf(stderr, "res_update: send error for %s\n",
-			    rrecp->r_dname);
-		    return (n);
-		} else if (n > sizeof(answer)) {
-		    fprintf(stderr, "res_update: buffer too small\n");
-		    return (-1);
-		}
-		if (n < HFIXEDSZ)
-			return (-1);
-		ancount = ntohs(hp->ancount);
-		nscount = ntohs(hp->nscount);
-		arcount = ntohs(hp->arcount);
-		rcode = hp->rcode;
-		cp = answer + HFIXEDSZ;
-		eom = answer + n;
-		/* skip the question section */
-		n = dn_skipname(cp, eom);
-		if (n < 0 || cp + n + 2 * INT16SZ > eom)
-			return (-1);
-		cp += n + 2 * INT16SZ;
-
-		if (qtype == T_SOA) {
-		    if (ancount == 0 && nscount == 0 && arcount == 0) {
-			/*
-			 * if (rcode == NOERROR) then the dname exists but
-			 * has no soa record associated with it.
-			 * if (rcode == NXDOMAIN) then the dname does not
-			 * exist and the server is replying out of NCACHE.
-			 * in either case, proceed with the next try
-			 */
-			dname = strchr(dname, '.');
-			if (dname != NULL)
-				dname++;
-			continue;
-		    } else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
-			       ancount == 0 &&
-			       nscount == 1 && arcount == 0) {
-			/*
-			 * name/data does not exist, soa record supplied in the
-			 * authority section
-			 */
-			/* authority section must contain the soa record */
-			if ((n = dn_expand(answer, eom, cp, zname,
-					sizeof zname)) < 0)
-			    return (n);
-			cp += n;
-			if (cp + 2 * INT16SZ > eom)
-				return (-1);
-			GETSHORT(type, cp);
-			GETSHORT(class, cp);
-			if (type != T_SOA || class != qclass) {
-			    fprintf(stderr, "unknown answer\n");
-			    return (-1);
-			}
-			myzone = 0;
-			svdname = dname;
-			while (dname)
-			    if (strcasecmp(dname, zname) == 0) {
-				myzone = 1;
-				break;
-			    } else if ((dname = strchr(dname, '.')) != NULL)
-				dname++;
-			if (!myzone) {
-			    dname = strchr(svdname, '.');
-			    if (dname != NULL)
-				dname++;
-			    continue;
-			}
-			nscount = 0;
-			/* fallthrough */
-		    } else if (rcode == NOERROR && ancount == 1) {
-			/*
-			 * found the zone name
-			 * new servers will supply NS records for the zone
-			 * in authority section and A records for those 
-			 * nameservers in the additional section
-			 * older servers have to be explicitly queried for
-			 * NS records for the zone
-			 */
-			/* answer section must contain the soa record */
-			if ((n = dn_expand(answer, eom, cp, zname,
-			 	       	   sizeof zname)) < 0)
-				return (n);
-			else
-				cp += n;
-			if (cp + 2 * INT16SZ > eom)
-				return (-1);
-			GETSHORT(type, cp);
-			GETSHORT(class, cp);
-			if (type == T_CNAME) {
-				dname = strchr(dname, '.');
-				if (dname != NULL)
-					dname++;
-				continue;
-			}
-			if (strcasecmp(dname, zname) != 0 ||
-			    type != T_SOA ||
-			    class != rrecp->r_class) {
-				fprintf(stderr, "unknown answer\n");
-				return (-1);
-			}
-			/* FALLTHROUGH */
-		    } else {
-			fprintf(stderr,
-		"unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
-				ancount, nscount, arcount, hp->rcode);
-			return (-1);
-		    }
-		    if (cp + INT32SZ + INT16SZ > eom)
-			    return (-1);
-		    /* continue processing the soa record */
-		    GETLONG(ttl, cp);
-		    GETSHORT(dlen, cp);
-		    if (cp + dlen > eom)
-			    return (-1);
-		    newgroup = 1;
-		    zptr = zgrp_start;
-		    prevzptr = NULL;
-		    while (zptr) {
-			if (strcasecmp(zname, zptr->z_origin) == 0 &&
-			    type == T_SOA && class == qclass) {
-				newgroup = 0;
-				break;
-			}
-			prevzptr = zptr;
-			zptr = zptr->z_next;
-		    }
-		    if (!newgroup) {
-			for (tmprrecp = zptr->z_rr;
-			     tmprrecp->r_grpnext;
-			     tmprrecp = tmprrecp->r_grpnext)
-				    ;
-			tmprrecp->r_grpnext = rrecp;
-			rrecp->r_grpnext = NULL;
-			done = 1;
-			cp += dlen;
-			break;
-		    } else {
-			if ((n = dn_expand(answer, eom, cp, primary,
-				       	   sizeof primary)) < 0)
-			    return (n);
-			cp += n;
-			/* 
-			 * We don't have to bounds check here because the
-			 * next use of 'cp' is in dn_expand().
-			 */
-			cp1 = (char *)soardata;
-			strcpy(cp1, primary);
-			cp1 += strlen(cp1) + 1;
-			if ((n = dn_expand(answer, eom, cp, mailaddr,
-				       	   sizeof mailaddr)) < 0)
-			    return (n);
-			cp += n;
-			strcpy(cp1, mailaddr);
-			cp1 += strlen(cp1) + 1;
-			if (cp + 5*INT32SZ > eom)
-				return (-1);
-			memcpy(cp1, cp, 5*INT32SZ);
-			cp += 5*INT32SZ;
-			cp1 += 5*INT32SZ;
-			rdatasize = (u_char *)cp1 - soardata;
-			zptr = calloc(1, sizeof(struct zonegrp));
-			if (zptr == NULL)
-                	    return (-1);
-			if (zgrp_start == NULL)
-			    zgrp_start = zptr;
-			else
-			    prevzptr->z_next = zptr;
-			zptr->z_rr = rrecp;
-			rrecp->r_grpnext = NULL;
-			strcpy(zptr->z_origin, zname);
-			zptr->z_class = class;
-			memcpy(zptr->z_soardata, soardata, rdatasize);
-			/* fallthrough to process NS and A records */
-		    }
-		} else if (qtype == T_NS) {
-		    if (rcode == NOERROR && ancount > 0) {
-			strcpy(zname, dname);
-			for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
-			    if (strcasecmp(zname, zptr->z_origin) == 0)
-				break;
-			}
-			if (zptr == NULL)
-			    /* should not happen */
-			    return (-1);
-			if (nscount > 0) {
-			    /*
-			     * answer and authority sections contain
-			     * the same information, skip answer section
-			     */
-			    for (j = 0; j < ancount; j++) {
-				n = dn_skipname(cp, eom);
-				if (n < 0)
-					return (-1);
-				n += 2*INT16SZ + INT32SZ;
-				if (cp + n + INT16SZ > eom)
-					return (-1);
-				cp += n;
-				GETSHORT(dlen, cp);
-				cp += dlen;
-			    }
-			} else
-			    nscount = ancount;
-			/* fallthrough to process NS and A records */
-		    } else {
-			fprintf(stderr, "cannot determine nameservers for %s:\
-ans=%d, auth=%d, add=%d, rcode=%d\n",
-				dname, ancount, nscount, arcount, hp->rcode);
-			return (-1);
-		    }
-		} else if (qtype == T_A) {
-		    if (rcode == NOERROR && ancount > 0) {
-			arcount = ancount;
-			ancount = nscount = 0;
-			/* fallthrough to process A records */
-		    } else {
-			fprintf(stderr, "cannot determine address for %s:\
-ans=%d, auth=%d, add=%d, rcode=%d\n",
-				dname, ancount, nscount, arcount, hp->rcode);
-			return (-1);
-		    }
-		}
-		/* process NS records for the zone */
-		j = 0;
-		for (i = 0; i < nscount; i++) {
-		    if ((n = dn_expand(answer, eom, cp, name,
-					sizeof name)) < 0)
-			return (n);
-		    cp += n;
-		    if (cp + 3 * INT16SZ + INT32SZ > eom)
-			    return (-1);
-		    GETSHORT(type, cp);
-		    GETSHORT(class, cp);
-		    GETLONG(ttl, cp);
-		    GETSHORT(dlen, cp);
-		    if (cp + dlen > eom)
-			return (-1);
-		    if (strcasecmp(name, zname) == 0 &&
-			type == T_NS && class == qclass) {
-				if ((n = dn_expand(answer, eom, cp,
-						   name, sizeof name)) < 0)
-					return (n);
-			    target = zptr->z_ns[j++].nsname;
-			    strcpy(target, name);
-		    }
-		    cp += dlen;
-		}
-		if (zptr->z_nscount == 0)
-		    zptr->z_nscount = j;
-		/* get addresses for the nameservers */
-		for (i = 0; i < arcount; i++) {
-		    if ((n = dn_expand(answer, eom, cp, name,
-					sizeof name)) < 0)
-			return (n);
-		    cp += n;
-		    if (cp + 3 * INT16SZ + INT32SZ > eom)
-			return (-1);
-		    GETSHORT(type, cp);
-		    GETSHORT(class, cp);
-		    GETLONG(ttl, cp);
-		    GETSHORT(dlen, cp);
-		    if (cp + dlen > eom)
-			    return (-1);
-		    if (type == T_A && dlen == INT32SZ && class == qclass) {
-			for (j = 0; j < zptr->z_nscount; j++)
-			    if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
-				memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
-				       INT32SZ);
-				break;
-			    }
-		    }
-		    cp += dlen;
-		}
-		if (zptr->z_nscount == 0) {
-		    dname = zname;
-		    qtype = T_NS;
-		    continue;
-		}
-		done = 1;
-		for (k = 0; k < zptr->z_nscount; k++)
-		    if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
-			done = 0;
-			dname = zptr->z_ns[k].nsname;
-			qtype = T_A;
-		    }
-
- 	    } /* while */
-	}
-
-	_res.options |= RES_DEBUG;
-	for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
-
-		/* append zone section */
-		rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
-				     zptr->z_class, ns_t_soa, 0);
-		if (rrecp == NULL) {
-			fprintf(stderr, "saverrec error\n");
-			fflush(stderr);
-			return (-1);
-		}
-		rrecp->r_grpnext = zptr->z_rr;
-		zptr->z_rr = rrecp;
-
-		n = res_mkupdate(zptr->z_rr, packet, sizeof packet);
-		if (n < 0) {
-			fprintf(stderr, "res_mkupdate error\n");
-			fflush(stderr);
-			return (-1);
-		} else
-			fprintf(stdout, "res_mkupdate: packet size = %d\n", n);
-
-		/*
-		 * Override the list of NS records from res_init() with
-		 * the authoritative nameservers for the zone being updated.
-		 * Sort primary to be the first in the list of nameservers.
-		 */
-		for (i = 0; i < zptr->z_nscount; i++) {
-			if (strcasecmp(zptr->z_ns[i].nsname,
-				       zptr->z_soardata) == 0) {
-				struct in_addr tmpaddr;
-
-				if (i != 0) {
-					strcpy(zptr->z_ns[i].nsname,
-					       zptr->z_ns[0].nsname);
-					strcpy(zptr->z_ns[0].nsname,
-					       zptr->z_soardata);
-					tmpaddr = zptr->z_ns[i].nsaddr1;
-					zptr->z_ns[i].nsaddr1 =
-						zptr->z_ns[0].nsaddr1;
-					zptr->z_ns[0].nsaddr1 = tmpaddr;
-				}
-				break;
-			}
-		}
-		for (i = 0; i < MAXNS; i++) {
-			_res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
-			_res.nsaddr_list[i].sin_family = AF_INET;
-			_res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
-		}
-		_res.nscount = (zptr->z_nscount < MAXNS) ? 
-					zptr->z_nscount : MAXNS;
-		n = res_send(packet, n, answer, sizeof(answer));
-		if (n < 0) {
-			fprintf(stderr, "res_send: send error, n=%d\n", n);
-			break;
-		} else if (n > sizeof(answer)) {
-			fprintf(stderr, "res_send: buffer too small\n");
-			break;
-		}
-			numzones++;
-	}
-
-	/* free malloc'ed memory */
-	while(zgrp_start) {
-		zptr = zgrp_start;
-		zgrp_start = zgrp_start->z_next;
-		res_freeupdrec(zptr->z_rr);  /* Zone section we allocated. */
-		free((char *)zptr);
-	}
-
-	return (numzones);
-}
--- lib/libc/net/res_comp.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Copyright (c) 1985, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_comp.c	8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_comp.c,v 1.18 2005/04/08 21:24:23 stefanf Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#define BIND_4_COMPAT
-
-/*
- * Expand compressed domain name 'comp_dn' to full domain name.
- * 'msg' is a pointer to the begining of the message,
- * 'eomorig' points to the first location after the message,
- * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
- * Return size of compressed name or -1 if there was an error.
- */
-int
-dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
-	  char *dst, int dstsiz)
-{
-	int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
-
-	if (n > 0 && dst[0] == '.')
-		dst[0] = '\0';
-	return (n);
-}
-
-/*
- * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
- * Return the size of the compressed name or -1.
- * 'length' is the size of the array pointed to by 'comp_dn'.
- */
-int
-dn_comp(const char *src, u_char *dst, int dstsiz,
-	u_char **dnptrs, u_char **lastdnptr)
-{
-	return (ns_name_compress(src, dst, (size_t)dstsiz,
-				 (const u_char **)dnptrs,
-				 (const u_char **)lastdnptr));
-}
-
-/*
- * Skip over a compressed domain name. Return the size or -1.
- */
-int
-dn_skipname(const u_char *ptr, const u_char *eom) {
-	const u_char *saveptr = ptr;
-
-	if (ns_name_skip(&ptr, eom) == -1)
-		return (-1);
-	return (ptr - saveptr);
-}
-
-/*
- * Verify that a domain name uses an acceptable character set.
- */
-
-/*
- * Note the conspicuous absence of ctype macros in these definitions.  On
- * non-ASCII hosts, we can't depend on string literals or ctype macros to
- * tell us anything about network-format data.  The rest of the BIND system
- * is not careful about this, but for some reason, we're doing it right here.
- */
-#define PERIOD 0x2e
-#define	hyphenchar(c) ((c) == 0x2d)
-#define bslashchar(c) ((c) == 0x5c)
-#define periodchar(c) ((c) == PERIOD)
-#define asterchar(c) ((c) == 0x2a)
-#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
-		   || ((c) >= 0x61 && (c) <= 0x7a))
-#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
-
-#define borderchar(c) (alphachar(c) || digitchar(c))
-#define middlechar(c) (borderchar(c) || hyphenchar(c))
-#define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
-
-int
-res_hnok(dn)
-	const char *dn;
-{
-	int pch = PERIOD, ch = *dn++;
-
-	while (ch != '\0') {
-		int nch = *dn++;
-
-		if (periodchar(ch)) {
-			(void)NULL;
-		} else if (periodchar(pch)) {
-			if (!borderchar(ch))
-				return (0);
-		} else if (periodchar(nch) || nch == '\0') {
-			if (!borderchar(ch))
-				return (0);
-		} else {
-			if (!middlechar(ch))
-				return (0);
-		}
-		pch = ch, ch = nch;
-	}
-	return (1);
-}
-
-/*
- * hostname-like (A, MX, WKS) owners can have "*" as their first label
- * but must otherwise be as a host name.
- */
-int
-res_ownok(dn)
-	const char *dn;
-{
-	if (asterchar(dn[0])) {
-		if (periodchar(dn[1]))
-			return (res_hnok(dn+2));
-		if (dn[1] == '\0')
-			return (1);
-	}
-	return (res_hnok(dn));
-}
-
-/*
- * SOA RNAMEs and RP RNAMEs can have any printable character in their first
- * label, but the rest of the name has to look like a host name.
- */
-int
-res_mailok(dn)
-	const char *dn;
-{
-	int ch, escaped = 0;
-
-	/* "." is a valid missing representation */
-	if (*dn == '\0')
-		return (1);
-
-	/* otherwise <label>.<hostname> */
-	while ((ch = *dn++) != '\0') {
-		if (!domainchar(ch))
-			return (0);
-		if (!escaped && periodchar(ch))
-			break;
-		if (escaped)
-			escaped = 0;
-		else if (bslashchar(ch))
-			escaped = 1;
-	}
-	if (periodchar(ch))
-		return (res_hnok(dn));
-	return (0);
-}
-
-/*
- * This function is quite liberal, since RFC 1034's character sets are only
- * recommendations.
- */
-int
-res_dnok(dn)
-	const char *dn;
-{
-	int ch;
-
-	while ((ch = *dn++) != '\0')
-		if (!domainchar(ch))
-			return (0);
-	return (1);
-}
-
-#ifdef BIND_4_COMPAT
-/*
- * This module must export the following externally-visible symbols:
- *    ___putlong
- *    ___putshort
- *    __getlong
- *    __getshort
- * Note that one _ comes from C and the others come from us.
- */
-void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
-void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
-u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
-u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
-#endif /*BIND_4_COMPAT*/
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef dn_comp
-__weak_reference(__dn_comp, dn_comp);
-#undef dn_expand
-__weak_reference(__dn_expand, dn_expand);
--- lib/libc/net/inet_makeaddr.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_makeaddr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_makeaddr.c,v 1.4 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/*
- * Formulate an Internet address from network + host.  Used in
- * building addresses stored in the ifnet structure.
- */
-struct in_addr
-inet_makeaddr(net, host)
-	in_addr_t net, host;
-{
-	in_addr_t addr;
-
-	if (net < 128)
-		addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
-	else if (net < 65536)
-		addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
-	else if (net < 16777216L)
-		addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
-	else
-		addr = net | host;
-	addr = htonl(addr);
-	return (*(struct in_addr *)&addr);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_makeaddr
-__weak_reference(__inet_makeaddr, inet_makeaddr);
--- lib/libc/net/res_send_private.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $FreeBSD: src/lib/libc/net/res_send_private.h,v 1.1 2004/02/25 21:03:46 green Exp $ */
-
-/*
- * Copyright (c) 1985, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-struct __res_send_private {
-	int s;			/* socket used for communications */
-	int connected;		/* is the socket connected */
-	int vc;			/* is the socket a virtual circuit? */
-	int af;			/* address family of socket */
-	res_send_qhook Qhook;
-	res_send_rhook Rhook;
-};
-
-struct __res_send_private *___res_send_private(void);
--- lib/libc/net/getservbyport.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyport.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/getservbyport.c,v 1.7 2005/04/18 18:34:58 ume Exp $");
-
-#include <netdb.h>
-#include <string.h>
-#include "netdb_private.h"
-
-int
-getservbyport_r(int port, const char *proto, struct servent *se,
-    struct servent_data *sed)
-{
-	int error;
-
-#ifdef YP
-	sed->yp_port = port;
-	sed->yp_proto = (char *)proto;
-#endif
-
-	setservent_r(sed->stayopen, sed);
-	while ((error = getservent_r(se, sed)) == 0) {
-		if (se->s_port != port)
-			continue;
-		if (proto == 0 || strcmp(se->s_proto, proto) == 0)
-			break;
-	}
-	if (!sed->stayopen)
-		endservent_r(sed);
-
-#ifdef YP
-	sed->yp_port = 0;
-	sed->yp_proto = NULL;
-#endif
-
-	return (error);
-}
-
-struct servent *
-getservbyport(int port, const char *proto)
-{
-	struct servdata *sd;
-
-	if ((sd = __servdata_init()) == NULL)
-		return (NULL);
-	if (getservbyport_r(port, proto, &sd->serv, &sd->data) != 0)
-		return (NULL);
-	return (&sd->serv);
-}
--- lib/libc/net/res_init.c
+++ /dev/null
@@ -1,715 +0,0 @@
-/*
- * Copyright (c) 1985, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_init.c	8.1 (Berkeley) 6/7/93";
-static char orig_rcsid[] = "From: Id: res_init.c,v 8.7 1996/11/18 09:10:04 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_init.c,v 1.33 2004/09/09 17:42:18 yar Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <limits.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-
-#include "namespace.h"
-#include "reentrant.h"
-#include "un-namespace.h"
-#include "res_config.h"
-#include "res_send_private.h"
-
-#undef h_errno
-extern int h_errno;
-
-static void res_setoptions(char *, char *);
-
-#ifdef RESOLVSORT
-static const char sort_mask[] = "/&";
-#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
-static u_int32_t net_mask(struct in_addr);
-#endif
-
-#if !defined(isascii) /* XXX - could be a function */
-# define isascii(c) (!(c & 0200))
-#endif
-
-/*
- * Check structure for failed per-thread allocations.
- */
-static struct res_per_thread {
-	struct __res_state res_state;
-	struct __res_state_ext res_state_ext;
-	struct __res_send_private res_send_private;
-	int h_errno;
-} _res_per_thread_bogus = { .res_send_private = { .s = -1 } }; /* socket */
-
-/*
- * Set up default settings.  If the configuration file exist, the values
- * there will have precedence.  Otherwise, the server address is set to
- * INADDR_ANY and the default domain name comes from the gethostname().
- *
- * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
- * rather than INADDR_ANY ("0.0.0.0") as the default name server address
- * since it was noted that INADDR_ANY actually meant ``the first interface
- * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
- * it had to be "up" in order for you to reach your own name server.  It
- * was later decided that since the recommended practice is to always 
- * install local static routes through 127.0.0.1 for all your network
- * interfaces, that we could solve this problem without a code change.
- *
- * The configuration file should always be used, since it is the only way
- * to specify a default domain.  If you are running a server on your local
- * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
- * in the configuration file.
- *
- * Return 0 if completes successfully, -1 on error
- */
-int
-res_init()
-{
-	FILE *fp;
-	struct __res_send_private *rsp;
-	char *cp, **pp;
-	int n;
-	char buf[MAXDNAME];
-	int nserv = 0;    /* number of nameserver records read from file */
-	int haveenv = 0;
-	int havesearch = 0;
-#ifdef RESOLVSORT
-	int nsort = 0;
-	char *net;
-#endif
-#ifndef RFC1535
-	int dots;
-#endif
-
-	/*
-	 * If allocation of memory for this thread's resolver has failed,
-	 * return the error to the user.
-	 */
-	if (&_res == &_res_per_thread_bogus.res_state)
-		return (-1);
-	rsp = ___res_send_private();
-	rsp->s = -1;
-	rsp->connected = 0;
-	rsp->vc = 0;
-	rsp->af = 0;
-	rsp->Qhook = NULL;
-	rsp->Rhook = NULL;
-	/*
-	 * These three fields used to be statically initialized.  This made
-	 * it hard to use this code in a shared library.  It is necessary,
-	 * now that we're doing dynamic initialization here, that we preserve
-	 * the old semantics: if an application modifies one of these three
-	 * fields of _res before res_init() is called, res_init() will not
-	 * alter them.  Of course, if an application is setting them to
-	 * _zero_ before calling res_init(), hoping to override what used
-	 * to be the static default, we can't detect it and unexpected results
-	 * will follow.  Zero for any of these fields would make no sense,
-	 * so one can safely assume that the applications were already getting
-	 * unexpected results.
-	 *
-	 * _res.options is tricky since some apps were known to diddle the bits
-	 * before res_init() was first called. We can't replicate that semantic
-	 * with dynamic initialization (they may have turned bits off that are
-	 * set in RES_DEFAULT).  Our solution is to declare such applications
-	 * "broken".  They could fool us by setting RES_INIT but none do (yet).
-	 */
-	if (!_res.retrans)
-		_res.retrans = RES_TIMEOUT;
-	if (!_res.retry)
-		_res.retry = RES_DFLRETRY;
-	if (!(_res.options & RES_INIT))
-		_res.options = RES_DEFAULT;
-
-	/*
-	 * This one used to initialize implicitly to zero, so unless the app
-	 * has set it to something in particular, we can randomize it now.
-	 */
-	if (!_res.id)
-		_res.id = res_randomid();
-
-#ifdef USELOOPBACK
-	_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
-#else
-	_res.nsaddr.sin_addr.s_addr = INADDR_ANY;
-#endif
-	_res.nsaddr.sin_family = AF_INET;
-	_res.nsaddr.sin_port = htons(NAMESERVER_PORT);
-	_res.nsaddr.sin_len = sizeof(struct sockaddr_in);
-	if (sizeof(_res_ext.nsaddr) >= _res.nsaddr.sin_len)
-		memcpy(&_res_ext.nsaddr, &_res.nsaddr, _res.nsaddr.sin_len);
-	_res.nscount = 1;
-	_res.ndots = 1;
-	_res.pfcode = 0;
-
-	/* Allow user to override the local domain definition */
-	if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) {
-		(void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
-		_res.defdname[sizeof(_res.defdname) - 1] = '\0';
-		haveenv++;
-
-		/*
-		 * Set search list to be blank-separated strings
-		 * from rest of env value.  Permits users of LOCALDOMAIN
-		 * to still have a search list, and anyone to set the
-		 * one that they want to use as an individual (even more
-		 * important now that the rfc1535 stuff restricts searches)
-		 */
-		cp = _res.defdname;
-		pp = _res.dnsrch;
-		*pp++ = cp;
-		for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
-			if (*cp == '\n')	/* silly backwards compat */
-				break;
-			else if (*cp == ' ' || *cp == '\t') {
-				*cp = 0;
-				n = 1;
-			} else if (n) {
-				*pp++ = cp;
-				n = 0;
-				havesearch = 1;
-			}
-		}
-		/* null terminate last domain if there are excess */
-		while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
-			cp++;
-		*cp = '\0';
-		*pp++ = 0;
-	}
-
-#define	MATCH(line, name) \
-	(!strncmp(line, name, sizeof(name) - 1) && \
-	(line[sizeof(name) - 1] == ' ' || \
-	 line[sizeof(name) - 1] == '\t'))
-
-	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
-	    /* read the config file */
-	    while (fgets(buf, sizeof(buf), fp) != NULL) {
-		/* skip comments */
-		if (*buf == ';' || *buf == '#')
-			continue;
-		/* read default domain name */
-		if (MATCH(buf, "domain")) {
-		    if (haveenv)	/* skip if have from environ */
-			    continue;
-		    cp = buf + sizeof("domain") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			    cp++;
-		    if ((*cp == '\0') || (*cp == '\n'))
-			    continue;
-		    strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
-		    _res.defdname[sizeof(_res.defdname) - 1] = '\0';
-		    if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
-			    *cp = '\0';
-		    havesearch = 0;
-		    continue;
-		}
-		/* set search list */
-		if (MATCH(buf, "search")) {
-		    if (haveenv)	/* skip if have from environ */
-			    continue;
-		    cp = buf + sizeof("search") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			    cp++;
-		    if ((*cp == '\0') || (*cp == '\n'))
-			    continue;
-		    strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
-		    _res.defdname[sizeof(_res.defdname) - 1] = '\0';
-		    if ((cp = strchr(_res.defdname, '\n')) != NULL)
-			    *cp = '\0';
-		    /*
-		     * Set search list to be blank-separated strings
-		     * on rest of line.
-		     */
-		    cp = _res.defdname;
-		    pp = _res.dnsrch;
-		    *pp++ = cp;
-		    for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
-			    if (*cp == ' ' || *cp == '\t') {
-				    *cp = 0;
-				    n = 1;
-			    } else if (n) {
-				    *pp++ = cp;
-				    n = 0;
-			    }
-		    }
-		    /* null terminate last domain if there are excess */
-		    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
-			    cp++;
-		    *cp = '\0';
-		    *pp++ = 0;
-		    havesearch = 1;
-		    continue;
-		}
-		/* read nameservers to query */
-		if (MATCH(buf, "nameserver") && nserv < MAXNS) {
-		    char *q;
-		    struct addrinfo hints, *res;
-		    char pbuf[NI_MAXSERV];
-
-		    cp = buf + sizeof("nameserver") - 1;
-		    while (*cp == ' ' || *cp == '\t')
-			cp++;
-		    if ((*cp == '\0') || (*cp == '\n'))
-			continue;
-		    for (q = cp; *q; q++) {
-			if (isspace(*q)) {
-			    *q = '\0';
-			    break;
-			}
-		    }
-		    memset(&hints, 0, sizeof(hints));
-		    hints.ai_flags = AI_NUMERICHOST;
-		    hints.ai_socktype = SOCK_DGRAM;
-		    snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT);
-		    if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
-			    res->ai_next == NULL) {
-			if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) {
-			    memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr,
-				res->ai_addrlen);
-			} else {
-			    memset(&_res_ext.nsaddr_list[nserv], 0,
-				sizeof(_res_ext.nsaddr_list[nserv]));
-			}
-			if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) {
-			    memcpy(&_res.nsaddr_list[nserv], res->ai_addr,
-				res->ai_addrlen);
-			} else {
-			    memset(&_res.nsaddr_list[nserv], 0,
-				sizeof(_res.nsaddr_list[nserv]));
-			}
-			nserv++;
-		    }
-		    if (res)
-			    freeaddrinfo(res);
-		    continue;
-		}
-#ifdef RESOLVSORT
-		if (MATCH(buf, "sortlist")) {
-		    struct in_addr a;
-		    struct in6_addr a6;
-		    int m, i;
-		    u_char *u;
-
-		    cp = buf + sizeof("sortlist") - 1;
-		    while (nsort < MAXRESOLVSORT) {
-			while (*cp == ' ' || *cp == '\t')
-			    cp++;
-			if (*cp == '\0' || *cp == '\n' || *cp == ';')
-			    break;
-			net = cp;
-			while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
-			       isascii(*cp) && !isspace(*cp))
-				cp++;
-			n = *cp;
-			*cp = 0;
-			if (inet_aton(net, &a)) {
-			    _res.sort_list[nsort].addr = a;
-			    if (ISSORTMASK(n)) {
-				*cp++ = n;
-				net = cp;
-				while (*cp && *cp != ';' &&
-					isascii(*cp) && !isspace(*cp))
-				    cp++;
-				n = *cp;
-				*cp = 0;
-				if (inet_aton(net, &a)) {
-				    _res.sort_list[nsort].mask = a.s_addr;
-				} else {
-				    _res.sort_list[nsort].mask = 
-					net_mask(_res.sort_list[nsort].addr);
-				}
-			    } else {
-				_res.sort_list[nsort].mask = 
-				    net_mask(_res.sort_list[nsort].addr);
-			    }
-			    _res_ext.sort_list[nsort].af = AF_INET;
-			    _res_ext.sort_list[nsort].addr.ina =
-				_res.sort_list[nsort].addr;
-			    _res_ext.sort_list[nsort].mask.ina.s_addr =
-				_res.sort_list[nsort].mask;
-			    nsort++;
-			}
-			else if (inet_pton(AF_INET6, net, &a6) == 1) {
-
-			    _res_ext.sort_list[nsort].af = AF_INET6;
-			    _res_ext.sort_list[nsort].addr.in6a = a6;
-			    u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a;
-			    *cp++ = n;
-			    net = cp;
-			    while (*cp && *cp != ';' &&
-				    isascii(*cp) && !isspace(*cp))
-				cp++;
-			    m = n;
-			    n = *cp;
-			    *cp = 0;
-			    switch (m) {
-			    case '/':
-				m = atoi(net);
-				break;
-			    case '&':
-				if (inet_pton(AF_INET6, net, u) == 1) {
-				    m = -1;
-				    break;
-				}
-				/*FALLTHROUGH*/
-			    default:
-				m = sizeof(struct in6_addr) * CHAR_BIT;
-				break;
-			    }
-			    if (m >= 0) {
-				for (i = 0; i < sizeof(struct in6_addr); i++) {
-				    if (m <= 0) {
-					*u = 0;
-				    } else {
-					m -= CHAR_BIT;
-					*u = (u_char)~0;
-					if (m < 0)
-					    *u <<= -m;
-				    }
-				    u++;
-				}
-			    }
-			    _res.sort_list[nsort].addr.s_addr =
-				(u_int32_t)0xffffffff;
-			    _res.sort_list[nsort].mask = (u_int32_t)0xffffffff;
-			    nsort++;
-			}
-			*cp = n;
-		    }
-		    continue;
-		}
-#endif
-		if (MATCH(buf, "options")) {
-		    res_setoptions(buf + sizeof("options") - 1, "conf");
-		    continue;
-		}
-	    }
-	    if (nserv > 1) 
-		_res.nscount = nserv;
-#ifdef RESOLVSORT
-	    _res.nsort = nsort;
-#endif
-	    (void) fclose(fp);
-	}
-	if (_res.defdname[0] == 0 &&
-	    gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
-	    (cp = strchr(buf, '.')) != NULL)
-		strcpy(_res.defdname, cp + 1);
-
-	/* find components of local domain that might be searched */
-	if (havesearch == 0) {
-		pp = _res.dnsrch;
-		*pp++ = _res.defdname;
-		*pp = NULL;
-
-#ifndef RFC1535
-		dots = 0;
-		for (cp = _res.defdname; *cp; cp++)
-			dots += (*cp == '.');
-
-		cp = _res.defdname;
-		while (pp < _res.dnsrch + MAXDFLSRCH) {
-			if (dots < LOCALDOMAINPARTS)
-				break;
-			cp = strchr(cp, '.') + 1;    /* we know there is one */
-			*pp++ = cp;
-			dots--;
-		}
-		*pp = NULL;
-#ifdef DEBUG
-		if (_res.options & RES_DEBUG) {
-			printf(";; res_init()... default dnsrch list:\n");
-			for (pp = _res.dnsrch; *pp; pp++)
-				printf(";;\t%s\n", *pp);
-			printf(";;\t..END..\n");
-		}
-#endif
-#endif /* !RFC1535 */
-	}
-
-	if (issetugid())
-		_res.options |= RES_NOALIASES;
-	else if ((cp = getenv("RES_OPTIONS")) != NULL)
-		res_setoptions(cp, "env");
-	_res.options |= RES_INIT;
-	return (0);
-}
-
-static void
-res_setoptions(options, source)
-	char *options, *source;
-{
-	char *cp = options;
-	int i;
-
-#ifdef DEBUG
-	if (_res.options & RES_DEBUG)
-		printf(";; res_setoptions(\"%s\", \"%s\")...\n",
-		       options, source);
-#endif
-	while (*cp) {
-		/* skip leading and inner runs of spaces */
-		while (*cp == ' ' || *cp == '\t')
-			cp++;
-		/* search for and process individual options */
-		if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
-			i = atoi(cp + sizeof("ndots:") - 1);
-			if (i <= RES_MAXNDOTS)
-				_res.ndots = i;
-			else
-				_res.ndots = RES_MAXNDOTS;
-#ifdef DEBUG
-			if (_res.options & RES_DEBUG)
-				printf(";;\tndots=%d\n", _res.ndots);
-#endif
-		} else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
-			i = atoi(cp + sizeof("timeout:") - 1);
-			if (i <= RES_MAXRETRANS)
-				_res.retrans = i;
-			else
-				_res.retrans = RES_MAXRETRANS;
-#ifdef DEBUG
-			if (_res.options & RES_DEBUG)
-				printf(";;\ttimeout=%d\n", _res.retrans);
-#endif
-		} else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
-			i = atoi(cp + sizeof("attempts:") - 1);
-			if (i <= RES_MAXRETRY)
-				_res.retry = i;
-			else
-				_res.retry = RES_MAXRETRY;
-#ifdef DEBUG
-			if (_res.options & RES_DEBUG)
-				printf(";;\tretry=%d\n", _res.retry);
-#endif
-		} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
-#ifdef DEBUG
-			if (!(_res.options & RES_DEBUG)) {
-				printf(";; res_setoptions(\"%s\", \"%s\")..\n",
-				       options, source);
-				_res.options |= RES_DEBUG;
-			}
-			printf(";;\tdebug\n");
-#endif
-		} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
-			_res.options |= RES_USE_INET6;
-		} else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) {
-		       _res.options |= RES_INSECURE1;
-		} else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) {
-		       _res.options |= RES_INSECURE2;
-		} else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) {
-			_res.options |= RES_NOTLDQUERY;
-		} else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
-		       _res.options |= RES_USE_EDNS0;
-		} else {
-			/* XXX - print a warning here? */
-		}
-		/* skip to next run of spaces */
-		while (*cp && *cp != ' ' && *cp != '\t')
-			cp++;
-	}
-}
-
-#ifdef RESOLVSORT
-/* XXX - should really support CIDR which means explicit masks always. */
-static u_int32_t
-net_mask(in)		/* XXX - should really use system's version of this */
-	struct in_addr in;
-{
-	u_int32_t i = ntohl(in.s_addr);
-
-	if (IN_CLASSA(i))
-		return (htonl(IN_CLASSA_NET));
-	else if (IN_CLASSB(i))
-		return (htonl(IN_CLASSB_NET));
-	return (htonl(IN_CLASSC_NET));
-}
-#endif
-
-u_int
-res_randomid()
-{
-	struct timeval now;
-
-	gettimeofday(&now, NULL);
-	return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
-}
-
-/*
- * Resolver state default settings.
- */
-
-#undef _res
-#undef _res_ext
-#ifdef __BIND_RES_TEXT
-struct __res_state _res = { RES_TIMEOUT };	/* Motorola, et al. */
-#else
-struct __res_state _res;
-#endif
-struct __res_state_ext _res_ext;
-static struct __res_send_private _res_send_private = { .s = -1 }; /* socket */
-
-static thread_key_t res_key;
-static once_t res_init_once = ONCE_INITIALIZER;
-static int res_thr_keycreated = 0;
-
-static void
-free_res(void *ptr)
-{
-	struct res_per_thread *myrsp = ptr;
-
-	if (myrsp->res_state.options & RES_INIT)
-		res_close();
-	free(myrsp);
-}
-
-static void
-res_keycreate(void)
-{
-	res_thr_keycreated = thr_keycreate(&res_key, free_res) == 0;
-}
-
-static struct res_per_thread *
-allocate_res(void)
-{
-	struct res_per_thread *myrsp;
-	
-	if (thr_once(&res_init_once, res_keycreate) != 0 ||
-	    !res_thr_keycreated)
-		return (&_res_per_thread_bogus);
-
-	myrsp = thr_getspecific(res_key);
-	if (myrsp != NULL)
-		return (myrsp);
-	myrsp = calloc(1, sizeof(*myrsp));
-	if (myrsp == NULL)
-		return (&_res_per_thread_bogus);
-#ifdef __BIND_RES_TEXT
-	myrsp->res_state.options = RES_TIMEOUT;		/* Motorola, et al. */
-#endif
-	myrsp->res_send_private.s = -1;			/* socket */
-	if (thr_setspecific(res_key, myrsp) == 0)
-		return (myrsp);
-	free(myrsp);
-	return (&_res_per_thread_bogus);
-}
-
-struct __res_state *
-___res(void)
-{
-	if (thr_main() != 0)
-		return (&_res);
-	return (&allocate_res()->res_state);
-}
-
-struct __res_state_ext *
-___res_ext(void)
-{
-	if (thr_main() != 0)
-		return (&_res_ext);
-	return (&allocate_res()->res_state_ext);
-}
-
-struct __res_send_private *
-___res_send_private(void)
-{
-	if (thr_main() != 0)
-		return (&_res_send_private);
-	return (&allocate_res()->res_send_private);
-}
-
-int *
-__h_error(void)
-{
-	if (thr_main() != 0)
-		return (&h_errno);
-	return (&allocate_res()->h_errno);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_init
-__weak_reference(__res_init, res_init);
--- lib/libc/net/inet_ntoa.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_ntoa.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_ntoa.c,v 1.6 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdio.h>
-#include <string.h>
-
-/*
- * Convert network-format internet address
- * to base 256 d.d.d.d representation.
- */
-char *
-inet_ntoa(in)
-	struct in_addr in;
-{
-	static char ret[18];
-
-	strcpy(ret, "[inet_ntoa error]");
-	(void) inet_ntop(AF_INET, &in, ret, sizeof ret);
-	return (ret);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_ntoa
-__weak_reference(__inet_ntoa, inet_ntoa);
--- lib/libc/net/res_send.c
+++ /dev/null
@@ -1,941 +0,0 @@
-/*
- * Copyright (c) 1985, 1989, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_send.c	8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_send.c,v 1.50 2005/05/13 16:31:09 ume Exp $");
-
-/*
- * Send query to name server and wait for reply.
- */
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/event.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-#include "res_config.h"
-#include "res_send_private.h"
-
-
-#define	s		___res_send_private()->s
-#define	connected	___res_send_private()->connected
-#define	vc		___res_send_private()->vc
-#define	af		___res_send_private()->af
-#define	Qhook		___res_send_private()->Qhook
-#define	Rhook		___res_send_private()->Rhook
-
-#define CAN_RECONNECT 1
-
-#ifndef DEBUG
-#   define Dprint(cond, args) /*empty*/
-#   define DprintQ(cond, args, query, size) /*empty*/
-#   define Aerror(file, string, error, address) /*empty*/
-#   define Perror(file, string, error) /*empty*/
-#else
-#   define Dprint(cond, args) if (cond) {fprintf args;} else {}
-#   define DprintQ(cond, args, query, size) if (cond) {\
-			fprintf args;\
-			__fp_nquery(query, size, stdout);\
-		} else {}
-static void Aerror(FILE *, char *, int, struct sockaddr *);
-static void Perror(FILE *, char *, int);
-
-    static void
-    Aerror(file, string, error, address)
-	FILE *file;
-	char *string;
-	int error;
-	struct sockaddr *address;
-    {
-	int save = errno;
-
-	if (_res.options & RES_DEBUG) {
-		char abuf[NI_MAXHOST];
-		char pbuf[NI_MAXSERV];
-
-		if (getnameinfo(address, address->sa_len, abuf, sizeof(abuf),
-		    pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
-			strncpy(abuf, "?", sizeof(abuf));
-			strncpy(pbuf, "?", sizeof(pbuf));
-		}
-		fprintf(file, "res_send: %s ([%s].%s): %s\n",
-			string, abuf, pbuf, strerror(error));
-	}
-	errno = save;
-    }
-    static void
-    Perror(file, string, error)
-	FILE *file;
-	char *string;
-	int error;
-    {
-	int save = errno;
-
-	if (_res.options & RES_DEBUG) {
-		fprintf(file, "res_send: %s: %s\n",
-			string, strerror(error));
-	}
-	errno = save;
-    }
-#endif
-
-void
-res_send_setqhook(hook)
-	res_send_qhook hook;
-{
-
-	Qhook = hook;
-}
-
-void
-res_send_setrhook(hook)
-	res_send_rhook hook;
-{
-
-	Rhook = hook;
-}
-
-static struct sockaddr * get_nsaddr(size_t);
-
-/*
- * pick appropriate nsaddr_list for use.  see res_init() for initialization.
- */
-static struct sockaddr *
-get_nsaddr(n)
-	size_t n;
-{
-
-	if (!_res.nsaddr_list[n].sin_family) {
-		/*
-		 * - _res_ext.nsaddr_list[n] holds an address that is larger
-		 *   than struct sockaddr, and
-		 * - user code did not update _res.nsaddr_list[n].
-		 */
-		return (struct sockaddr *)&_res_ext.nsaddr_list[n];
-	} else {
-		/*
-		 * - user code updated _res.nsaddr_list[n], or
-		 * - _res.nsaddr_list[n] has the same content as
-		 *   _res_ext.nsaddr_list[n].
-		 */
-		return (struct sockaddr *)&_res.nsaddr_list[n];
-	}
-}
-
-/* int
- * res_isourserver(ina)
- *	looks up "ina" in _res.ns_addr_list[]
- * returns:
- *	0  : not found
- *	>0 : found
- * author:
- *	paul vixie, 29may94
- */
-int
-res_isourserver(inp)
-	const struct sockaddr_in *inp;
-{
-	const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp;
-	const struct sockaddr_in6 *srv6;
-	const struct sockaddr_in *srv;
-	int ns, ret;
-
-	ret = 0;
-	switch (inp->sin_family) {
-	case AF_INET6:
-		for (ns = 0; ns < _res.nscount; ns++) {
-			srv6 = (struct sockaddr_in6 *)get_nsaddr(ns);
-			if (srv6->sin6_family == in6p->sin6_family &&
-			    srv6->sin6_port == in6p->sin6_port &&
-			    srv6->sin6_scope_id == in6p->sin6_scope_id &&
-			    (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
-			     IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr,
-			         &in6p->sin6_addr))) {
-				ret++;
-				break;
-			}
-		}
-		break;
-	case AF_INET:
-		for (ns = 0; ns < _res.nscount; ns++) {
-			srv = (struct sockaddr_in *)get_nsaddr(ns);
-			if (srv->sin_family == inp->sin_family &&
-			    srv->sin_port == inp->sin_port &&
-			    (srv->sin_addr.s_addr == INADDR_ANY ||
-			     srv->sin_addr.s_addr == inp->sin_addr.s_addr)) {
-				ret++;
-				break;
-			}
-		}
-		break;
-	}
-	return (ret);
-}
-
-/* int
- * res_nameinquery(name, type, class, buf, eom)
- *	look for (name,type,class) in the query section of packet (buf,eom)
- * requires:
- *	buf + HFIXEDSZ <= eom
- * returns:
- *	-1 : format error
- *	0  : not found
- *	>0 : found
- * author:
- *	paul vixie, 29may94
- */
-int
-res_nameinquery(name, type, class, buf, eom)
-	const char *name;
-	int type, class;
-	const u_char *buf, *eom;
-{
-	const u_char *cp = buf + HFIXEDSZ;
-	int qdcount = ntohs(((HEADER*)buf)->qdcount);
-
-	while (qdcount-- > 0) {
-		char tname[MAXDNAME+1];
-		int n, ttype, tclass;
-
-		n = dn_expand(buf, eom, cp, tname, sizeof tname);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		if (cp + 2 * INT16SZ > eom)
-			return (-1);
-		ttype = ns_get16(cp); cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
-		if (ttype == type &&
-		    tclass == class &&
-		    strcasecmp(tname, name) == 0)
-			return (1);
-	}
-	return (0);
-}
-
-/* int
- * res_queriesmatch(buf1, eom1, buf2, eom2)
- *	is there a 1:1 mapping of (name,type,class)
- *	in (buf1,eom1) and (buf2,eom2)?
- * returns:
- *	-1 : format error
- *	0  : not a 1:1 mapping
- *	>0 : is a 1:1 mapping
- * author:
- *	paul vixie, 29may94
- */
-int
-res_queriesmatch(buf1, eom1, buf2, eom2)
-	const u_char *buf1, *eom1;
-	const u_char *buf2, *eom2;
-{
-	const u_char *cp = buf1 + HFIXEDSZ;
-	int qdcount = ntohs(((HEADER*)buf1)->qdcount);
-
-	if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
-		return (-1);
-
-	/*
-	 * Only header section present in replies to
-	 * dynamic update packets.
-	 */
-	if ( (((HEADER *)buf1)->opcode == ns_o_update) &&
-	     (((HEADER *)buf2)->opcode == ns_o_update) )
-		return (1);
-
-	if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
-		return (0);
-	while (qdcount-- > 0) {
-		char tname[MAXDNAME+1];
-		int n, ttype, tclass;
-
-		n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		if (cp + 2 * INT16SZ > eom1)
-			return (-1);
-		ttype = ns_get16(cp);	cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
-		if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
-			return (0);
-	}
-	return (1);
-}
-
-int
-res_send(buf, buflen, ans, anssiz)
-	const u_char *buf;
-	int buflen;
-	u_char *ans;
-	int anssiz;
-{
-	HEADER *hp = (HEADER *) buf;
-	HEADER *anhp = (HEADER *) ans;
-	int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns, n;
-	int kq;
-	u_int badns;	/* XXX NSMAX can't exceed #/bits in this variable */
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		/* errno should have been set by res_init() in this case. */
-		return (-1);
-	}
-	if (anssiz < HFIXEDSZ) {
-		errno = EINVAL;
-		return (-1);
-	}
-	DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
-		(stdout, ";; res_send()\n"), buf, buflen);
-	v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
-	gotsomewhere = 0;
-	connreset = 0;
-	terrno = ETIMEDOUT;
-	badns = 0;
-
-	if ((kq = kqueue()) < 0) {
-		Perror(stderr, "kqueue", errno);
-		return (-1);
-	}
-
-	/*
-	 * Send request, RETRY times, or until successful
-	 */
-	for (try = 0; try < _res.retry; try++) {
-	    for (ns = 0; ns < _res.nscount; ns++) {
-		char abuf[NI_MAXHOST];
-		struct sockaddr *nsap = get_nsaddr(ns);
-		socklen_t salen;
-
-		if (nsap->sa_len)
-			salen = nsap->sa_len;
-		else if (nsap->sa_family == AF_INET6)
-			salen = sizeof(struct sockaddr_in6);
-		else if (nsap->sa_family == AF_INET)
-			salen = sizeof(struct sockaddr_in);
-		else
-			salen = 0;	/*unknown, die on connect*/
-
-    same_ns:
-		if (badns & (1 << ns)) {
-			res_close();
-			goto next_ns;
-		}
-
-		if (Qhook) {
-			int done = 0, loops = 0;
-
-			do {
-				res_sendhookact act;
-
-				act = (*Qhook)(&nsap,
-					       &buf, &buflen,
-					       ans, anssiz, &resplen);
-				switch (act) {
-				case res_goahead:
-					done = 1;
-					break;
-				case res_nextns:
-					res_close();
-					goto next_ns;
-				case res_done:
-					_close(kq);
-					return (resplen);
-				case res_modified:
-					/* give the hook another try */
-					if (++loops < 42) /*doug adams*/
-						break;
-					/*FALLTHROUGH*/
-				case res_error:
-					/*FALLTHROUGH*/
-				default:
-					_close(kq);
-					return (-1);
-				}
-			} while (!done);
-		}
-
-		Dprint((_res.options & RES_DEBUG) &&
-		       getnameinfo(nsap, salen, abuf, sizeof(abuf),
-			   NULL, 0, NI_NUMERICHOST) == 0,
-		       (stdout, ";; Querying server (# %d) address = %s\n",
-			ns + 1, abuf));
-
-		if (v_circuit) {
-			int truncated;
-			struct iovec iov[2];
-			u_short len;
-			u_char *cp;
-
-			/*
-			 * Use virtual circuit;
-			 * at most one attempt per server.
-			 */
-			try = _res.retry;
-			truncated = 0;
-			if (s < 0 || !vc || hp->opcode == ns_o_update ||
-			    af != nsap->sa_family) {
-				if (s >= 0)
-					res_close();
-
-				af = nsap->sa_family;
-				s = _socket(af, SOCK_STREAM, 0);
-				if (s < 0) {
-					terrno = errno;
-					Perror(stderr, "socket(vc)", errno);
-					badns |= (1 << ns);
-					res_close();
-					goto next_ns;
-				}
-				errno = 0;
-				if (_connect(s, nsap, salen) < 0) {
-					terrno = errno;
-					Aerror(stderr, "connect/vc",
-					       errno, nsap);
-					badns |= (1 << ns);
-					res_close();
-					goto next_ns;
-				}
-				vc = 1;
-			}
-			/*
-			 * Send length & message
-			 */
-			putshort((u_short)buflen, (u_char*)&len);
-			iov[0].iov_base = (caddr_t)&len;
-			iov[0].iov_len = INT16SZ;
-			iov[1].iov_base = (caddr_t)buf;
-			iov[1].iov_len = buflen;
-			if (_writev(s, iov, 2) != (INT16SZ + buflen)) {
-				terrno = errno;
-				Perror(stderr, "write failed", errno);
-				badns |= (1 << ns);
-				res_close();
-				goto next_ns;
-			}
-			/*
-			 * Receive length & response
-			 */
-read_len:
-			cp = ans;
-			len = INT16SZ;
-			while ((n = _read(s, (char *)cp, (int)len)) > 0) {
-				cp += n;
-				if ((len -= n) <= 0)
-					break;
-			}
-			if (n <= 0) {
-				terrno = errno;
-				Perror(stderr, "read failed", errno);
-				res_close();
-				/*
-				 * A long running process might get its TCP
-				 * connection reset if the remote server was
-				 * restarted.  Requery the server instead of
-				 * trying a new one.  When there is only one
-				 * server, this means that a query might work
-				 * instead of failing.  We only allow one reset
-				 * per query to prevent looping.
-				 */
-				if (terrno == ECONNRESET && !connreset) {
-					connreset = 1;
-					res_close();
-					goto same_ns;
-				}
-				res_close();
-				goto next_ns;
-			}
-			resplen = ns_get16(ans);
-			if (resplen > anssiz) {
-				Dprint(_res.options & RES_DEBUG,
-				       (stdout, ";; response truncated\n")
-				       );
-				truncated = 1;
-				len = anssiz;
-			} else
-				len = resplen;
-			if (len < HFIXEDSZ) {
-				/*
-				 * Undersized message.
-				 */
-				Dprint(_res.options & RES_DEBUG,
-				       (stdout, ";; undersized: %d\n", len));
-				terrno = EMSGSIZE;
-				badns |= (1 << ns);
-				res_close();
-				goto next_ns;
-			}
-			cp = ans;
-			while (len != 0 &&
-			       (n = _read(s, (char *)cp, (int)len)) > 0) {
-				cp += n;
-				len -= n;
-			}
-			if (n <= 0) {
-				terrno = errno;
-				Perror(stderr, "read(vc)", errno);
-				res_close();
-				goto next_ns;
-			}
-			if (truncated) {
-				/*
-				 * Flush rest of answer
-				 * so connection stays in synch.
-				 */
-				anhp->tc = 1;
-				len = resplen - anssiz;
-				while (len != 0) {
-					char junk[PACKETSZ];
-
-					n = (len > sizeof(junk)
-					     ? sizeof(junk)
-					     : len);
-					if ((n = _read(s, junk, n)) > 0)
-						len -= n;
-					else
-						break;
-				}
-			}
-			/*
-			 * The calling applicating has bailed out of
-			 * a previous call and failed to arrange to have
-			 * the circuit closed or the server has got
-			 * itself confused. Anyway drop the packet and
-			 * wait for the correct one.
-			 */
-			if (hp->id != anhp->id) {
-				DprintQ((_res.options & RES_DEBUG) ||
-					(_res.pfcode & RES_PRF_REPLY),
-					(stdout, ";; old answer (unexpected):\n"),
-					ans, (resplen>anssiz)?anssiz:resplen);
-				goto read_len;
-			}
-		} else {
-			/*
-			 * Use datagrams.
-			 */
-			struct kevent kv;
-			struct timespec ts;
-			struct timeval timeout, ctv;
-			struct sockaddr_storage from;
-			socklen_t fromlen;
-
-			if (s < 0 || vc || af != nsap->sa_family) {
-				if (vc)
-					res_close();
-				af = nsap->sa_family;
-				s = _socket(af, SOCK_DGRAM, 0);
-				if (s < 0) {
-#ifndef CAN_RECONNECT
- bad_dg_sock:
-#endif
-					terrno = errno;
-					Perror(stderr, "socket(dg)", errno);
-					badns |= (1 << ns);
-					res_close();
-					goto next_ns;
-				}
-				connected = 0;
-			}
-#ifndef CANNOT_CONNECT_DGRAM
-			/*
-			 * On a 4.3BSD+ machine (client and server,
-			 * actually), sending to a nameserver datagram
-			 * port with no nameserver will cause an
-			 * ICMP port unreachable message to be returned.
-			 * If our datagram socket is "connected" to the
-			 * server, we get an ECONNREFUSED error on the next
-			 * socket operation, and select returns if the
-			 * error message is received.  We can thus detect
-			 * the absence of a nameserver without timing out.
-			 * If we have sent queries to at least two servers,
-			 * however, we don't want to remain connected,
-			 * as we wish to receive answers from the first
-			 * server to respond.
-			 *
-			 * When the option "insecure1" is specified, we'd
-			 * rather expect to see responses from an "unknown"
-			 * address.  In order to let the kernel accept such
-			 * responses, do not connect the socket here.
-			 * XXX: or do we need an explicit option to disable
-			 * connecting?
-			 */
-			if (!(_res.options & RES_INSECURE1) &&
-			    (_res.nscount == 1 || (try == 0 && ns == 0))) {
-				/*
-				 * Connect only if we are sure we won't
-				 * receive a response from another server.
-				 */
-				if (!connected) {
-					if (_connect(s, nsap, salen) < 0) {
-						Aerror(stderr,
-						       "connect(dg)",
-						       errno, nsap);
-						badns |= (1 << ns);
-						res_close();
-						goto next_ns;
-					}
-					connected = 1;
-				}
-				if (send(s, (char*)buf, buflen, 0) != buflen) {
-					Perror(stderr, "send", errno);
-					badns |= (1 << ns);
-					res_close();
-					goto next_ns;
-				}
-			} else {
-				/*
-				 * Disconnect if we want to listen
-				 * for responses from more than one server.
-				 */
-				if (connected) {
-#ifdef CAN_RECONNECT
-					/* XXX: any errornous address */
-					struct sockaddr_in no_addr;
-
-					no_addr.sin_family = AF_INET;
-					no_addr.sin_addr.s_addr = INADDR_ANY;
-					no_addr.sin_port = 0;
-					(void) _connect(s,
-						       (struct sockaddr *)
-						        &no_addr,
-						       sizeof no_addr);
-#else
-					int s1 = _socket(af, SOCK_DGRAM,0);
-					if (s1 < 0)
-						goto bad_dg_sock;
-					(void)_dup2(s1, s);
-					(void)_close(s1);
-					Dprint(_res.options & RES_DEBUG,
-						(stdout, ";; new DG socket\n"))
-#endif /* CAN_RECONNECT */
-					connected = 0;
-					errno = 0;
-				}
-#endif /* !CANNOT_CONNECT_DGRAM */
-				if (_sendto(s, (char*)buf, buflen, 0,
-					   nsap, salen) != buflen) {
-					Aerror(stderr, "sendto", errno, nsap);
-					badns |= (1 << ns);
-					res_close();
-					goto next_ns;
-				}
-#ifndef CANNOT_CONNECT_DGRAM
-			}
-#endif /* !CANNOT_CONNECT_DGRAM */
-
-			/*
-			 * Wait for reply
-			 */
-
-			timeout.tv_sec = (_res.retrans << try);
-			if (try > 0)
-				timeout.tv_sec /= _res.nscount;
-			if ((long) timeout.tv_sec <= 0)
-				timeout.tv_sec = 1;
-			timeout.tv_usec = 0;
-			TIMEVAL_TO_TIMESPEC(&timeout, &ts);
-			(void) gettimeofday(&ctv, NULL);
-			timeradd(&timeout, &ctv, &timeout);
-    wait:
-			if (s < 0) {
-				Perror(stderr, "s out-of-bounds", EMFILE);
-				res_close();
-				goto next_ns;
-			}
-
-			EV_SET(&kv, s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0,0,0);
-
-			n = _kevent(kq, &kv, 1, &kv, 1, &ts);
-			if (n < 0) {
-				if (errno == EINTR) {
-					(void) gettimeofday(&ctv, NULL);
-					if (timercmp(&ctv, &timeout, <)) {
-						timersub(&timeout, &ctv, &ctv);
-						TIMEVAL_TO_TIMESPEC(&ctv, &ts);
-						goto wait;
-					}
-				}
-				Perror(stderr, "kevent", errno);
-				res_close();
-				goto next_ns;
-			}
-
-			if (n == 0) {
-				/*
-				 * timeout
-				 */
-				Dprint(_res.options & RES_DEBUG,
-				       (stdout, ";; timeout\n"));
-				gotsomewhere = 1;
-				res_close();
-				goto next_ns;
-			}
-			errno = 0;
-			fromlen = sizeof(from);
-			resplen = _recvfrom(s, (char*)ans, anssiz, 0,
-					   (struct sockaddr *)&from, &fromlen);
-			if (resplen <= 0) {
-				Perror(stderr, "recvfrom", errno);
-				res_close();
-				goto next_ns;
-			}
-			gotsomewhere = 1;
-			if (resplen < HFIXEDSZ) {
-				/*
-				 * Undersized message.
-				 */
-				Dprint(_res.options & RES_DEBUG,
-				       (stdout, ";; undersized: %d\n",
-					resplen));
-				terrno = EMSGSIZE;
-				badns |= (1 << ns);
-				res_close();
-				goto next_ns;
-			}
-			if (hp->id != anhp->id) {
-				/*
-				 * response from old query, ignore it.
-				 * XXX - potential security hazard could
-				 *	 be detected here.
-				 */
-				DprintQ((_res.options & RES_DEBUG) ||
-					(_res.pfcode & RES_PRF_REPLY),
-					(stdout, ";; old answer:\n"),
-					ans, (resplen>anssiz)?anssiz:resplen);
-				goto wait;
-			}
-#ifdef CHECK_SRVR_ADDR
-			if (!(_res.options & RES_INSECURE1) &&
-			    !res_isourserver((struct sockaddr_in *)&from)) {
-				/*
-				 * response from wrong server? ignore it.
-				 * XXX - potential security hazard could
-				 *	 be detected here.
-				 */
-				DprintQ((_res.options & RES_DEBUG) ||
-					(_res.pfcode & RES_PRF_REPLY),
-					(stdout, ";; not our server:\n"),
-					ans, (resplen>anssiz)?anssiz:resplen);
-				goto wait;
-			}
-#endif
-			if (!(_res.options & RES_INSECURE2) &&
-			    !res_queriesmatch(buf, buf + buflen,
-					      ans, ans + anssiz)) {
-				/*
-				 * response contains wrong query? ignore it.
-				 * XXX - potential security hazard could
-				 *	 be detected here.
-				 */
-				DprintQ((_res.options & RES_DEBUG) ||
-					(_res.pfcode & RES_PRF_REPLY),
-					(stdout, ";; wrong query name:\n"),
-					ans, (resplen>anssiz)?anssiz:resplen);
-				goto wait;
-			}
-			if (anhp->rcode == SERVFAIL ||
-			    anhp->rcode == NOTIMP ||
-			    anhp->rcode == REFUSED) {
-				DprintQ(_res.options & RES_DEBUG,
-					(stdout, "server rejected query:\n"),
-					ans, (resplen>anssiz)?anssiz:resplen);
-				badns |= (1 << ns);
-				res_close();
-				/* don't retry if called from dig */
-				if (!_res.pfcode)
-					goto next_ns;
-			}
-			if (!(_res.options & RES_IGNTC) && anhp->tc) {
-				/*
-				 * get rest of answer;
-				 * use TCP with same server.
-				 */
-				Dprint(_res.options & RES_DEBUG,
-				       (stdout, ";; truncated answer\n"));
-				v_circuit = 1;
-				res_close();
-				goto same_ns;
-			}
-		} /*if vc/dg*/
-		Dprint((_res.options & RES_DEBUG) ||
-		       ((_res.pfcode & RES_PRF_REPLY) &&
-			(_res.pfcode & RES_PRF_HEAD1)),
-		       (stdout, ";; got answer:\n"));
-		DprintQ((_res.options & RES_DEBUG) ||
-			(_res.pfcode & RES_PRF_REPLY),
-			(stdout, "%.*s", 0, ""),
-			ans, (resplen>anssiz)?anssiz:resplen);
-		/*
-		 * If using virtual circuits, we assume that the first server
-		 * is preferred over the rest (i.e. it is on the local
-		 * machine) and only keep that one open.
-		 * If we have temporarily opened a virtual circuit,
-		 * or if we haven't been asked to keep a socket open,
-		 * close the socket.
-		 */
-		if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
-		    !(_res.options & RES_STAYOPEN)) {
-			res_close();
-		}
-		if (Rhook) {
-			int done = 0, loops = 0;
-
-			do {
-				res_sendhookact act;
-
-				act = (*Rhook)(nsap,
-					       buf, buflen,
-					       ans, anssiz, &resplen);
-				switch (act) {
-				case res_goahead:
-				case res_done:
-					done = 1;
-					break;
-				case res_nextns:
-					res_close();
-					goto next_ns;
-				case res_modified:
-					/* give the hook another try */
-					if (++loops < 42) /*doug adams*/
-						break;
-					/*FALLTHROUGH*/
-				case res_error:
-					/*FALLTHROUGH*/
-				default:
-					_close(kq);
-					return (-1);
-				}
-			} while (!done);
-
-		}
-		_close(kq);
-		return (resplen);
-    next_ns: ;
-	   } /*foreach ns*/
-	} /*foreach retry*/
-	res_close();
-	_close(kq);
-	if (!v_circuit) {
-		if (!gotsomewhere)
-			errno = ECONNREFUSED;	/* no nameservers found */
-		else
-			errno = ETIMEDOUT;	/* no answer obtained */
-	} else
-		errno = terrno;
-	return (-1);
-}
-
-/*
- * This routine is for closing the socket if a virtual circuit is used and
- * the program wants to close it.  This provides support for endhostent()
- * which expects to close the socket.
- *
- * This routine is not expected to be user visible.
- */
-void
-res_close()
-{
-	if (s >= 0) {
-		(void)_close(s);
-		s = -1;
-		connected = 0;
-		vc = 0;
-		af = 0;
-	}
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_close
-__weak_reference(__res_close, _res_close);
-#undef res_send
-__weak_reference(__res_send, res_send);
--- lib/libc/net/addr2ascii.3
+++ /dev/null
@@ -1,235 +0,0 @@
-.\"
-.\" Copyright 1996 Massachusetts Institute of Technology
-.\"
-.\" Permission to use, copy, modify, and distribute this software and
-.\" its documentation for any purpose and without fee is hereby
-.\" granted, provided that both the above copyright notice and this
-.\" permission notice appear in all copies, that both the above
-.\" copyright notice and this permission notice appear in all
-.\" supporting documentation, and that the name of M.I.T. not be used
-.\" in advertising or publicity pertaining to distribution of the
-.\" software without specific, written prior permission.  M.I.T. makes
-.\" no representations about the suitability of this software for any
-.\" purpose.  It is provided "as is" without express or implied
-.\" warranty.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
-.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
-.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
-.\" SHALL M.I.T. 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.
-.\"
-.\"	$ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $
-.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.18 2005/01/11 20:50:49 ru Exp $
-.\"
-.Dd June 13, 1996
-.Dt ADDR2ASCII 3
-.Os
-.Sh NAME
-.Nm addr2ascii ,
-.Nm ascii2addr
-.Nd Generic address formatting routines
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In arpa/inet.h
-.Ft "char *"
-.Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf"
-.Ft int
-.Fn ascii2addr "int af" "const char *ascii" "void *result"
-.Sh DESCRIPTION
-The routines
-.Fn addr2ascii
-and
-.Fn ascii2addr
-are used to convert network addresses between binary form and a
-printable form appropriate to the address family.
-Both functions take
-an
-.Fa af
-argument, specifying the address family to be used in the conversion
-process.
-(Currently, only the
-.Dv AF_INET
-and
-.Dv AF_LINK
-address families are supported.)
-.Pp
-The
-.Fn addr2ascii
-function
-is used to convert binary, network-format addresses into printable
-form.
-In addition to
-.Fa af ,
-there are three other arguments.
-The
-.Fa addrp
-argument is a pointer to the network address to be converted.
-The
-.Fa len
-argument is the length of the address.
-The
-.Fa buf
-argument is an optional pointer to a caller-allocated buffer to hold
-the result; if a null pointer is passed,
-.Fn addr2ascii
-uses a statically-allocated buffer.
-.Pp
-The
-.Fn ascii2addr
-function performs the inverse operation to
-.Fn addr2ascii .
-In addition to
-.Fa af ,
-it takes two arguments,
-.Fa ascii
-and
-.Fa result .
-The
-.Fa ascii
-argument is a pointer to the string which is to be converted into
-binary.
-The
-.Fa result
-argument is a pointer to an appropriate network address structure for
-the specified family.
-.Pp
-The following gives the appropriate structure to use for binary
-addresses in the specified family:
-.Pp
-.Bl -tag -width AF_INETxxxx -compact
-.It Dv AF_INET
-.Vt "struct in_addr"
-(in
-.In arpa/inet.h )
-.It Dv AF_LINK
-.Vt "struct sockaddr_dl"
-(in
-.In net/if_dl.h )
-.\" .It Dv AF_INET6
-.\" .Vt "struct in6_addr"
-.\" (in
-.\" .In netinet6/in6.h )
-.El
-.Pp
-.Dv AF_INET
-and
-.Dv AF_LINK
-constants are defined in
-.In sys/socket.h .
-.Sh RETURN VALUES
-The
-.Fn addr2ascii
-function returns the address of the buffer it was passed, or a static
-buffer if the a null pointer was passed; on failure, it returns a null
-pointer.
-The
-.Fn ascii2addr
-function returns the length of the binary address in bytes, or -1 on
-failure.
-.Sh EXAMPLES
-The
-.Xr inet 3
-functions
-.Fn inet_ntoa
-and
-.Fn inet_aton
-could be implemented thusly:
-.Bd -literal -offset indent
-#include <sys/socket.h>
-#include <arpa/inet.h>
-
-char *
-inet_ntoa(struct in_addr addr)
-{
-	return addr2ascii(AF_INET, &addr, sizeof addr, 0);
-}
-
-int
-inet_aton(const char *ascii, struct in_addr *addr)
-{
-	return (ascii2addr(AF_INET, ascii, addr)
-	    == sizeof(*addr));
-}
-.Ed
-.Pp
-In actuality, this cannot be done because
-.Fn addr2ascii
-and
-.Fn ascii2addr
-are implemented in terms of the
-.Xr inet 3
-functions, rather than the other way around.
-.Sh ERRORS
-When a failure is returned,
-.Va errno
-is set to one of the following values:
-.Bl -tag -width Er
-.It Bq Er ENAMETOOLONG
-The
-.Fn addr2ascii
-routine was passed a
-.Fa len
-argument which was inappropriate for the address family given by
-.Fa af .
-.It Bq Er EPROTONOSUPPORT
-Either routine was passed an
-.Fa af
-argument other than
-.Dv AF_INET
-or
-.Dv AF_LINK .
-.It Bq Er EINVAL
-The string passed to
-.Fn ascii2addr
-was improperly formatted for address family
-.Fa af .
-.El
-.Sh SEE ALSO
-.Xr inet 3 ,
-.Xr linkaddr 3 ,
-.Xr inet 4
-.Sh HISTORY
-An interface close to this one was originally suggested by Craig
-Partridge.
-This particular interface originally appeared in the
-.Tn INRIA
-.Tn IPv6
-implementation.
-.Sh AUTHORS
-Code and documentation by
-.An Garrett A. Wollman ,
-MIT Laboratory for Computer Science.
-.Sh BUGS
-The original implementations supported IPv6.
-This support should
-eventually be resurrected.
-The
-.Tn NRL
-implementation also included support for the
-.Dv AF_ISO
-and
-.Dv AF_NS
-address families.
-.Pp
-The genericity of this interface is somewhat questionable.
-A truly
-generic interface would provide a means for determining the length of
-the buffer to be used so that it could be dynamically allocated, and
-would always require a
-.Vt "struct sockaddr"
-to hold the binary address.
-Unfortunately, this is incompatible with existing
-practice.
-This limitation means that a routine for printing network
-addresses from arbitrary address families must still have internal
-knowledge of the maximum buffer length needed and the appropriate part
-of the address to use as the binary address.
--- lib/libc/net/ns_ttl.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ns_ttl.c,v 1.4 2003/02/18 13:39:52 nectar Exp $");
-
-/* Import. */
-
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#define SPRINTF(x) ((size_t)sprintf x)
-
-/* Forward. */
-
-static int	fmt1(int t, char s, char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define T(x) if ((x) < 0) return (-1); else (void)NULL
-
-/* Public. */
-
-int
-ns_format_ttl(u_long src, char *dst, size_t dstlen) {
-	char *odst = dst;
-	int secs, mins, hours, days, weeks, x;
-	char *p;
-
-	secs = src % 60;   src /= 60;
-	mins = src % 60;   src /= 60;
-	hours = src % 24;  src /= 24;
-	days = src % 7;    src /= 7;
-	weeks = src;       src = 0;
-
-	x = 0;
-	if (weeks) {
-		T(fmt1(weeks, 'W', &dst, &dstlen));
-		x++;
-	}
-	if (days) {
-		T(fmt1(days, 'D', &dst, &dstlen));
-		x++;
-	}
-	if (hours) {
-		T(fmt1(hours, 'H', &dst, &dstlen));
-		x++;
-	}
-	if (mins) {
-		T(fmt1(mins, 'M', &dst, &dstlen));
-		x++;
-	}
-	if (secs || !(weeks || days || hours || mins)) {
-		T(fmt1(secs, 'S', &dst, &dstlen));
-		x++;
-	}
-
-	if (x > 1) {
-		int ch;
-
-		for (p = odst; (ch = *p) != '\0'; p++)
-			if (isascii(ch) && isupper(ch))
-				*p = tolower(ch);
-	}
-
-	return (dst - odst);
-}
-
-int
-ns_parse_ttl(const char *src, u_long *dst) {
-	u_long ttl, tmp;
-	int ch, digits, dirty;
-
-	ttl = 0;
-	tmp = 0;
-	digits = 0;
-	dirty = 0;
-	while ((ch = *src++) != '\0') {
-		if (!isascii(ch) || !isprint(ch))
-			goto einval;
-		if (isdigit(ch)) {
-			tmp *= 10;
-			tmp += (ch - '0');
-			digits++;
-			continue;
-		}
-		if (digits == 0)
-			goto einval;
-		if (islower(ch))
-			ch = toupper(ch);
-		switch (ch) {
-		case 'W':  tmp *= 7;
-		case 'D':  tmp *= 24;
-		case 'H':  tmp *= 60;
-		case 'M':  tmp *= 60;
-		case 'S':  break;
-		default:   goto einval;
-		}
-		ttl += tmp;
-		tmp = 0;
-		digits = 0;
-		dirty = 1;
-	}
-	if (digits > 0) {
-		if (dirty)
-			goto einval;
-		else
-			ttl += tmp;
-	}
-	*dst = ttl;
-	return (0);
-
- einval:
-	errno = EINVAL;
-	return (-1);
-}
-
-/* Private. */
-
-static int
-fmt1(int t, char s, char **buf, size_t *buflen) {
-	char tmp[50];
-	size_t len;
-
-	len = SPRINTF((tmp, "%d%c", t, s));
-	if (len + 1 > *buflen)
-		return (-1);
-	strcpy(*buf, tmp);
-	*buf += len;
-	*buflen -= len;
-	return (0);
-}
--- lib/libc/net/res_mkupdate.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Based on the Dynamic DNS reference implementation by Viraj Bais
- * <viraj_bais at ccm.fm.intel.com>
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_mkupdate.c,v 1.6 2005/04/08 21:24:23 stefanf Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <limits.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include "res_config.h"
-
-static int getnum_str(u_char **, u_char *);
-static int getword_str(char *, int, u_char **, u_char *);
-
-#define ShrinkBuffer(x)  if ((buflen -= x) < 0) return (-2);
-
-/*
- * Form update packets.
- * Returns the size of the resulting packet if no error
- * On error,
- *	returns -1 if error in reading a word/number in rdata
- *		   portion for update packets
- *		-2 if length of buffer passed is insufficient
- *		-3 if zone section is not the first section in
- *		   the linked list, or section order has a problem
- *		-4 on a number overflow
- *		-5 unknown operation or no records
- */
-int
-res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
-	ns_updrec *rrecp_start = rrecp_in;
-	HEADER *hp;
-	u_char *cp, *sp2, *startp, *endp;
-	int n, i, soanum, multiline;
-	ns_updrec *rrecp;
-	struct in_addr ina;
-        char buf2[MAXDNAME];
-	int section, numrrs = 0, counts[ns_s_max];
-	u_int16_t rtype, rclass;
-	u_int32_t n1, rttl;
-	u_char *dnptrs[20], **dpp, **lastdnptr;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-
-	/*
-	 * Initialize header fields.
-	 */
-	if ((buf == NULL) || (buflen < HFIXEDSZ))
-		return (-1);
-	memset(buf, 0, HFIXEDSZ);
-	hp = (HEADER *) buf;
-	hp->id = htons(++_res.id);
-	hp->opcode = ns_o_update;
-	hp->rcode = NOERROR;
-	cp = buf + HFIXEDSZ;
-	buflen -= HFIXEDSZ;
-	dpp = dnptrs;
-	*dpp++ = buf;
-	*dpp++ = NULL;
-	lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
-
-	if (rrecp_start == NULL)
-		return (-5);
-	else if (rrecp_start->r_section != S_ZONE)
-		return (-3);
-
-	memset(counts, 0, sizeof counts);
-	for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
-		numrrs++;
-                section = rrecp->r_section;
-		if (section < 0 || section >= ns_s_max)
-			return (-1);
-		counts[section]++;
-		for (i = section + 1; i < ns_s_max; i++)
-			if (counts[i])
-				return (-3);
-		rtype = rrecp->r_type;
-		rclass = rrecp->r_class;
-		rttl = rrecp->r_ttl;
-		/* overload class and type */
-		if (section == S_PREREQ) {
-			rttl = 0;
-			switch (rrecp->r_opcode) {
-			case YXDOMAIN:
-				rclass = C_ANY;
-				rtype = T_ANY;
-				rrecp->r_size = 0;
-				break;
-			case NXDOMAIN:
-				rclass = C_NONE;
-				rtype = T_ANY;
-				rrecp->r_size = 0;
-				break;
-			case NXRRSET:
-				rclass = C_NONE;
-				rrecp->r_size = 0;
-				break;
-			case YXRRSET:
-				if (rrecp->r_size == 0)
-					rclass = C_ANY;
-				break;
-			default:
-				fprintf(stderr,
-					"res_mkupdate: incorrect opcode: %d\n",
-					rrecp->r_opcode);
-				fflush(stderr);
-				return (-1);
-			}
-		} else if (section == S_UPDATE) {
-			switch (rrecp->r_opcode) {
-			case DELETE:
-				rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
-				break;
-			case ADD:
-				break;
-			default:
-				fprintf(stderr,
-					"res_mkupdate: incorrect opcode: %d\n",
-					rrecp->r_opcode);
-				fflush(stderr);
-				return (-1);
-			}
-		}
-
-		/*
-		 * XXX	appending default domain to owner name is omitted,
-		 *	fqdn must be provided
-		 */
-		if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
-				 lastdnptr)) < 0)
-			return (-1);
-		cp += n;
-		ShrinkBuffer(n + 2*INT16SZ);
-		PUTSHORT(rtype, cp);
-		PUTSHORT(rclass, cp);
-		if (section == S_ZONE) {
-			if (numrrs != 1 || rrecp->r_type != T_SOA)
-				return (-3);
-			continue;
-		}
-		ShrinkBuffer(INT32SZ + INT16SZ);
-		PUTLONG(rttl, cp);
-		sp2 = cp;  /* save pointer to length byte */
-		cp += INT16SZ;
-		if (rrecp->r_size == 0) {
-			if (section == S_UPDATE && rclass != C_ANY)
-				return (-1);
-			else {
-				PUTSHORT(0, sp2);
-				continue;
-			}
-		}
-		startp = rrecp->r_data;
-		endp = startp + rrecp->r_size - 1;
-		/* XXX this should be done centrally. */
-		switch (rrecp->r_type) {
-		case T_A:
-			if (!getword_str(buf2, sizeof buf2, &startp, endp))
-				return (-1);
-			if (!inet_aton(buf2, &ina))
-				return (-1);
-			n1 = ntohl(ina.s_addr);
-			ShrinkBuffer(INT32SZ);
-			PUTLONG(n1, cp);
-			break;
-		case T_CNAME:
-		case T_MB:
-		case T_MG:
-		case T_MR:
-		case T_NS:
-		case T_PTR:
-			if (!getword_str(buf2, sizeof buf2, &startp, endp))
-				return (-1);
-			n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
-			if (n < 0)
-				return (-1);
-			cp += n;
-			ShrinkBuffer(n);
-			break;
-		case T_MINFO:
-		case T_SOA:
-		case T_RP:
-			for (i = 0; i < 2; i++) {
-				if (!getword_str(buf2, sizeof buf2, &startp,
-						 endp))
-				return (-1);
-				n = dn_comp(buf2, cp, buflen,
-					    dnptrs, lastdnptr);
-				if (n < 0)
-					return (-1);
-				cp += n;
-				ShrinkBuffer(n);
-			}
-			if (rrecp->r_type == T_SOA) {
-				ShrinkBuffer(5 * INT32SZ);
-				while (isspace(*startp) || !*startp)
-					startp++;
-				if (*startp == '(') {
-					multiline = 1;
-					startp++;
-				} else
-					multiline = 0;
-				/* serial, refresh, retry, expire, minimum */
-				for (i = 0; i < 5; i++) {
-					soanum = getnum_str(&startp, endp);
-					if (soanum < 0)
-						return (-1);
-					PUTLONG(soanum, cp);
-				}
-				if (multiline) {
-					while (isspace(*startp) || !*startp)
-						startp++;
-					if (*startp != ')')
-						return (-1);
-				}
-			}
-			break;
-		case T_MX:
-		case T_AFSDB:
-		case T_RT:
-			n = getnum_str(&startp, endp);
-			if (n < 0)
-				return (-1);
-			PUTSHORT(n, cp);
-			ShrinkBuffer(INT16SZ);
-			if (!getword_str(buf2, sizeof buf2, &startp, endp))
-				return (-1);
-			n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
-			if (n < 0)
-				return (-1);
-			cp += n;
-			ShrinkBuffer(n);
-			break;
-		case T_PX:
-			n = getnum_str(&startp, endp);
-			if (n < 0)
-				return (-1);
-			PUTSHORT(n, cp);
-			ShrinkBuffer(INT16SZ);
-			for (i = 0; i < 2; i++) {
-				if (!getword_str(buf2, sizeof buf2, &startp,
-						 endp))
-					return (-1);
-				n = dn_comp(buf2, cp, buflen, dnptrs,
-					    lastdnptr);
-				if (n < 0)
-					return (-1);
-				cp += n;
-				ShrinkBuffer(n);
-			}
-			break;
-		case T_WKS:
-		case T_HINFO:
-		case T_TXT:
-		case T_X25:
-		case T_ISDN:
-		case T_NSAP:
-		case T_LOC:
-			/* XXX - more fine tuning needed here */
-			ShrinkBuffer(rrecp->r_size);
-			memcpy(cp, rrecp->r_data, rrecp->r_size);
-			cp += rrecp->r_size;
-			break;
-		default:
-			return (-1);
-		} /*switch*/
-		n = (u_int16_t)((cp - sp2) - INT16SZ);
-		PUTSHORT(n, sp2);
-	} /*for*/
-		
-	hp->qdcount = htons(counts[0]);
-	hp->ancount = htons(counts[1]);
-	hp->nscount = htons(counts[2]);
-	hp->arcount = htons(counts[3]);
-	return (cp - buf);
-}
-
-/*
- * Get a whitespace delimited word from a string (not file)
- * into buf. modify the start pointer to point after the
- * word in the string.
- */
-static int
-getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
-        char *cp;
-        int c;
- 
-        for (cp = buf; *startpp <= endp; ) {
-                c = **startpp;
-                if (isspace(c) || c == '\0') {
-                        if (cp != buf) /* trailing whitespace */
-                                break;
-                        else { /* leading whitespace */
-                                (*startpp)++;
-                                continue;
-                        }
-                }
-                (*startpp)++;
-                if (cp >= buf+size-1)
-                        break;
-                *cp++ = (u_char)c;
-        }
-        *cp = '\0';
-        return (cp != buf);
-}
-
-/*
- * Get a whitespace delimited number from a string (not file) into buf
- * update the start pointer to point after the number in the string.
- */
-static int
-getnum_str(u_char **startpp, u_char *endp) {
-        int c, n;
-        int seendigit = 0;
-        int m = 0;
-
-        for (n = 0; *startpp <= endp; ) {
-                c = **startpp;
-                if (isspace(c) || c == '\0') {
-                        if (seendigit) /* trailing whitespace */
-                                break;
-                        else { /* leading whitespace */
-                                (*startpp)++;
-                                continue;
-                        }
-                }
-                if (c == ';') {
-                        while ((*startpp <= endp) &&
-			       ((c = **startpp) != '\n'))
-					(*startpp)++;
-                        if (seendigit)
-                                break;
-                        continue;
-                }
-                if (!isdigit(c)) {
-                        if (c == ')' && seendigit) {
-                                (*startpp)--;
-                                break;
-                        }
-			return (-1);
-                }        
-                (*startpp)++;
-                n = n * 10 + (c - '0');
-                seendigit = 1;
-        }
-        return (n + m);
-}
-
-/*
- * Allocate a resource record buffer & save rr info.
- */
-ns_updrec *
-res_mkupdrec(int section, const char *dname,
-	     u_int class, u_int type, u_long ttl) {
-	ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
-
-	if (!rrecp || !(rrecp->r_dname = strdup(dname)))
-		return (NULL);
- 	rrecp->r_class = class;
-	rrecp->r_type = type;
-	rrecp->r_ttl = ttl;
-	rrecp->r_section = section;
-	return (rrecp);
-}
-
-/*
- * Free a resource record buffer created by res_mkupdrec.
- */
-void
-res_freeupdrec(ns_updrec *rrecp) {
-	/* Note: freeing r_dp is the caller's responsibility. */
-	if (rrecp->r_dname != NULL)
-		free(rrecp->r_dname);
-	free(rrecp);
-}
--- lib/libc/net/herror.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 1987, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)herror.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/herror.c,v 1.12 2004/02/25 21:03:45 green Exp $");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <netdb.h>
-#include <string.h>
-#include <unistd.h>
-#include "un-namespace.h"
-
-const char *h_errlist[] = {
-	"Resolver Error 0 (no error)",
-	"Unknown host",				/* 1 HOST_NOT_FOUND */
-	"Host name lookup failure",		/* 2 TRY_AGAIN */
-	"Unknown server error",			/* 3 NO_RECOVERY */
-	"No address associated with name",	/* 4 NO_ADDRESS */
-};
-const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
-
-/*
- * herror --
- *	print the error indicated by the h_errno value.
- */
-void
-herror(s)
-	const char *s;
-{
-	struct iovec iov[4];
-	struct iovec *v = iov;
-
-	if (s && *s) {
-		v->iov_base = (char *)s;
-		v->iov_len = strlen(s);
-		v++;
-		v->iov_base = ": ";
-		v->iov_len = 2;
-		v++;
-	}
-	v->iov_base = (char *)hstrerror(h_errno);
-	v->iov_len = strlen(v->iov_base);
-	v++;
-	v->iov_base = "\n";
-	v->iov_len = 1;
-	_writev(STDERR_FILENO, iov, (v - iov) + 1);
-}
-
-const char *
-hstrerror(err)
-	int err;
-{
-	if (err < 0)
-		return ("Resolver internal error");
-	else if (err < h_nerr)
-		return (h_errlist[err]);
-	return ("Unknown resolver error");
-}
-
-#undef h_errno
-int	h_errno;
--- lib/libc/net/inet_pton.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*	$KAME: inet_pton.c,v 1.5 2001/08/20 02:32:40 itojun Exp $	*/
-
-/* Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_pton.c,v 1.11.14.1 2005/07/29 16:10:35 ume Exp $");
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <string.h>
-#include <errno.h>
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int	inet_pton4(const char *src, u_char *dst);
-static int	inet_pton6(const char *src, u_char *dst);
-
-/* int
- * inet_pton(af, src, dst)
- *	convert from presentation format (which usually means ASCII printable)
- *	to network format (which is usually some kind of binary format).
- * return:
- *	1 if the address was valid for the specified address family
- *	0 if the address wasn't valid (`dst' is untouched in this case)
- *	-1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- *	Paul Vixie, 1996.
- */
-int
-inet_pton(int af, const char * __restrict src, void * __restrict dst)
-{
-	switch (af) {
-	case AF_INET:
-		return (inet_pton4(src, dst));
-	case AF_INET6:
-		return (inet_pton6(src, dst));
-	default:
-		errno = EAFNOSUPPORT;
-		return (-1);
-	}
-	/* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst)
- *	like inet_aton() but without all the hexadecimal and shorthand.
- * return:
- *	1 if `src' is a valid dotted quad, else 0.
- * notice:
- *	does not touch `dst' unless it's returning 1.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton4(const char *src, u_char *dst)
-{
-	static const char digits[] = "0123456789";
-	int saw_digit, octets, ch;
-	u_char tmp[NS_INADDRSZ], *tp;
-
-	saw_digit = 0;
-	octets = 0;
-	*(tp = tmp) = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr(digits, ch)) != NULL) {
-			u_int new = *tp * 10 + (pch - digits);
-
-			if (saw_digit && *tp == 0)
-				return (0);
-			if (new > 255)
-				return (0);
-			*tp = new;
-			if (! saw_digit) {
-				if (++octets > 4)
-					return (0);
-				saw_digit = 1;
-			}
-		} else if (ch == '.' && saw_digit) {
-			if (octets == 4)
-				return (0);
-			*++tp = 0;
-			saw_digit = 0;
-		} else
-			return (0);
-	}
-	if (octets < 4)
-		return (0);
-
-	memcpy(dst, tmp, NS_INADDRSZ);
-	return (1);
-}
-
-/* int
- * inet_pton6(src, dst)
- *	convert presentation level address to network order binary form.
- * return:
- *	1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- *	(1) does not touch `dst' unless it's returning 1.
- *	(2) :: in a full address is silently ignored.
- * credit:
- *	inspired by Mark Andrews.
- * author:
- *	Paul Vixie, 1996.
- */
-static int
-inet_pton6(const char *src, u_char *dst)
-{
-	static const char xdigits_l[] = "0123456789abcdef",
-			  xdigits_u[] = "0123456789ABCDEF";
-	u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
-	const char *xdigits, *curtok;
-	int ch, saw_xdigit;
-	u_int val;
-
-	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
-	endp = tp + NS_IN6ADDRSZ;
-	colonp = NULL;
-	/* Leading :: requires some special handling. */
-	if (*src == ':')
-		if (*++src != ':')
-			return (0);
-	curtok = src;
-	saw_xdigit = 0;
-	val = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-			pch = strchr((xdigits = xdigits_u), ch);
-		if (pch != NULL) {
-			val <<= 4;
-			val |= (pch - xdigits);
-			if (val > 0xffff)
-				return (0);
-			saw_xdigit = 1;
-			continue;
-		}
-		if (ch == ':') {
-			curtok = src;
-			if (!saw_xdigit) {
-				if (colonp)
-					return (0);
-				colonp = tp;
-				continue;
-			}
-			if (tp + NS_INT16SZ > endp)
-				return (0);
-			*tp++ = (u_char) (val >> 8) & 0xff;
-			*tp++ = (u_char) val & 0xff;
-			saw_xdigit = 0;
-			val = 0;
-			continue;
-		}
-		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
-		    inet_pton4(curtok, tp) > 0) {
-			tp += NS_INADDRSZ;
-			saw_xdigit = 0;
-			break;	/* '\0' was seen by inet_pton4(). */
-		}
-		return (0);
-	}
-	if (saw_xdigit) {
-		if (tp + NS_INT16SZ > endp)
-			return (0);
-		*tp++ = (u_char) (val >> 8) & 0xff;
-		*tp++ = (u_char) val & 0xff;
-	}
-	if (colonp != NULL) {
-		/*
-		 * Since some memmove()'s erroneously fail to handle
-		 * overlapping regions, we'll do the shift by hand.
-		 */
-		const int n = tp - colonp;
-		int i;
-
-		if (tp == endp)
-			return (0);
-		for (i = 1; i <= n; i++) {
-			endp[- i] = colonp[n - i];
-			colonp[n - i] = 0;
-		}
-		tp = endp;
-	}
-	if (tp != endp)
-		return (0);
-	memcpy(dst, tmp, NS_IN6ADDRSZ);
-	return (1);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_pton
-__weak_reference(__inet_pton, inet_pton);
--- lib/libc/net/inet_net_ntop.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char orig_rcsid[] = "From Id: inet_net_ntop.c,v 1.1.2.1.8.1 2004/03/09 08:33:32 marka Exp";
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_ntop.c,v 1.7.14.1 2006/03/06 14:53:51 ume Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-static char *	inet_net_ntop_ipv4(const u_char *src, int bits, char *dst,
-		    size_t size);
-static char *	inet_net_ntop_ipv6(const u_char *src, int bits, char *dst,
-		    size_t size);
-
-/*
- * char *
- * inet_net_ntop(af, src, bits, dst, size)
- *	convert network number from network to presentation format.
- *	generates CIDR style result always.
- * return:
- *	pointer to dst, or NULL if an error occurred (check errno).
- * author:
- *	Paul Vixie (ISC), July 1996
- */
-char *
-inet_net_ntop(af, src, bits, dst, size)
-	int af;
-	const void *src;
-	int bits;
-	char *dst;
-	size_t size;
-{
-	switch (af) {
-	case AF_INET:
-		return (inet_net_ntop_ipv4(src, bits, dst, size));
-	case AF_INET6:
-		return (inet_net_ntop_ipv6(src, bits, dst, size));
-	default:
-		errno = EAFNOSUPPORT;
-		return (NULL);
-	}
-}
-
-/*
- * static char *
- * inet_net_ntop_ipv4(src, bits, dst, size)
- *	convert IPv4 network number from network to presentation format.
- *	generates CIDR style result always.
- * return:
- *	pointer to dst, or NULL if an error occurred (check errno).
- * note:
- *	network byte order assumed.  this means 192.5.5.240/28 has
- *	0b11110000 in its fourth octet.
- * author:
- *	Paul Vixie (ISC), July 1996
- */
-static char *
-inet_net_ntop_ipv4(src, bits, dst, size)
-	const u_char *src;
-	int bits;
-	char *dst;
-	size_t size;
-{
-	char *odst = dst;
-	char *t;
-	u_int m;
-	int b;
-
-	if (bits < 0 || bits > 32) {
-		errno = EINVAL;
-		return (NULL);
-	}
-
-	if (bits == 0) {
-		if (size < sizeof "0")
-			goto emsgsize;
-		*dst++ = '0';
-		size--;
-		*dst = '\0';
-	}
-
-	/* Format whole octets. */
-	for (b = bits / 8; b > 0; b--) {
-		if (size <= sizeof "255.")
-			goto emsgsize;
-		t = dst;
-		dst += SPRINTF((dst, "%u", *src++));
-		if (b > 1) {
-			*dst++ = '.';
-			*dst = '\0';
-		}
-		size -= (size_t)(dst - t);
-	}
-
-	/* Format partial octet. */
-	b = bits % 8;
-	if (b > 0) {
-		if (size <= sizeof ".255")
-			goto emsgsize;
-		t = dst;
-		if (dst != odst)
-			*dst++ = '.';
-		m = ((1 << b) - 1) << (8 - b);
-		dst += SPRINTF((dst, "%u", *src & m));
-		size -= (size_t)(dst - t);
-	}
-
-	/* Format CIDR /width. */
-	if (size <= sizeof "/32")
-		goto emsgsize;
-	dst += SPRINTF((dst, "/%u", bits));
-	return (odst);
-
- emsgsize:
-	errno = EMSGSIZE;
-	return (NULL);
-}
-
-/*
- * static char *
- * inet_net_ntop_ipv6(src, bits, fakebits, dst, size)
- *	convert IPv6 network number from network to presentation format.
- *	generates CIDR style result always. Picks the shortest representation
- *	unless the IP is really IPv4.
- *	always prints specified number of bits (bits).
- * return:
- *	pointer to dst, or NULL if an error occurred (check errno).
- * note:
- *	network byte order assumed.  this means 192.5.5.240/28 has
- *	0b11110000 in its fourth octet.
- * author:
- *	Vadim Kogan (UCB), June 2001
- *  Original version (IPv4) by Paul Vixie (ISC), July 1996
- */
-
-static char *
-inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) {
-	u_int	m;
-	int	b;
-	int	p;
-	int	zero_s, zero_l, tmp_zero_s, tmp_zero_l;
-	int	i;
-	int	is_ipv4 = 0;
-	unsigned char inbuf[16];
-	char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
-	char	*cp;
-	int	words;
-	u_char	*s;
-
-	if (bits < 0 || bits > 128) {
-		errno = EINVAL;
-		return (NULL);
-	}
-
-	cp = outbuf;
-
-	if (bits == 0) {
-		*cp++ = ':';
-		*cp++ = ':';
-		*cp = '\0';
-	} else {
-		/* Copy src to private buffer.  Zero host part. */
-		p = (bits + 7) / 8;
-		memcpy(inbuf, src, p);
-		memset(inbuf + p, 0, 16 - p);
-		b = bits % 8;
-		if (b != 0) {
-			m = ~0 << (8 - b);
-			inbuf[p-1] &= m;
-		}
-
-		s = inbuf;
-
-		/* how many words need to be displayed in output */
-		words = (bits + 15) / 16;
-		if (words == 1)
-			words = 2;
-
-		/* Find the longest substring of zero's */
-		zero_s = zero_l = tmp_zero_s = tmp_zero_l = 0;
-		for (i = 0; i < (words * 2); i += 2) {
-			if ((s[i] | s[i+1]) == 0) {
-				if (tmp_zero_l == 0)
-					tmp_zero_s = i / 2;
-				tmp_zero_l++;
-			} else {
-				if (tmp_zero_l && zero_l < tmp_zero_l) {
-					zero_s = tmp_zero_s;
-					zero_l = tmp_zero_l;
-					tmp_zero_l = 0;
-				}
-			}
-		}
-
-		if (tmp_zero_l && zero_l < tmp_zero_l) {
-			zero_s = tmp_zero_s;
-			zero_l = tmp_zero_l;
-		}
-
-		if (zero_l != words && zero_s == 0 && ((zero_l == 6) ||
-		    ((zero_l == 5 && s[10] == 0xff && s[11] == 0xff) ||
-		    ((zero_l == 7 && s[14] != 0 && s[15] != 1)))))
-			is_ipv4 = 1;
-
-		/* Format whole words. */
-		for (p = 0; p < words; p++) {
-			if (zero_l != 0 && p >= zero_s && p < zero_s + zero_l) {
-				/* Time to skip some zeros */
-				if (p == zero_s)
-					*cp++ = ':';
-				if (p == words - 1)
-					*cp++ = ':';
-				s++;
-				s++;
-				continue;
-			}
-
-			if (is_ipv4 && p > 5 ) {
-				*cp++ = (p == 6) ? ':' : '.';
-				cp += SPRINTF((cp, "%u", *s++));
-				/* we can potentially drop the last octet */
-				if (p != 7 || bits > 120) {
-					*cp++ = '.';
-					cp += SPRINTF((cp, "%u", *s++));
-				}
-			} else {
-				if (cp != outbuf)
-					*cp++ = ':';
-				cp += SPRINTF((cp, "%x", *s * 256 + s[1]));
-				s += 2;
-			}
-		}
-	}
-	/* Format CIDR /width. */
-	SPRINTF((cp, "/%u", bits));
-	if (strlen(outbuf) + 1 > size)
-		goto emsgsize;
-	strcpy(dst, outbuf);
-
-	return (dst);
-
-emsgsize:
-	errno = EMSGSIZE;
-	return (NULL);
-}
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_net_ntop
-__weak_reference(__inet_net_ntop, inet_net_ntop);
--- lib/libc/net/inet_ntop.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/* Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$Id: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_ntop.c,v 1.12 2002/09/06 11:23:49 tjr Exp $");
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size);
-static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
-
-/* char *
- * inet_ntop(af, src, dst, size)
- *	convert a network format address to presentation format.
- * return:
- *	pointer to presentation format address (`dst'), or NULL (see errno).
- * author:
- *	Paul Vixie, 1996.
- */
-const char *
-inet_ntop(int af, const void * __restrict src, char * __restrict dst,
-    socklen_t size)
-{
-	switch (af) {
-	case AF_INET:
-		return (inet_ntop4(src, dst, size));
-	case AF_INET6:
-		return (inet_ntop6(src, dst, size));
-	default:
-		errno = EAFNOSUPPORT;
-		return (NULL);
-	}
-	/* NOTREACHED */
-}
-
-/* const char *
- * inet_ntop4(src, dst, size)
- *	format an IPv4 address, more or less like inet_ntoa()
- * return:
- *	`dst' (as a const)
- * notes:
- *	(1) uses no statics
- *	(2) takes a u_char* not an in_addr as input
- * author:
- *	Paul Vixie, 1996.
- */
-static const char *
-inet_ntop4(const u_char *src, char *dst, socklen_t size)
-{
-	static const char fmt[] = "%u.%u.%u.%u";
-
-	if ((socklen_t)snprintf(dst, size, fmt, src[0], src[1], src[2], src[3])
-	    >= size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
-	return (dst);
-}
-
-/* const char *
- * inet_ntop6(src, dst, size)
- *	convert IPv6 binary address into presentation (printable) format
- * author:
- *	Paul Vixie, 1996.
- */
-static const char *
-inet_ntop6(const u_char *src, char *dst, socklen_t size)
-{
-	/*
-	 * Note that int32_t and int16_t need only be "at least" large enough
-	 * to contain a value of the specified size.  On some systems, like
-	 * Crays, there is no such thing as an integer variable with 16 bits.
-	 * Keep this in mind if you think this function should have been coded
-	 * to use pointer overlays.  All the world's not a VAX.
-	 */
-	char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
-	struct { int base, len; } best, cur;
-	u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
-	int i;
-
-	/*
-	 * Preprocess:
-	 *	Copy the input (bytewise) array into a wordwise array.
-	 *	Find the longest run of 0x00's in src[] for :: shorthanding.
-	 */
-	memset(words, '\0', sizeof words);
-	for (i = 0; i < NS_IN6ADDRSZ; i++)
-		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
-	best.base = -1;
-	cur.base = -1;
-	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
-		if (words[i] == 0) {
-			if (cur.base == -1)
-				cur.base = i, cur.len = 1;
-			else
-				cur.len++;
-		} else {
-			if (cur.base != -1) {
-				if (best.base == -1 || cur.len > best.len)
-					best = cur;
-				cur.base = -1;
-			}
-		}
-	}
-	if (cur.base != -1) {
-		if (best.base == -1 || cur.len > best.len)
-			best = cur;
-	}
-	if (best.base != -1 && best.len < 2)
-		best.base = -1;
-
-	/*
-	 * Format the result.
-	 */
-	tp = tmp;
-	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
-		/* Are we inside the best run of 0x00's? */
-		if (best.base != -1 && i >= best.base &&
-		    i < (best.base + best.len)) {
-			if (i == best.base)
-				*tp++ = ':';
-			continue;
-		}
-		/* Are we following an initial run of 0x00s or any real hex? */
-		if (i != 0)
-			*tp++ = ':';
-		/* Is this address an encapsulated IPv4? */
-		if (i == 6 && best.base == 0 &&
-		    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
-			if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
-				return (NULL);
-			tp += strlen(tp);
-			break;
-		}
-		tp += sprintf(tp, "%x", words[i]);
-	}
-	/* Was it a trailing run of 0x00's? */
-	if (best.base != -1 && (best.base + best.len) ==
-	    (NS_IN6ADDRSZ / NS_INT16SZ))
-		*tp++ = ':';
-	*tp++ = '\0';
-
-	/*
-	 * Check for overflow, copy, and we're done.
-	 */
-	if ((socklen_t)(tp - tmp) > size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
-	strcpy(dst, tmp);
-	return (dst);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_ntop
-__weak_reference(__inet_ntop, inet_ntop);
--- lib/libc/net/ascii2addr.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 1996 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that both the above copyright notice and this
- * permission notice appear in all copies, that both the above
- * copyright notice and this permission notice appear in all
- * supporting documentation, and that the name of M.I.T. not be used
- * in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  M.I.T. makes
- * no representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied
- * warranty.
- * 
- * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
- * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
- * SHALL M.I.T. 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.
- *
- *	$ANA: ascii2addr.c,v 1.2 1996/06/13 18:46:02 wollman Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ascii2addr.c,v 1.4 2002/03/22 21:52:28 obrien Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include <net/if_dl.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-int
-ascii2addr(af, ascii, result)
-	int af;
-	const char *ascii;
-	void *result;
-{
-	struct in_addr *ina;
-	char strbuf[4*sizeof("123")]; /* long enough for V4 only */
-
-	switch(af) {
-	case AF_INET:
-		ina = result;
-		strbuf[0] = '\0';
-		strncat(strbuf, ascii, (sizeof strbuf)-1);
-		if (inet_aton(strbuf, ina))
-			return sizeof(struct in_addr);
-		errno = EINVAL;
-		break;
-
-	case AF_LINK:
-		link_addr(ascii, result);
-		/* oops... no way to detect failure */
-		return sizeof(struct sockaddr_dl);
-
-	default:
-		errno = EPROTONOSUPPORT;
-		break;
-	}
-
-	return -1;
-}
--- lib/libc/net/ns_netint.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ns_netint.c,v 1.3 2002/03/22 21:52:29 obrien Exp $");
-
-/* Import. */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-u_int
-ns_get16(const u_char *src) {
-	u_int dst;
-
-	NS_GET16(dst, src);
-	return (dst);
-}
-
-u_long
-ns_get32(const u_char *src) {
-	u_long dst;
-
-	NS_GET32(dst, src);
-	return (dst);
-}
-
-void
-ns_put16(u_int src, u_char *dst) {
-	NS_PUT16(src, dst);
-}
-
-void
-ns_put32(u_long src, u_char *dst) {
-	NS_PUT32(src, dst);
-}
--- lib/libc/net/inet_network.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_network.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_network.c,v 1.9 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-
-/*
- * Internet network address interpretation routine.
- * The library routines call this routine to interpret
- * network numbers.
- */
-in_addr_t
-inet_network(cp)
-	const char *cp;
-{
-	in_addr_t val, base, n;
-	char c;
-	in_addr_t parts[4], *pp = parts;
-	int i;
-
-again:
-	val = 0; base = 10;
-	if (*cp == '0')
-		base = 8, cp++;
-	if (*cp == 'x' || *cp == 'X')
-		base = 16, cp++;
-	while ((c = *cp) != 0) {
-		if (isdigit((unsigned char)c)) {
-			val = (val * base) + (c - '0');
-			cp++;
-			continue;
-		}
-		if (base == 16 && isxdigit((unsigned char)c)) {
-			val = (val << 4) + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
-			cp++;
-			continue;
-		}
-		break;
-	}
-	if (*cp == '.') {
-		if (pp >= parts + 3)
-			return (INADDR_NONE);
-		*pp++ = val, cp++;
-		goto again;
-	}
-	if (*cp && !isspace((unsigned char)*cp))
-		return (INADDR_NONE);
-	*pp++ = val;
-	n = pp - parts;
-	for (val = 0, i = 0; i < n; i++) {
-		val <<= 8;
-		val |= parts[i] & 0xff;
-	}
-	return (val);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_network
-__weak_reference(__inet_network, inet_network);
--- lib/libc/net/getservbyname.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyname.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/getservbyname.c,v 1.7 2005/04/18 18:34:58 ume Exp $");
-
-#include <netdb.h>
-#include <string.h>
-#include "netdb_private.h"
-
-int
-getservbyname_r(const char *name, const char *proto, struct servent *se,
-    struct servent_data *sed)
-{
-	char **cp;
-	int error;
-
-#ifdef YP
-	sed->yp_name = (char *)name;
-	sed->yp_proto = (char *)proto;
-#endif
-
-	setservent_r(sed->stayopen, sed);
-	while ((error = getservent_r(se, sed)) == 0) {
-		if (strcmp(name, se->s_name) == 0)
-			goto gotname;
-		for (cp = se->s_aliases; *cp; cp++)
-			if (strcmp(name, *cp) == 0)
-				goto gotname;
-		continue;
-gotname:
-		if (proto == 0 || strcmp(se->s_proto, proto) == 0)
-			break;
-	}
-	if (!sed->stayopen)
-		endservent_r(sed);
-
-#ifdef YP
-	sed->yp_name = NULL;
-	sed->yp_proto = NULL;
-#endif
-
-	return (error);
-}
-
-struct servent *
-getservbyname(const char *name, const char *proto)
-{
-	struct servdata *sd;
-
-	if ((sd = __servdata_init()) == NULL)
-		return (NULL);
-	if (getservbyname_r(name, proto, &sd->serv, &sd->data) != 0)
-		return (NULL);
-	return (&sd->serv);
-}
--- lib/libc/net/ns_print.c
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ns_print.c,v 1.3 2002/03/22 21:52:29 obrien Exp $");
-
-/* Import. */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-#include <ctype.h>
-
-#define SPRINTF(x) ((size_t)sprintf x)
-
-/* Forward. */
-
-static size_t	prune_origin(const char *name, const char *origin);
-static int	charstr(const u_char *rdata, const u_char *edata,
-			char **buf, size_t *buflen);
-static int	addname(const u_char *msg, size_t msglen,
-			const u_char **p, const char *origin,
-			char **buf, size_t *buflen);
-static void	addlen(size_t len, char **buf, size_t *buflen);
-static int	addstr(const char *src, size_t len,
-		       char **buf, size_t *buflen);
-static int	addtab(size_t len, size_t target, int spaced,
-		       char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define	T(x) \
-	do { \
-		if ((x) < 0) \
-			return (-1); \
-	} while (0)
-
-/* Public. */
-
-/*
- * int
- * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
- *	Convert an RR to presentation format.
- * return:
- *	Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
-	    const char *name_ctx, const char *origin,
-	    char *buf, size_t buflen)
-{
-	int n;
-
-	n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
-			 ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
-			 ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
-			 name_ctx, origin, buf, buflen);
-	return (n);
-}
-
-/*
- * int
- * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
- *	       name_ctx, origin, buf, buflen)
- *	Convert the fields of an RR into presentation format.
- * return:
- *	Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrrf(const u_char *msg, size_t msglen,
-	    const char *name, ns_class class, ns_type type,
-	    u_long ttl, const u_char *rdata, size_t rdlen,
-	    const char *name_ctx, const char *origin,
-	    char *buf, size_t buflen)
-{
-	const char *obuf = buf;
-	const u_char *edata = rdata + rdlen;
-	int spaced = 0;
-
-	const char *comment;
-	char tmp[100];
-	int len, x;
-
-	/*
-	 * Owner.
-	 */
-	if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) {
-		T(addstr("\t\t\t", 3, &buf, &buflen));
-	} else {
-		len = prune_origin(name, origin);
-		if (len == 0) {
-			T(addstr("@\t\t\t", 4, &buf, &buflen));
-		} else {
-			T(addstr(name, len, &buf, &buflen));
-			/* Origin not used and no trailing dot? */
-			if ((!origin || !origin[0] || name[len] == '\0') &&
-			    name[len - 1] != '.') {
-				T(addstr(".", 1, &buf, &buflen));
-				len++;
-			}
-			T(spaced = addtab(len, 24, spaced, &buf, &buflen));
-		}
-	}
-
-	/*
-	 * TTL, Class, Type.
-	 */
-	T(x = ns_format_ttl(ttl, buf, buflen));
-	addlen(x, &buf, &buflen);
-	len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
-	T(addstr(tmp, len, &buf, &buflen));
-	T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
-
-	/*
-	 * RData.
-	 */
-	switch (type) {
-	case ns_t_a:
-		if (rdlen != NS_INADDRSZ)
-			goto formerr;
-		(void) inet_ntop(AF_INET, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		break;
-
-	case ns_t_cname:
-	case ns_t_mb:
-	case ns_t_mg:
-	case ns_t_mr:
-	case ns_t_ns:
-	case ns_t_ptr:
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-
-	case ns_t_hinfo:
-	case ns_t_isdn:
-		/* First word. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Second word. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		break;
-
-	case ns_t_soa: {
-		u_long t;
-
-		/* Server name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Administrator name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" (\n", 3, &buf, &buflen));
-		spaced = 0;
-
-		if ((edata - rdata) != 5*NS_INT32SZ)
-			goto formerr;
-
-		/* Serial number. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
-		len = SPRINTF((tmp, "%lu", t));
-		T(addstr(tmp, len, &buf, &buflen));
-		T(spaced = addtab(len, 16, spaced, &buf, &buflen));
-		T(addstr("; serial\n", 9, &buf, &buflen));
-		spaced = 0;
-
-		/* Refresh interval. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen(len, &buf, &buflen);
-		T(spaced = addtab(len, 16, spaced, &buf, &buflen));
-		T(addstr("; refresh\n", 10, &buf, &buflen));
-		spaced = 0;
-
-		/* Retry interval. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen(len, &buf, &buflen);
-		T(spaced = addtab(len, 16, spaced, &buf, &buflen));
-		T(addstr("; retry\n", 8, &buf, &buflen));
-		spaced = 0;
-
-		/* Expiry. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen(len, &buf, &buflen);
-		T(spaced = addtab(len, 16, spaced, &buf, &buflen));
-		T(addstr("; expiry\n", 9, &buf, &buflen));
-		spaced = 0;
-
-		/* Minimum TTL. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
-		T(len = ns_format_ttl(t, buf, buflen));
-		addlen(len, &buf, &buflen);
-		T(addstr(" )", 2, &buf, &buflen));
-		T(spaced = addtab(len, 16, spaced, &buf, &buflen));
-		T(addstr("; minimum\n", 10, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_mx:
-	case ns_t_afsdb:
-	case ns_t_rt: {
-		u_int t;
-
-		if (rdlen < NS_INT16SZ)
-			goto formerr;
-
-		/* Priority. */
-		t = ns_get16(rdata);
-		rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", t));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Target. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_px: {
-		u_int t;
-
-		if (rdlen < NS_INT16SZ)
-			goto formerr;
-
-		/* Priority. */
-		t = ns_get16(rdata);
-		rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", t));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Name1. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Name2. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_x25:
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		break;
-
-	case ns_t_txt:
-		while (rdata < edata) {
-			T(len = charstr(rdata, edata, &buf, &buflen));
-			if (len == 0)
-				goto formerr;
-			rdata += len;
-			if (rdata < edata)
-				T(addstr(" ", 1, &buf, &buflen));
-		}
-		break;
-
-	case ns_t_nsap: {
-		char t[255*3];
-
-		(void) inet_nsap_ntoa(rdlen, rdata, t);
-		T(addstr(t, strlen(t), &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_aaaa:
-		if (rdlen != NS_IN6ADDRSZ)
-			goto formerr;
-		(void) inet_ntop(AF_INET6, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		break;
-
-	case ns_t_loc: {
-		char t[255];
-
-		/* XXX protocol format checking? */
-		(void) loc_ntoa(rdata, t);
-		T(addstr(t, strlen(t), &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_naptr: {
-		u_int order, preference;
-		char t[50];
-
-		if (rdlen < 2*NS_INT16SZ)
-			goto formerr;
-
-		/* Order, Precedence. */
-		order = ns_get16(rdata);	rdata += NS_INT16SZ;
-		preference = ns_get16(rdata);	rdata += NS_INT16SZ;
-		len = SPRINTF((t, "%u %u ", order, preference));
-		T(addstr(t, len, &buf, &buflen));
-
-		/* Flags. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Service. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Regexp. */
-		T(len = charstr(rdata, edata, &buf, &buflen));
-		if (len < 0)
-			return (-1);
-		if (len == 0)
-			goto formerr;
-		rdata += len;
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Server. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_srv: {
-		u_int priority, weight, port;
-		char t[50];
-
-		if (rdlen < NS_INT16SZ*3)
-			goto formerr;
-
-		/* Priority, Weight, Port. */
-		priority = ns_get16(rdata);  rdata += NS_INT16SZ;
-		weight   = ns_get16(rdata);  rdata += NS_INT16SZ;
-		port     = ns_get16(rdata);  rdata += NS_INT16SZ;
-		len = SPRINTF((t, "%u %u %u ", priority, weight, port));
-		T(addstr(t, len, &buf, &buflen));
-
-		/* Server. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		break;
-	    }
-
-	case ns_t_minfo:
-	case ns_t_rp:
-		/* Name1. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-		T(addstr(" ", 1, &buf, &buflen));
-
-		/* Name2. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		break;
-
-	case ns_t_wks: {
-		int n, lcnt;
-
-		if (rdlen < NS_INT32SZ + 1)
-			goto formerr;
-
-		/* Address. */
-		(void) inet_ntop(AF_INET, rdata, buf, buflen);
-		addlen(strlen(buf), &buf, &buflen);
-		rdata += NS_INADDRSZ;
-
-		/* Protocol. */
-		len = SPRINTF((tmp, " %u ( ", *rdata));
-		T(addstr(tmp, len, &buf, &buflen));
-		rdata += NS_INT8SZ;
-
-		/* Bit map. */
-		n = 0;
-		lcnt = 0;
-		while (rdata < edata) {
-			u_int c = *rdata++;
-			do {
-				if (c & 0200) {
-					if (lcnt == 0) {
-						T(addstr("\n\t\t\t\t", 5,
-							 &buf, &buflen));
-						lcnt = 10;
-						spaced = 0;
-					}
-					len = SPRINTF((tmp, "%d ", n));
-					T(addstr(tmp, len, &buf, &buflen));
-					lcnt--;
-				}
-				c <<= 1;
-			} while (++n & 07);
-		}
-		T(addstr(")", 1, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_key: {
-		char base64_key[NS_MD5RSA_MAX_BASE64];
-		u_int keyflags, protocol, algorithm;
-		const char *leader;
-		int n;
-
-		if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
-			goto formerr;
-
-		/* Key flags, Protocol, Algorithm. */
-		keyflags = ns_get16(rdata);  rdata += NS_INT16SZ;
-		protocol = *rdata++;
-		algorithm = *rdata++;
-		len = SPRINTF((tmp, "0x%04x %u %u",
-			       keyflags, protocol, algorithm));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Public key data. */
-		len = b64_ntop(rdata, edata - rdata,
-			       base64_key, sizeof base64_key);
-		if (len < 0)
-			goto formerr;
-		if (len > 15) {
-			T(addstr(" (", 2, &buf, &buflen));
-			leader = "\n\t\t";
-			spaced = 0;
-		} else
-			leader = " ";
-		for (n = 0; n < len; n += 48) {
-			T(addstr(leader, strlen(leader), &buf, &buflen));
-			T(addstr(base64_key + n, MIN(len - n, 48),
-				 &buf, &buflen));
-		}
-		if (len > 15)
-			T(addstr(" )", 2, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_sig: {
-		char base64_key[NS_MD5RSA_MAX_BASE64];
-		u_int type, algorithm, labels, footprint;
-		const char *leader;
-		u_long t;
-		int n;
-
-		if (rdlen < 22)
-			goto formerr;
-
-		/* Type covered, Algorithm, Label count, Original TTL. */
-	        type = ns_get16(rdata);  rdata += NS_INT16SZ;
-		algorithm = *rdata++;
-		labels = *rdata++;
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, " %s %d %lu ",
-			       p_type(type), algorithm, t));
-		T(addstr(tmp, len, &buf, &buflen));
-		if (labels != (u_int)dn_count_labels(name))
-			goto formerr;
-
-		/* Signature expiry. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Time signed. */
-		t = ns_get32(rdata);  rdata += NS_INT32SZ;
-		len = SPRINTF((tmp, "%s ", p_secstodate(t)));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Signature Footprint. */
-		footprint = ns_get16(rdata);  rdata += NS_INT16SZ;
-		len = SPRINTF((tmp, "%u ", footprint));
-		T(addstr(tmp, len, &buf, &buflen));
-
-		/* Signer's name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		/* Signature. */
-		len = b64_ntop(rdata, edata - rdata,
-			       base64_key, sizeof base64_key);
-		if (len > 15) {
-			T(addstr(" (", 2, &buf, &buflen));
-			leader = "\n\t\t";
-			spaced = 0;
-		} else
-			leader = " ";
-		if (len < 0)
-			goto formerr;
-		for (n = 0; n < len; n += 48) {
-			T(addstr(leader, strlen(leader), &buf, &buflen));
-			T(addstr(base64_key + n, MIN(len - n, 48),
-				 &buf, &buflen));
-		}
-		if (len > 15)
-			T(addstr(" )", 2, &buf, &buflen));
-
-		break;
-	    }
-
-	case ns_t_nxt: {
-		int n, c;
-
-		/* Next domain name. */
-		T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
-		/* Type bit map. */
-		n = edata - rdata;
-		for (c = 0; c < n*8; c++)
-			if (NS_NXT_BIT_ISSET(c, rdata)) {
-				len = SPRINTF((tmp, " %s", p_type(c)));
-				T(addstr(tmp, len, &buf, &buflen));
-			}
-		break;
-	    }
-
-	default:
-		comment = "unknown RR type";
-		goto hexify;
-	}
-	return (buf - obuf);
- formerr:
-	comment = "RR format error";
- hexify: {
-	int n, m;
-	char *p;
-
-	len = SPRINTF((tmp, "\\#(\t\t; %s", comment));
-	T(addstr(tmp, len, &buf, &buflen));
-	while (rdata < edata) {
-		p = tmp;
-		p += SPRINTF((p, "\n\t"));
-		spaced = 0;
-		n = MIN(16, edata - rdata);
-		for (m = 0; m < n; m++)
-			p += SPRINTF((p, "%02x ", rdata[m]));
-		T(addstr(tmp, p - tmp, &buf, &buflen));
-		if (n < 16) {
-			T(addstr(")", 1, &buf, &buflen));
-			T(addtab(p - tmp + 1, 48, spaced, &buf, &buflen));
-		}
-		p = tmp;
-		p += SPRINTF((p, "; "));
-		for (m = 0; m < n; m++)
-			*p++ = (isascii(rdata[m]) && isprint(rdata[m]))
-				? rdata[m]
-				: '.';
-		T(addstr(tmp, p - tmp, &buf, &buflen));
-		rdata += n;
-	}
-	return (buf - obuf);
-    }
-}
-
-/* Private. */
-
-/*
- * size_t
- * prune_origin(name, origin)
- *	Find out if the name is at or under the current origin.
- * return:
- *	Number of characters in name before start of origin,
- *	or length of name if origin does not match.
- * notes:
- *	This function should share code with samedomain().
- */
-static size_t
-prune_origin(const char *name, const char *origin) {
-	const char *oname = name;
-
-	while (*name != '\0') {
-		if (origin != NULL && strcasecmp(name, origin) == 0)
-			return (name - oname - (name > oname));
-		while (*name != '\0') {
-			if (*name == '\\') {
-				name++;
-				/* XXX need to handle \nnn form. */
-				if (*name == '\0')
-					break;
-			} else if (*name == '.') {
-				name++;
-				break;
-			}
-			name++;
-		}
-	}
-	return (name - oname);
-}
-
-/*
- * int
- * charstr(rdata, edata, buf, buflen)
- *	Format a <character-string> into the presentation buffer.
- * return:
- *	Number of rdata octets consumed
- *	0 for protocol format error
- *	-1 for output buffer error
- * side effects:
- *	buffer is advanced on success.
- */
-static int
-charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
-	const u_char *odata = rdata;
-	size_t save_buflen = *buflen;
-	char *save_buf = *buf;
-
-	if (addstr("\"", 1, buf, buflen) < 0)
-		goto enospc;
-	if (rdata < edata) {
-		int n = *rdata;
-
-		if (rdata + 1 + n <= edata) {
-			rdata++;
-			while (n-- > 0) {
-				if (strchr("\n\"\\", *rdata) != NULL)
-					if (addstr("\\", 1, buf, buflen) < 0)
-						goto enospc;
-				if (addstr((const char *)rdata, 1,
-					   buf, buflen) < 0)
-					goto enospc;
-				rdata++;
-			}
-		}
-	}
-	if (addstr("\"", 1, buf, buflen) < 0)
-		goto enospc;
-	return (rdata - odata);
- enospc:
-	errno = ENOSPC;
-	*buf = save_buf;
-	*buflen = save_buflen;
-	return (-1);
-}
-
-static int
-addname(const u_char *msg, size_t msglen,
-	const u_char **pp, const char *origin,
-	char **buf, size_t *buflen)
-{
-	size_t newlen, save_buflen = *buflen;
-	char *save_buf = *buf;
-	int n;
-
-	n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen);
-	if (n < 0)
-		goto enospc;	/* Guess. */
-	newlen = prune_origin(*buf, origin);
-	if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
-	    (newlen == 0 || (*buf)[newlen - 1] != '.')) {
-		/* No trailing dot. */
-		if (newlen + 2 > *buflen)
-			goto enospc;	/* No room for ".\0". */
-		(*buf)[newlen++] = '.';
-		(*buf)[newlen] = '\0';
-	}
-	if (newlen == 0) {
-		/* Use "@" instead of name. */
-		if (newlen + 2 > *buflen)
-			goto enospc;        /* No room for "@\0". */
-		(*buf)[newlen++] = '@';
-		(*buf)[newlen] = '\0';
-	}
-	*pp += n;
-	addlen(newlen, buf, buflen);
-	**buf = '\0';
-	return (newlen);
- enospc:
-	errno = ENOSPC;
-	*buf = save_buf;
-	*buflen = save_buflen;
-	return (-1);
-}
-
-static void
-addlen(size_t len, char **buf, size_t *buflen) {
-	assert(len <= *buflen);
-	*buf += len;
-	*buflen -= len;
-}
-
-static int
-addstr(const char *src, size_t len, char **buf, size_t *buflen) {
-	if (len > *buflen) {
-		errno = ENOSPC;
-		return (-1);
-	}
-	memcpy(*buf, src, len);
-	addlen(len, buf, buflen);
-	**buf = '\0';
-	return (0);
-}
-
-static int
-addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
-	size_t save_buflen = *buflen;
-	char *save_buf = *buf;
-	int t;
-
-	if (spaced || len >= target - 1) {
-		T(addstr("  ", 2, buf, buflen));
-		spaced = 1;
-	} else {
-		for (t = (target - len - 1) / 8; t >= 0; t--)
-			if (addstr("\t", 1, buf, buflen) < 0) {
-				*buflen = save_buflen;
-				*buf = save_buf;
-				return (-1);
-			}
-		spaced = 0;
-	}
-	return (spaced);
-}
--- lib/libc/net/ns_parse.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ns_parse.c,v 1.4 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-
-/* These need to be in the same order as the nres.h:ns_flag enum. */
-struct _ns_flagdata _ns_flagdata[16] = {
-	{ 0x8000, 15 },		/* qr. */
-	{ 0x7800, 11 },		/* opcode. */
-	{ 0x0400, 10 },		/* aa. */
-	{ 0x0200, 9 },		/* tc. */
-	{ 0x0100, 8 },		/* rd. */
-	{ 0x0080, 7 },		/* ra. */
-	{ 0x0040, 6 },		/* z. */
-	{ 0x0020, 5 },		/* ad. */
-	{ 0x0010, 4 },		/* cd. */
-	{ 0x000f, 0 },		/* rcode. */
-	{ 0x0000, 0 },		/* expansion (1/6). */
-	{ 0x0000, 0 },		/* expansion (2/6). */
-	{ 0x0000, 0 },		/* expansion (3/6). */
-	{ 0x0000, 0 },		/* expansion (4/6). */
-	{ 0x0000, 0 },		/* expansion (5/6). */
-	{ 0x0000, 0 },		/* expansion (6/6). */
-};
-
-static int
-skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
-	const u_char *optr = ptr;
-
-	for ((void)NULL; count > 0; count--) {
-		int b, rdlength;
-
-		b = dn_skipname(ptr, eom);
-		if (b < 0)
-			goto emsgsize;
-		ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
-		if (section != ns_s_qd) {
-			if (ptr + NS_INT32SZ > eom)
-				goto emsgsize;
-			ptr += NS_INT32SZ/*TTL*/;
-			if (ptr + NS_INT16SZ > eom)
-				goto emsgsize;
-			NS_GET16(rdlength, ptr);
-			ptr += rdlength/*RData*/;
-		}
-	}
-	if (ptr > eom)
-		goto emsgsize;
-	return (ptr - optr);
- emsgsize:
-	errno = EMSGSIZE;
-	return (-1);
-}
-
-int
-ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
-	const u_char *eom = msg + msglen;
-	int i;
-
-	memset(handle, 0x5e, sizeof *handle);
-	handle->_msg = msg;
-	handle->_eom = eom;
-	if (msg + NS_INT16SZ > eom)
-		goto emsgsize;
-	NS_GET16(handle->_id, msg);
-	if (msg + NS_INT16SZ > eom)
-		goto emsgsize;
-	NS_GET16(handle->_flags, msg);
-	for (i = 0; i < ns_s_max; i++) {
-		if (msg + NS_INT16SZ > eom)
-			goto emsgsize;
-		NS_GET16(handle->_counts[i], msg);
-	}
-	for (i = 0; i < ns_s_max; i++)
-		if (handle->_counts[i] == 0)
-			handle->_sections[i] = NULL;
-		else {
-			int b = skiprr(msg, eom, (ns_sect)i,
-				       handle->_counts[i]);
-
-			if (b < 0)
-				return (-1);
-			handle->_sections[i] = msg;
-			msg += b;
-		}
-	if (msg != eom)
-		goto emsgsize;
-	handle->_sect = ns_s_max;
-	handle->_rrnum = -1;
-	handle->_ptr = NULL;
-	return (0);
- emsgsize:
-	errno = EMSGSIZE;
-	return (-1);
-}
-
-int
-ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
-	int b;
-
-	/* Make section right. */
-	if (section < 0 || section >= ns_s_max)
-		goto enodev;
-	if ((int)section != (int)handle->_sect) {
-		handle->_sect = section;
-		handle->_rrnum = 0;
-		handle->_ptr = handle->_sections[(int)section];
-	}
-
-	/* Make rrnum right. */
-	if (rrnum == -1)
-		rrnum = handle->_rrnum;
-	if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
-		goto enodev;
-	if (rrnum < handle->_rrnum) {
-		handle->_rrnum = 0;
-		handle->_ptr = handle->_sections[(int)section];
-	}
-	
-	b = skiprr(handle->_msg, handle->_eom, section,
-		   rrnum - handle->_rrnum);
-	if (b < 0)
-		return (-1);
-	handle->_ptr += b;
-	handle->_rrnum = rrnum;
-
-	/* Do the parse. */
-	b = dn_expand(handle->_msg, handle->_eom,
-		      handle->_ptr, rr->name, NS_MAXDNAME);
-	if (b < 0)
-		return (-1);
-	handle->_ptr += b;
-	if (handle->_ptr + NS_INT16SZ > handle->_eom)
-		goto emsgsize;
-	NS_GET16(rr->type, handle->_ptr);
-	if (handle->_ptr + NS_INT16SZ > handle->_eom)
-		goto emsgsize;
-	NS_GET16(rr->rr_class, handle->_ptr);
-	if (section == ns_s_qd) {
-		rr->ttl = 0;
-		rr->rdlength = 0;
-		rr->rdata = NULL;
-	} else {
-		if (handle->_ptr + NS_INT32SZ > handle->_eom)
-			goto emsgsize;
-		NS_GET32(rr->ttl, handle->_ptr);
-		if (handle->_ptr + NS_INT16SZ > handle->_eom)
-			goto emsgsize;
-		NS_GET16(rr->rdlength, handle->_ptr);
-		if (handle->_ptr + rr->rdlength > handle->_eom)
-			goto emsgsize;
-		rr->rdata = handle->_ptr;
-		handle->_ptr += rr->rdlength;
-	}
-	handle->_rrnum++;
-
-	/* All done. */
-	return (0);
- enodev:
-	errno = ENODEV;
-	return (-1);
- emsgsize:
-	errno = EMSGSIZE;
-	return (-1);
-}
--- lib/libc/net/inet_lnaof.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_lnaof.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_lnaof.c,v 1.5 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/*
- * Return the local network address portion of an
- * internet address; handles class a/b/c network
- * number formats.
- */
-in_addr_t
-inet_lnaof(in)
-	struct in_addr in;
-{
-	in_addr_t i = ntohl(in.s_addr);
-
-	if (IN_CLASSA(i))
-		return ((i)&IN_CLASSA_HOST);
-	else if (IN_CLASSB(i))
-		return ((i)&IN_CLASSB_HOST);
-	else
-		return ((i)&IN_CLASSC_HOST);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_lnaof
-__weak_reference(__inet_lnaof, inet_lnaof);
--- lib/libc/net/nsap_addr.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/nsap_addr.c,v 1.9 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <resolv.h>
-
-static char
-xtob(c)
-	int c;
-{
-	return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
-}
-
-u_int
-inet_nsap_addr(ascii, binary, maxlen)
-	const char *ascii;
-	u_char *binary;
-	int maxlen;
-{
-	u_char c, nib;
-	u_int len = 0;
-
-	while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
-		if (c == '.' || c == '+' || c == '/')
-			continue;
-		if (!isascii(c))
-			return (0);
-		if (islower(c))
-			c = toupper(c);
-		if (isxdigit(c)) {
-			nib = xtob(c);
-			c = *ascii++;
-			if (c != '\0') {
-				c = toupper(c);
-				if (isxdigit(c)) {
-					*binary++ = (nib << 4) | xtob(c);
-					len++;
-				} else
-					return (0);
-			}
-			else
-				return (0);
-		}
-		else
-			return (0);
-	}
-	return (len);
-}
-
-char *
-inet_nsap_ntoa(binlen, binary, ascii)
-	int binlen;
-	const u_char *binary;
-	char *ascii;
-{
-	int nib;
-	int i;
-	static char tmpbuf[255*3];
-	char *start;
-
-	if (ascii)
-		start = ascii;
-	else {
-		ascii = tmpbuf;
-		start = tmpbuf;
-	}
-
-	if (binlen > 255)
-		binlen = 255;
-
-	for (i = 0; i < binlen; i++) {
-		nib = *binary >> 4;
-		*ascii++ = nib + (nib < 10 ? '0' : '7');
-		nib = *binary++ & 0x0f;
-		*ascii++ = nib + (nib < 10 ? '0' : '7');
-		if (((i % 2) == 0 && (i + 1) < binlen))
-			*ascii++ = '.';
-	}
-	*ascii = '\0';
-	return (start);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_nsap_addr
-__weak_reference(__inet_nsap_addr, inet_nsap_addr);
-#undef inet_nsap_ntoa
-__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa);
--- lib/libc/net/res_query.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*-
- * Copyright (c) 1988, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: res_query.c,v 8.14 1997/06/09 17:47:05 halley Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_query.c,v 1.30.2.3 2006/03/29 03:35:59 ume Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "res_config.h"
-
-#if PACKETSZ > 1024
-#define MAXPACKET	PACKETSZ
-#else
-#define MAXPACKET	1024
-#endif
-
-const char *_res_hostalias(const char *, char *, size_t);
-
-/*
- * Formulate a normal query, send, and await answer.
- * Returned answer is placed in supplied buffer "answer".
- * Perform preliminary check of answer, returning success only
- * if no error is indicated and the answer count is nonzero.
- * Return the size of the response on success, -1 on error.
- * Error number is left in h_errno.
- *
- * Caller must parse answer and determine whether it answers the question.
- */
-int
-res_query(name, class, type, answer, anslen)
-	const char *name;	/* domain name */
-	int class, type;	/* class and type of query */
-	u_char *answer;		/* buffer to put answer */
-	int anslen;		/* size of answer buffer */
-{
-	u_char buf[MAXPACKET];
-	HEADER *hp = (HEADER *) answer;
-	int n;
-
-	hp->rcode = NOERROR;	/* default */
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-#ifdef DEBUG
-	if (_res.options & RES_DEBUG)
-		printf(";; res_query(%s, %d, %d)\n", name, class, type);
-#endif
-
-	n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
-			buf, sizeof(buf));
-	if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
-		n = res_opt(n, buf, sizeof(buf), anslen);
-	if (n <= 0) {
-#ifdef DEBUG
-		if (_res.options & RES_DEBUG)
-			printf(";; res_query: mkquery failed\n");
-#endif
-		h_errno = NO_RECOVERY;
-		return (n);
-	}
-	n = res_send(buf, n, answer, anslen);
-	if (n < 0) {
-#ifdef DEBUG
-		if (_res.options & RES_DEBUG)
-			printf(";; res_query: send error\n");
-#endif
-		h_errno = TRY_AGAIN;
-		return (n);
-	}
-
-	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-#ifdef DEBUG
-		if (_res.options & RES_DEBUG)
-			printf(";; rcode = %d, ancount=%d\n", hp->rcode,
-			    ntohs(hp->ancount));
-#endif
-		switch (hp->rcode) {
-		case NXDOMAIN:
-			h_errno = HOST_NOT_FOUND;
-			break;
-		case SERVFAIL:
-			h_errno = TRY_AGAIN;
-			break;
-		case NOERROR:
-			h_errno = NO_DATA;
-			break;
-		case FORMERR:
-		case NOTIMP:
-		case REFUSED:
-		default:
-			h_errno = NO_RECOVERY;
-			break;
-		}
-		return (-1);
-	}
-	return (n);
-}
-
-/*
- * Formulate a normal query, send, and retrieve answer in supplied buffer.
- * Return the size of the response on success, -1 on error.
- * If enabled, implement search rules until answer or unrecoverable failure
- * is detected.  Error code, if any, is left in h_errno.
- */
-int
-res_search(name, class, type, answer, anslen)
-	const char *name;	/* domain name */
-	int class, type;	/* class and type of query */
-	u_char *answer;		/* buffer to put answer */
-	int anslen;		/* size of answer */
-{
-	const char *cp, * const *domain;
-	HEADER *hp = (HEADER *) answer;
-	char tmp[MAXDNAME];
-	u_int dots;
-	int trailing_dot, ret, saved_herrno;
-	int got_nodata = 0, got_servfail = 0, root_on_list = 0;
-	int tried_as_is = 0;
-	int searched = 0;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-	errno = 0;
-	h_errno = HOST_NOT_FOUND;	/* default, if we never query */
-	dots = 0;
-	for (cp = name; *cp; cp++)
-		dots += (*cp == '.');
-	trailing_dot = 0;
-	if (cp > name && *--cp == '.')
-		trailing_dot++;
-
-	/* If there aren't any dots, it could be a user-level alias */
-	if (!dots && (cp = _res_hostalias(name, tmp, sizeof tmp)) != NULL)
-		return (res_query(cp, class, type, answer, anslen));
-
-	/*
-	 * If there are enough dots in the name, let's just give it a
-	 * try 'as is'. The threshold can be set with the "ndots" option.
-	 * Also, query 'as is', if there is a trailing dot in the name.
-	 */
-	saved_herrno = -1;
-	if (dots >= _res.ndots || trailing_dot) {
-		ret = res_querydomain(name, NULL, class, type, answer, anslen);
-		if (ret > 0 || trailing_dot)
-			return (ret);
-		if (errno == ECONNREFUSED) {
-			h_errno = TRY_AGAIN;
-			return (-1);
-		}
-		switch (h_errno) {
-		case NO_DATA:
-		case HOST_NOT_FOUND:
-			break;
-		case TRY_AGAIN:
-			if (hp->rcode == SERVFAIL)
-				break;
-			/* FALLTHROUGH */
-		default:
-			return (-1);
-		}
-		saved_herrno = h_errno;
-		tried_as_is++;
-	}
-
-	/*
-	 * We do at least one level of search if
-	 *	- there is no dot and RES_DEFNAME is set, or
-	 *	- there is at least one dot, there is no trailing dot,
-	 *	  and RES_DNSRCH is set.
-	 */
-	if ((!dots && (_res.options & RES_DEFNAMES)) ||
-	    (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
-		int done = 0;
-
-		for (domain = (const char * const *)_res.dnsrch;
-		     *domain && !done;
-		     domain++) {
-			searched = 1;
-
-			if (domain[0][0] == '\0' ||
-			    (domain[0][0] == '.' && domain[0][1] == '\0'))
-				root_on_list++;
-
-			if (root_on_list && tried_as_is)
-				continue;
-
-			ret = res_querydomain(name, *domain, class, type,
-					      answer, anslen);
-			if (ret > 0)
-				return (ret);
-
-			/*
-			 * If no server present, give up.
-			 * If name isn't found in this domain,
-			 * keep trying higher domains in the search list
-			 * (if that's enabled).
-			 * On a NO_DATA error, keep trying, otherwise
-			 * a wildcard entry of another type could keep us
-			 * from finding this entry higher in the domain.
-			 * If we get some other error (negative answer or
-			 * server failure), then stop searching up,
-			 * but try the input name below in case it's
-			 * fully-qualified.
-			 */
-			if (errno == ECONNREFUSED) {
-				h_errno = TRY_AGAIN;
-				return (-1);
-			}
-
-			switch (h_errno) {
-			case NO_DATA:
-				got_nodata++;
-				/* FALLTHROUGH */
-			case HOST_NOT_FOUND:
-				/* keep trying */
-				break;
-			case TRY_AGAIN:
-				/*
-				 * This can occur due to a server failure
-				 * (that is, all listed servers have failed),
-				 * or all listed servers have timed out.
-				 * ((HEADER *)answer)->rcode may not be set
-				 * to SERVFAIL in the case of a timeout.
-				 *
-				 * Either way we must return TRY_AGAIN in
-				 * order to avoid non-deterministic
-				 * return codes.
-				 * For example, loaded name servers or races
-				 * against network startup/validation (dhcp,
-				 * ppp, etc) can cause the search to timeout
-				 * on one search element, e.g. 'fu.bar.com',
-				 * and return a definitive failure on the
-				 * next search element, e.g. 'fu.'.
-				 */
-				++got_servfail;
-				if (hp->rcode == SERVFAIL) {
-					/* try next search element, if any */
-					break;
-				}
-				/* FALLTHROUGH */
-			default:
-				/* anything else implies that we're done */
-				done++;
-			}
-
-			/* if we got here for some reason other than DNSRCH,
-			 * we only wanted one iteration of the loop, so stop.
-			 */
-			if (!(_res.options & RES_DNSRCH))
-				done++;
-		}
-	}
-
-	switch (h_errno) {
-	case NO_DATA:
-	case HOST_NOT_FOUND:
-		break;
-	case TRY_AGAIN:
-		if (hp->rcode == SERVFAIL)
-			break;
-		/* FALLTHROUGH */
-	default:
-		goto giveup;
-	}
-
-	/*
-	 * If the query has not already been tried as is then try it
-	 * unless RES_NOTLDQUERY is set and there were no dots.
-	 */
-	if ((dots || !searched || !(_res.options & RES_NOTLDQUERY)) &&
-	    !(tried_as_is || root_on_list)) {
-		ret = res_querydomain(name, NULL, class, type, answer, anslen);
-		if (ret > 0)
-			return (ret);
-	}
-
-	/* if we got here, we didn't satisfy the search.
-	 * if we did an initial full query, return that query's h_errno
-	 * (note that we wouldn't be here if that query had succeeded).
-	 * else if we ever got a nodata, send that back as the reason.
-	 * else send back meaningless h_errno, that being the one from
-	 * the last DNSRCH we did.
-	 */
-giveup:
-	if (saved_herrno != -1)
-		h_errno = saved_herrno;
-	else if (got_nodata)
-		h_errno = NO_DATA;
-	else if (got_servfail)
-		h_errno = TRY_AGAIN;
-	return (-1);
-}
-
-/*
- * Perform a call on res_query on the concatenation of name and domain,
- * removing a trailing dot from name if domain is NULL.
- */
-int
-res_querydomain(name, domain, class, type, answer, anslen)
-	const char *name, *domain;
-	int class, type;	/* class and type of query */
-	u_char *answer;		/* buffer to put answer */
-	int anslen;		/* size of answer */
-{
-	char nbuf[MAXDNAME];
-	const char *longname = nbuf;
-	int n, d;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-#ifdef DEBUG
-	if (_res.options & RES_DEBUG)
-		printf(";; res_querydomain(%s, %s, %d, %d)\n",
-		       name, domain?domain:"<Nil>", class, type);
-#endif
-	if (domain == NULL) {
-		/*
-		 * Check for trailing '.';
-		 * copy without '.' if present.
-		 */
-		n = strlen(name);
-		if (n >= MAXDNAME) {
-			h_errno = NO_RECOVERY;
-			return (-1);
-		}
-		n--;
-		if (n >= 0 && name[n] == '.') {
-			strncpy(nbuf, name, n);
-			nbuf[n] = '\0';
-		} else
-			longname = name;
-	} else {
-		n = strlen(name);
-		d = strlen(domain);
-		if (n + d + 1 >= MAXDNAME) {
-			h_errno = NO_RECOVERY;
-			return (-1);
-		}
-		sprintf(nbuf, "%s.%s", name, domain);
-	}
-	return (res_query(longname, class, type, answer, anslen));
-}
-
-const char *
-_res_hostalias(const char *name, char *dst, size_t siz)
-{
-	char *file, *cp1, *cp2;
-	char buf[BUFSIZ];
-	FILE *fp;
-
-	if (_res.options & RES_NOALIASES)
-		return (NULL);
-	if (issetugid())
-		return (NULL);
-	file = getenv("HOSTALIASES");
-	if (file == NULL || (fp = fopen(file, "r")) == NULL)
-		return (NULL);
-	setbuf(fp, NULL);
-	buf[sizeof(buf) - 1] = '\0';
-	while (fgets(buf, sizeof(buf), fp)) {
-		for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1)
-			;
-		if (!*cp1)
-			break;
-		*cp1 = '\0';
-		if (!strcasecmp(buf, name)) {
-			while (isspace((unsigned char)*++cp1))
-				;
-			if (!*cp1)
-				break;
-			for (cp2 = cp1 + 1; *cp2 &&
-			     !isspace((unsigned char)*cp2); ++cp2)
-				;
-			*cp2 = '\0';
-			strncpy(dst, cp1, siz - 1);
-			dst[siz - 1] = '\0';
-			fclose(fp);
-			return (dst);
-		}
-	}
-	fclose(fp);
-	return (NULL);
-}
-
-const char *
-hostalias(const char *name)
-{
-	static char abuf[MAXDNAME];
-
-	return (_res_hostalias(name, abuf, sizeof abuf));
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_query
-__weak_reference(__res_query, res_query);
-#undef res_search
-__weak_reference(__res_search, res_search);
-#undef res_querydomain
-__weak_reference(__res_querydomain, res_querydomain);
--- lib/libc/net/inet_neta.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_neta.c,v 1.9 2003/01/01 18:48:43 schweikh Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/*
- * char *
- * inet_neta(src, dst, size)
- *	format an in_addr_t network number into presentation format.
- * return:
- *	pointer to dst, or NULL if an error occurred (check errno).
- * note:
- *	format of ``src'' is as for inet_network().
- * author:
- *	Paul Vixie (ISC), July 1996
- */
-char *
-inet_neta(src, dst, size)
-	in_addr_t src;
-	char *dst;
-	size_t size;
-{
-	char *odst = dst;
-	char *tp;
-
-	while (src & 0xffffffff) {
-		u_char b = (src & 0xff000000) >> 24;
-
-		src <<= 8;
-		if (b) {
-			if (size < sizeof "255.")
-				goto emsgsize;
-			tp = dst;
-			dst += SPRINTF((dst, "%u", b));
-			if (src != 0L) {
-				*dst++ = '.';
-				*dst = '\0';
-			}
-			size -= (size_t)(dst - tp);
-		}
-	}
-	if (dst == odst) {
-		if (size < sizeof "0.0.0.0")
-			goto emsgsize;
-		strcpy(dst, "0.0.0.0");
-	}
-	return (odst);
-
- emsgsize:
-	errno = EMSGSIZE;
-	return (NULL);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_neta
-__weak_reference(__inet_neta, inet_neta);
--- lib/libc/net/res_mkquery.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (c) 1985, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_mkquery.c	8.1 (Berkeley) 6/4/93";
-static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_mkquery.c,v 1.19 2002/09/14 17:28:40 ume Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "res_config.h"
-
-/*
- * Form all types of queries.
- * Returns the size of the result or -1.
- */
-int
-res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
-	int op;			/* opcode of query */
-	const char *dname;	/* domain name */
-	int class, type;	/* class and type of query */
-	const u_char *data;	/* resource record data */
-	int datalen;		/* length of data */
-	const u_char *newrr_in;	/* new rr for modify or append */
-	u_char *buf;		/* buffer to put query */
-	int buflen;		/* size of buffer */
-{
-	HEADER *hp;
-	u_char *cp;
-	int n;
-	u_char *dnptrs[20], **dpp, **lastdnptr;
-
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-#ifdef DEBUG
-	if (_res.options & RES_DEBUG)
-		printf(";; res_mkquery(%d, %s, %d, %d)\n",
-		       op, dname, class, type);
-#endif
-	/*
-	 * Initialize header fields.
-	 */
-	if ((buf == NULL) || (buflen < HFIXEDSZ))
-		return (-1);
-	memset(buf, 0, HFIXEDSZ);
-	hp = (HEADER *) buf;
-	hp->id = htons(++_res.id);
-	hp->opcode = op;
-	hp->rd = (_res.options & RES_RECURSE) != 0;
-	hp->rcode = NOERROR;
-	cp = buf + HFIXEDSZ;
-	buflen -= HFIXEDSZ;
-	dpp = dnptrs;
-	*dpp++ = buf;
-	*dpp++ = NULL;
-	lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
-	/*
-	 * perform opcode specific processing
-	 */
-	switch (op) {
-	case QUERY:	/*FALLTHROUGH*/
-	case NS_NOTIFY_OP:
-		if ((buflen -= QFIXEDSZ) < 0)
-			return (-1);
-		if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
-			return (-1);
-		cp += n;
-		buflen -= n;
-		__putshort(type, cp);
-		cp += INT16SZ;
-		__putshort(class, cp);
-		cp += INT16SZ;
-		hp->qdcount = htons(1);
-		if (op == QUERY || data == NULL)
-			break;
-		/*
-		 * Make an additional record for completion domain.
-		 */
-		buflen -= RRFIXEDSZ;
-		n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
-		if (n < 0)
-			return (-1);
-		cp += n;
-		buflen -= n;
-		__putshort(T_NULL, cp);
-		cp += INT16SZ;
-		__putshort(class, cp);
-		cp += INT16SZ;
-		__putlong(0, cp);
-		cp += INT32SZ;
-		__putshort(0, cp);
-		cp += INT16SZ;
-		hp->arcount = htons(1);
-		break;
-
-	case IQUERY:
-		/*
-		 * Initialize answer section
-		 */
-		if (buflen < 1 + RRFIXEDSZ + datalen)
-			return (-1);
-		*cp++ = '\0';	/* no domain name */
-		__putshort(type, cp);
-		cp += INT16SZ;
-		__putshort(class, cp);
-		cp += INT16SZ;
-		__putlong(0, cp);
-		cp += INT32SZ;
-		__putshort(datalen, cp);
-		cp += INT16SZ;
-		if (datalen) {
-			memcpy(cp, data, datalen);
-			cp += datalen;
-		}
-		hp->ancount = htons(1);
-		break;
-
-	default:
-		return (-1);
-	}
-	return (cp - buf);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <resolv.h>.
- */
-#undef res_mkquery
-__weak_reference(__res_mkquery, res_mkquery);
-
-/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
-int
-res_opt(n0, buf, buflen, anslen)
-	int n0;
-	u_char *buf;		/* buffer to put query */
-	int buflen;		/* size of buffer */
-	int anslen;		/* answer buffer length */
-{
-	HEADER *hp;
-	u_char *cp;
-
-	hp = (HEADER *) buf;
-	cp = buf + n0;
-	buflen -= n0;
-
-	if (buflen < 1 + RRFIXEDSZ)
-		return -1;
-
-	*cp++ = 0;	/* "." */
-	buflen--;
-
-	__putshort(T_OPT, cp);	/* TYPE */
-	cp += INT16SZ;
-	if (anslen > 0xffff)
-		anslen = 0xffff;		/* limit to 16bit value */
-	__putshort(anslen & 0xffff, cp);	/* CLASS = UDP payload size */
-	cp += INT16SZ;
-	*cp++ = NOERROR;	/* extended RCODE */
-	*cp++ = 0;		/* EDNS version */
-	__putshort(0, cp);	/* MBZ */
-	cp += INT16SZ;
-	__putshort(0, cp);	/* RDLEN */
-	cp += INT16SZ;
-	hp->arcount = htons(ntohs(hp->arcount) + 1);
-	buflen -= RRFIXEDSZ;
-
-	return cp - buf;
-}
--- lib/libc/net/inet_netof.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_netof.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_netof.c,v 1.5 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/*
- * Return the network number from an internet
- * address; handles class a/b/c network #'s.
- */
-in_addr_t
-inet_netof(in)
-	struct in_addr in;
-{
-	in_addr_t i = ntohl(in.s_addr);
-
-	if (IN_CLASSA(i))
-		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
-	else if (IN_CLASSB(i))
-		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
-	else
-		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_netof
-__weak_reference(__inet_netof, inet_netof);
--- lib/libc/net/ns_name.c
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
- * Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/ns_name.c,v 1.5 2003/02/18 13:39:52 nectar Exp $");
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-
-/* Data. */
-
-static char		digits[] = "0123456789";
-
-/* Forward. */
-
-static int		special(int);
-static int		printable(int);
-static int		dn_find(const u_char *, const u_char *,
-				const u_char * const *,
-				const u_char * const *);
-
-/* Public. */
-
-/*
- * ns_name_ntop(src, dst, dstsiz)
- *	Convert an encoded domain name to printable ascii as per RFC1035.
- * return:
- *	Number of bytes written to buffer, or -1 (with errno set)
- * notes:
- *	The root is returned as "."
- *	All other domains are returned in non absolute form
- */
-int
-ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
-	const u_char *cp;
-	char *dn, *eom;
-	u_char c;
-	u_int n;
-
-	cp = src;
-	dn = dst;
-	eom = dst + dstsiz;
-
-	while ((n = *cp++) != 0) {
-		if ((n & NS_CMPRSFLGS) != 0) {
-			/* Some kind of compression pointer. */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if (dn != dst) {
-			if (dn >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			*dn++ = '.';
-		}
-		if (dn + n >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		for ((void)NULL; n > 0; n--) {
-			c = *cp++;
-			if (special(c)) {
-				if (dn + 1 >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = '\\';
-				*dn++ = (char)c;
-			} else if (!printable(c)) {
-				if (dn + 3 >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = '\\';
-				*dn++ = digits[c / 100];
-				*dn++ = digits[(c % 100) / 10];
-				*dn++ = digits[c % 10];
-			} else {
-				if (dn >= eom) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dn++ = (char)c;
-			}
-		}
-	}
-	if (dn == dst) {
-		if (dn >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*dn++ = '.';
-	}
-	if (dn >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*dn++ = '\0';
-	return (dn - dst);
-}
-
-/*
- * ns_name_pton(src, dst, dstsiz)
- *	Convert an ascii string into an encoded domain name as per RFC1035.
- * return:
- *	-1 if it fails
- *	1 if string was fully qualified
- *	0 is string was not fully qualified
- * notes:
- *	Enforces label and domain length limits.
- */
-
-int
-ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
-	u_char *label, *bp, *eom;
-	int c, n, escaped;
-	char *cp;
-
-	escaped = 0;
-	bp = dst;
-	eom = dst + dstsiz;
-	label = bp++;
-
-	while ((c = *src++) != 0) {
-		if (escaped) {
-			if ((cp = strchr(digits, c)) != NULL) {
-				n = (cp - digits) * 100;
-				if ((c = *src++) == 0 ||
-				    (cp = strchr(digits, c)) == NULL) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				n += (cp - digits) * 10;
-				if ((c = *src++) == 0 ||
-				    (cp = strchr(digits, c)) == NULL) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				n += (cp - digits);
-				if (n > 255) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				c = n;
-			}
-			escaped = 0;
-		} else if (c == '\\') {
-			escaped = 1;
-			continue;
-		} else if (c == '.') {
-			c = (bp - label - 1);
-			if ((c & NS_CMPRSFLGS) != 0) {	/* Label too big. */
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			if (label >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			*label = c;
-			/* Fully qualified ? */
-			if (*src == '\0') {
-				if (c != 0) {
-					if (bp >= eom) {
-						errno = EMSGSIZE;
-						return (-1);
-					}
-					*bp++ = '\0';
-				}
-				if ((bp - dst) > MAXCDNAME) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				return (1);
-			}
-			if (c == 0) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			label = bp++;
-			continue;
-		}
-		if (bp >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*bp++ = (u_char)c;
-	}
-	c = (bp - label - 1);
-	if ((c & NS_CMPRSFLGS) != 0) {		/* Label too big. */
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	if (label >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*label = c;
-	if (c != 0) {
-		if (bp >= eom) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		*bp++ = 0;
-	}
-	if ((bp - dst) > MAXCDNAME) {	/* src too big */
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	return (0);
-}
-
-/*
- * ns_name_unpack(msg, eom, src, dst, dstsiz)
- *	Unpack a domain name from a message, source may be compressed.
- * return:
- *	-1 if it fails, or consumed octets if it succeeds.
- */
-int
-ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
-	       u_char *dst, size_t dstsiz)
-{
-	const u_char *srcp, *dstlim;
-	u_char *dstp;
-	int n, len, checked;
-
-	len = -1;
-	checked = 0;
-	dstp = dst;
-	srcp = src;
-	dstlim = dst + dstsiz;
-	if (srcp < msg || srcp >= eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	/* Fetch next label in domain name. */
-	while ((n = *srcp++) != 0) {
-		/* Check for indirection. */
-		switch (n & NS_CMPRSFLGS) {
-		case 0:
-			/* Limit checks. */
-			if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			checked += n + 1;
-			*dstp++ = n;
-			memcpy(dstp, srcp, n);
-			dstp += n;
-			srcp += n;
-			break;
-
-		case NS_CMPRSFLGS:
-			if (srcp >= eom) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			if (len < 0)
-				len = srcp - src + 1;
-			srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
-			if (srcp < msg || srcp >= eom) {  /* Out of range. */
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			checked += 2;
-			/*
-			 * Check for loops in the compressed name;
-			 * if we've looked at the whole message,
-			 * there must be a loop.
-			 */
-			if (checked >= eom - msg) {
-				errno = EMSGSIZE;
-				return (-1);
-			}
-			break;
-
-		default:
-			errno = EMSGSIZE;
-			return (-1);			/* flag error */
-		}
-	}
-	*dstp = '\0';
-	if (len < 0)
-		len = srcp - src;
-	return (len);
-}
-
-/*
- * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
- *	Pack domain name 'domain' into 'comp_dn'.
- * return:
- *	Size of the compressed name, or -1.
- * notes:
- *	'dnptrs' is an array of pointers to previous compressed names.
- *	dnptrs[0] is a pointer to the beginning of the message. The array
- *	ends with NULL.
- *	'lastdnptr' is a pointer to the end of the array pointed to
- *	by 'dnptrs'.
- * Side effects:
- *	The list of pointers in dnptrs is updated for labels inserted into
- *	the message as we compress the name.  If 'dnptr' is NULL, we don't
- *	try to compress names. If 'lastdnptr' is NULL, we don't update the
- *	list.
- */
-int
-ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
-	     const u_char **dnptrs, const u_char **lastdnptr)
-{
-	u_char *dstp;
-	const u_char **cpp, **lpp, *eob, *msg;
-	const u_char *srcp;
-	int n, l;
-
-	srcp = src;
-	dstp = dst;
-	eob = dstp + dstsiz;
-	lpp = cpp = NULL;
-	if (dnptrs != NULL) {
-		if ((msg = *dnptrs++) != NULL) {
-			for (cpp = dnptrs; *cpp != NULL; cpp++)
-				(void)NULL;
-			lpp = cpp;	/* end of list to search */
-		}
-	} else
-		msg = NULL;
-
-	/* make sure the domain we are about to add is legal */
-	l = 0;
-	do {
-		n = *srcp;
-		if ((n & NS_CMPRSFLGS) != 0) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		l += n + 1;
-		if (l > MAXCDNAME) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		srcp += n + 1;
-	} while (n != 0);
-
-	srcp = src;
-	do {
-		/* Look to see if we can use pointers. */
-		n = *srcp;
-		if (n != 0 && msg != NULL) {
-			l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
-				    (const u_char * const *)lpp);
-			if (l >= 0) {
-				if (dstp + 1 >= eob) {
-					errno = EMSGSIZE;
-					return (-1);
-				}
-				*dstp++ = (l >> 8) | NS_CMPRSFLGS;
-				*dstp++ = l % 256;
-				return (dstp - dst);
-			}
-			/* Not found, save it. */
-			if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
-			    (dstp - msg) < 0x4000) {
-				*cpp++ = dstp;
-				*cpp = NULL;
-			}
-		}
-		/* copy label to buffer */
-		if (n & NS_CMPRSFLGS) {		/* Should not happen. */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		if (dstp + 1 + n >= eob) {
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		memcpy(dstp, srcp, n + 1);
-		srcp += n + 1;
-		dstp += n + 1;
-	} while (n != 0);
-
-	if (dstp > eob) {
-		if (msg != NULL)
-			*lpp = NULL;
-		errno = EMSGSIZE;
-		return (-1);
-	} 
-	return (dstp - dst);
-}
-
-/*
- * ns_name_uncompress(msg, eom, src, dst, dstsiz)
- *	Expand compressed domain name to presentation format.
- * return:
- *	Number of bytes read out of `src', or -1 (with errno set).
- * note:
- *	Root domain returns as "." not "".
- */
-int
-ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
-		   char *dst, size_t dstsiz)
-{
-	u_char tmp[NS_MAXCDNAME];
-	int n;
-	
-	if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
-		return (-1);
-	if (ns_name_ntop(tmp, dst, dstsiz) == -1)
-		return (-1);
-	return (n);
-}
-
-/*
- * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
- *	Compress a domain name into wire format, using compression pointers.
- * return:
- *	Number of bytes consumed in `dst' or -1 (with errno set).
- * notes:
- *	'dnptrs' is an array of pointers to previous compressed names.
- *	dnptrs[0] is a pointer to the beginning of the message.
- *	The list ends with NULL.  'lastdnptr' is a pointer to the end of the
- *	array pointed to by 'dnptrs'. Side effect is to update the list of
- *	pointers for labels inserted into the message as we compress the name.
- *	If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
- *	is NULL, we don't update the list.
- */
-int
-ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
-		 const u_char **dnptrs, const u_char **lastdnptr)
-{
-	u_char tmp[NS_MAXCDNAME];
-
-	if (ns_name_pton(src, tmp, sizeof tmp) == -1)
-		return (-1);
-	return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
-}
-
-/*
- * ns_name_skip(ptrptr, eom)
- *	Advance *ptrptr to skip over the compressed name it points at.
- * return:
- *	0 on success, -1 (with errno set) on failure.
- */
-int
-ns_name_skip(const u_char **ptrptr, const u_char *eom) {
-	const u_char *cp;
-	u_int n;
-
-	cp = *ptrptr;
-	while (cp < eom && (n = *cp++) != 0) {
-		/* Check for indirection. */
-		switch (n & NS_CMPRSFLGS) {
-		case 0:			/* normal case, n == len */
-			cp += n;
-			continue;
-		case NS_CMPRSFLGS:	/* indirection */
-			cp++;
-			break;
-		default:		/* illegal type */
-			errno = EMSGSIZE;
-			return (-1);
-		}
-		break;
-	}
-	if (cp > eom) {
-		errno = EMSGSIZE;
-		return (-1);
-	}
-	*ptrptr = cp;
-	return (0);
-}
-
-/* Private. */
-
-/*
- * special(ch)
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	is this characted special ("in need of quoting") ?
- * return:
- *	boolean.
- */
-static int
-special(int ch) {
-	switch (ch) {
-	case 0x22: /* '"' */
-	case 0x2E: /* '.' */
-	case 0x3B: /* ';' */
-	case 0x5C: /* '\\' */
-	/* Special modifiers in zone files. */
-	case 0x40: /* '@' */
-	case 0x24: /* '$' */
-		return (1);
-	default:
-		return (0);
-	}
-}
-
-/*
- * printable(ch)
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	is this character visible and not a space when printed ?
- * return:
- *	boolean.
- */
-static int
-printable(int ch) {
-	return (ch > 0x20 && ch < 0x7f);
-}
-
-/*
- *	Thinking in noninternationalized USASCII (per the DNS spec),
- *	convert this character to lower case if it's upper case.
- */
-static int
-mklower(int ch) {
-	if (ch >= 0x41 && ch <= 0x5A)
-		return (ch + 0x20);
-	return (ch);
-}
-
-/*
- * dn_find(domain, msg, dnptrs, lastdnptr)
- *	Search for the counted-label name in an array of compressed names.
- * return:
- *	offset from msg if found, or -1.
- * notes:
- *	dnptrs is the pointer to the first name on the list,
- *	not the pointer to the start of the message.
- */
-static int
-dn_find(const u_char *domain, const u_char *msg,
-	const u_char * const *dnptrs,
-	const u_char * const *lastdnptr)
-{
-	const u_char *dn, *cp, *sp;
-	const u_char * const *cpp;
-	u_int n;
-
-	for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
-		dn = domain;
-		sp = cp = *cpp;
-		while ((n = *cp++) != 0) {
-			/*
-			 * check for indirection
-			 */
-			switch (n & NS_CMPRSFLGS) {
-			case 0:			/* normal case, n == len */
-				if (n != *dn++)
-					goto next;
-				for ((void)NULL; n > 0; n--)
-					if (mklower(*dn++) != mklower(*cp++))
-						goto next;
-				/* Is next root for both ? */
-				if (*dn == '\0' && *cp == '\0')
-					return (sp - msg);
-				if (*dn)
-					continue;
-				goto next;
-
-			case NS_CMPRSFLGS:	/* indirection */
-				cp = msg + (((n & 0x3f) << 8) | *cp);
-				break;
-
-			default:	/* illegal type */
-				errno = EMSGSIZE;
-				return (-1);
-			}
-		}
- next: ;
-	}
-	errno = ENOENT;
-	return (-1);
-}
--- lib/libc/net/inet_addr.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*	$KAME: inet_addr.c,v 1.5 2001/08/20 02:32:40 itojun Exp $	*/
-
-/*
- * ++Copyright++ 1983, 1990, 1993
- * -
- * Copyright (c) 1983, 1990, 1993
- *    The Regents of the University of California.  All rights reserved.
- * 
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- * 	This product includes software developed by the University of
- * 	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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.
- * -
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- * 
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- * -
- * --Copyright--
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_addr.c	8.1 (Berkeley) 6/17/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_addr.c,v 1.16 2002/04/19 04:46:20 suz Exp $");
-
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-/*
- * ASCII internet address interpretation routine.
- * The value returned is in network order.
- */
-in_addr_t		/* XXX should be struct in_addr :( */
-inet_addr(cp)
-	const char *cp;
-{
-	struct in_addr val;
-
-	if (inet_aton(cp, &val))
-		return (val.s_addr);
-	return (INADDR_NONE);
-}
-
-/* 
- * Check whether "cp" is a valid ASCII representation
- * of an Internet address and convert to a binary address.
- * Returns 1 if the address is valid, 0 if not.
- * This replaces inet_addr, the return value from which
- * cannot distinguish between failure and a local broadcast address.
- */
-int
-inet_aton(cp, addr)
-	const char *cp;
-	struct in_addr *addr;
-{
-	u_long parts[4];
-	in_addr_t val;
-	char *c;
-	char *endptr;
-	int gotend, n;
-
-	c = (char *)cp;
-	n = 0;
-	/*
-	 * Run through the string, grabbing numbers until
-	 * the end of the string, or some error
-	 */
-	gotend = 0;
-	while (!gotend) {
-		errno = 0;
-		val = strtoul(c, &endptr, 0);
-
-		if (errno == ERANGE)	/* Fail completely if it overflowed. */
-			return (0);
-		
-		/* 
-		 * If the whole string is invalid, endptr will equal
-		 * c.. this way we can make sure someone hasn't
-		 * gone '.12' or something which would get past
-		 * the next check.
-		 */
-		if (endptr == c)
-			return (0);
-		parts[n] = val;
-		c = endptr;
-
-		/* Check the next character past the previous number's end */
-		switch (*c) {
-		case '.' :
-			/* Make sure we only do 3 dots .. */
-			if (n == 3)	/* Whoops. Quit. */
-				return (0);
-			n++;
-			c++;
-			break;
-
-		case '\0':
-			gotend = 1;
-			break;
-
-		default:
-			if (isspace((unsigned char)*c)) {
-				gotend = 1;
-				break;
-			} else
-				return (0);	/* Invalid character, so fail */
-		}
-
-	}
-
-	/*
-	 * Concoct the address according to
-	 * the number of parts specified.
-	 */
-
-	switch (n) {
-	case 0:				/* a -- 32 bits */
-		/*
-		 * Nothing is necessary here.  Overflow checking was
-		 * already done in strtoul().
-		 */
-		break;
-	case 1:				/* a.b -- 8.24 bits */
-		if (val > 0xffffff || parts[0] > 0xff)
-			return (0);
-		val |= parts[0] << 24;
-		break;
-
-	case 2:				/* a.b.c -- 8.8.16 bits */
-		if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16);
-		break;
-
-	case 3:				/* a.b.c.d -- 8.8.8.8 bits */
-		if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff ||
-		    parts[2] > 0xff)
-			return (0);
-		val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
-		break;
-	}
-
-	if (addr != NULL)
-		addr->s_addr = htonl(val);
-	return (1);
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_addr
-__weak_reference(__inet_addr, inet_addr);
-#undef inet_aton
-__weak_reference(__inet_aton, inet_aton);
--- lib/libc/net/res_data.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 1995,1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/res_data.c,v 1.8 2002/03/22 21:52:29 obrien Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "res_config.h"
-
-const char *_res_opcodes[] = {
-	"QUERY",
-	"IQUERY",
-	"CQUERYM",
-	"CQUERYU",	/* experimental */
-	"NOTIFY",	/* experimental */
-	"UPDATE",
-	"6",
-	"7",
-	"8",
-	"9",
-	"10",
-	"11",
-	"12",
-	"13",
-	"ZONEINIT",
-	"ZONEREF",
-};
-
-const char *_res_resultcodes[] = {
-	"NOERROR",
-	"FORMERR",
-	"SERVFAIL",
-	"NXDOMAIN",
-	"NOTIMP",
-	"REFUSED",
-	"YXDOMAIN",
-	"YXRRSET",
-	"NXRRSET",
-	"NOTAUTH",
-	"ZONEERR",
-	"11",
-	"12",
-	"13",
-	"14",
-	"NOCHANGE",
-};
-
-#ifdef BIND_UPDATE
-const char *_res_sectioncodes[] = {
-	"ZONE",
-	"PREREQUISITES",
-	"UPDATE",
-	"ADDITIONAL",
-};
-#endif
--- lib/libc/net/inet_net_pton.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.4.2.1.8.2 2004/03/17 00:29:47 marka Exp";
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9.10.1 2006/03/06 14:53:51 ume Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/*
- * static int
- * inet_net_pton_ipv4(src, dst, size)
- *	convert IPv4 network number from presentation to network format.
- *	accepts hex octets, hex strings, decimal octets, and /CIDR.
- *	"size" is in bytes and describes "dst".
- * return:
- *	number of bits, either imputed classfully or specified with /CIDR,
- *	or -1 if some failure occurred (check errno).  ENOENT means it was
- *	not an IPv4 network specification.
- * note:
- *	network byte order assumed.  this means 192.5.5.240/28 has
- *	0b11110000 in its fourth octet.
- * author:
- *	Paul Vixie (ISC), June 1996
- */
-static int
-inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
-	static const char xdigits[] = "0123456789abcdef";
-	static const char digits[] = "0123456789";
-	int n, ch, tmp = 0, dirty, bits;
-	const u_char *odst = dst;
-
-	ch = *src++;
-	if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
-	    && isascii((unsigned char)(src[1]))
-	    && isxdigit((unsigned char)(src[1]))) {
-		/* Hexadecimal: Eat nybble string. */
-		if (size <= 0U)
-			goto emsgsize;
-		dirty = 0;
-		src++;	/* skip x or X. */
-		while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) {
-			if (isupper(ch))
-				ch = tolower(ch);
-			n = strchr(xdigits, ch) - xdigits;
-			assert(n >= 0 && n <= 15);
-			if (dirty == 0)
-				tmp = n;
-			else
-				tmp = (tmp << 4) | n;
-			if (++dirty == 2) {
-				if (size-- <= 0U)
-					goto emsgsize;
-				*dst++ = (u_char) tmp;
-				dirty = 0;
-			}
-		}
-		if (dirty) {  /* Odd trailing nybble? */
-			if (size-- <= 0U)
-				goto emsgsize;
-			*dst++ = (u_char) (tmp << 4);
-		}
-	} else if (isascii(ch) && isdigit(ch)) {
-		/* Decimal: eat dotted digit string. */
-		for (;;) {
-			tmp = 0;
-			do {
-				n = strchr(digits, ch) - digits;
-				assert(n >= 0 && n <= 9);
-				tmp *= 10;
-				tmp += n;
-				if (tmp > 255)
-					goto enoent;
-			} while ((ch = *src++) != '\0' &&
-				 isascii(ch) && isdigit(ch));
-			if (size-- <= 0U)
-				goto emsgsize;
-			*dst++ = (u_char) tmp;
-			if (ch == '\0' || ch == '/')
-				break;
-			if (ch != '.')
-				goto enoent;
-			ch = *src++;
-			if (!isascii(ch) || !isdigit(ch))
-				goto enoent;
-		}
-	} else
-		goto enoent;
-
-	bits = -1;
-	if (ch == '/' && isascii((unsigned char)(src[0])) &&
-	    isdigit((unsigned char)(src[0])) && dst > odst) {
-		/* CIDR width specifier.  Nothing can follow it. */
-		ch = *src++;	/* Skip over the /. */
-		bits = 0;
-		do {
-			n = strchr(digits, ch) - digits;
-			assert(n >= 0 && n <= 9);
-			bits *= 10;
-			bits += n;
-		} while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
-		if (ch != '\0')
-			goto enoent;
-		if (bits > 32)
-			goto emsgsize;
-	}
-
-	/* Firey death and destruction unless we prefetched EOS. */
-	if (ch != '\0')
-		goto enoent;
-
-	/* If nothing was written to the destination, we found no address. */
-	if (dst == odst)
-		goto enoent;
-	/* If no CIDR spec was given, infer width from net class. */
-	if (bits == -1) {
-		if (*odst >= 240)	/* Class E */
-			bits = 32;
-		else if (*odst >= 224)	/* Class D */
-			bits = 8;
-		else if (*odst >= 192)	/* Class C */
-			bits = 24;
-		else if (*odst >= 128)	/* Class B */
-			bits = 16;
-		else			/* Class A */
-			bits = 8;
-		/* If imputed mask is narrower than specified octets, widen. */
-		if (bits < ((dst - odst) * 8))
-			bits = (dst - odst) * 8;
-		/*
-		 * If there are no additional bits specified for a class D
-		 * address adjust bits to 4.
-		 */
-		if (bits == 8 && *odst == 224)
-			bits = 4;
-	}
-	/* Extend network to cover the actual mask. */
-	while (bits > ((dst - odst) * 8)) {
-		if (size-- <= 0U)
-			goto emsgsize;
-		*dst++ = '\0';
-	}
-	return (bits);
-
- enoent:
-	errno = ENOENT;
-	return (-1);
-
- emsgsize:
-	errno = EMSGSIZE;
-	return (-1);
-}
-
-static int
-getbits(const char *src, int *bitsp) {
-	static const char digits[] = "0123456789";
-	int n;
-	int val;
-	char ch;
-
-	val = 0;
-	n = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		pch = strchr(digits, ch);
-		if (pch != NULL) {
-			if (n++ != 0 && val == 0)	/* no leading zeros */
-				return (0);
-			val *= 10;
-			val += (pch - digits);
-			if (val > 128)			/* range */
-				return (0);
-			continue;
-		}
-		return (0);
-	}
-	if (n == 0)
-		return (0);
-	*bitsp = val;
-	return (1);
-}
-
-static int
-getv4(const char *src, u_char *dst, int *bitsp) {
-	static const char digits[] = "0123456789";
-	u_char *odst = dst;
-	int n;
-	u_int val;
-	char ch;
-
-	val = 0;
-	n = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		pch = strchr(digits, ch);
-		if (pch != NULL) {
-			if (n++ != 0 && val == 0)	/* no leading zeros */
-				return (0);
-			val *= 10;
-			val += (pch - digits);
-			if (val > 255)			/* range */
-				return (0);
-			continue;
-		}
-		if (ch == '.' || ch == '/') {
-			if (dst - odst > 3)		/* too many octets? */
-				return (0);
-			*dst++ = val;
-			if (ch == '/')
-				return (getbits(src, bitsp));
-			val = 0;
-			n = 0;
-			continue;
-		}
-		return (0);
-	}
-	if (n == 0)
-		return (0);
-	if (dst - odst > 3)		/* too many octets? */
-		return (0);
-	*dst++ = val;
-	return (1);
-}
-
-static int
-inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) {
-	static const char xdigits_l[] = "0123456789abcdef",
-			  xdigits_u[] = "0123456789ABCDEF";
-	u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
-	const char *xdigits, *curtok;
-	int ch, saw_xdigit;
-	u_int val;
-	int digits;
-	int bits;
-	size_t bytes;
-	int words;
-	int ipv4;
-
-	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
-	endp = tp + NS_IN6ADDRSZ;
-	colonp = NULL;
-	/* Leading :: requires some special handling. */
-	if (*src == ':')
-		if (*++src != ':')
-			goto enoent;
-	curtok = src;
-	saw_xdigit = 0;
-	val = 0;
-	digits = 0;
-	bits = -1;
-	ipv4 = 0;
-	while ((ch = *src++) != '\0') {
-		const char *pch;
-
-		if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-			pch = strchr((xdigits = xdigits_u), ch);
-		if (pch != NULL) {
-			val <<= 4;
-			val |= (pch - xdigits);
-			if (++digits > 4)
-				goto enoent;
-			saw_xdigit = 1;
-			continue;
-		}
-		if (ch == ':') {
-			curtok = src;
-			if (!saw_xdigit) {
-				if (colonp)
-					goto enoent;
-				colonp = tp;
-				continue;
-			} else if (*src == '\0')
-				goto enoent;
-			if (tp + NS_INT16SZ > endp)
-				return (0);
-			*tp++ = (u_char) (val >> 8) & 0xff;
-			*tp++ = (u_char) val & 0xff;
-			saw_xdigit = 0;
-			digits = 0;
-			val = 0;
-			continue;
-		}
-		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
-		     getv4(curtok, tp, &bits) > 0) {
-			tp += NS_INADDRSZ;
-			saw_xdigit = 0;
-			ipv4 = 1;
-			break;	/* '\0' was seen by inet_pton4(). */
-		}
-		if (ch == '/' && getbits(src, &bits) > 0)
-			break;
-		goto enoent;
-	}
-	if (saw_xdigit) {
-		if (tp + NS_INT16SZ > endp)
-			goto enoent;
-		*tp++ = (u_char) (val >> 8) & 0xff;
-		*tp++ = (u_char) val & 0xff;
-	}
-	if (bits == -1)
-		bits = 128;
-
-	words = (bits + 15) / 16;
-	if (words < 2)
-		words = 2;
-	if (ipv4)
-		words = 8;
-	endp =  tmp + 2 * words;
-
-	if (colonp != NULL) {
-		/*
-		 * Since some memmove()'s erroneously fail to handle
-		 * overlapping regions, we'll do the shift by hand.
-		 */
-		const int n = tp - colonp;
-		int i;
-
-		if (tp == endp)
-			goto enoent;
-		for (i = 1; i <= n; i++) {
-			endp[- i] = colonp[n - i];
-			colonp[n - i] = 0;
-		}
-		tp = endp;
-	}
-	if (tp != endp)
-		goto enoent;
-
-	bytes = (bits + 7) / 8;
-	if (bytes > size)
-		goto emsgsize;
-	memcpy(dst, tmp, bytes);
-	return (bits);
-
- enoent:
-	errno = ENOENT;
-	return (-1);
-
- emsgsize:
-	errno = EMSGSIZE;
-	return (-1);
-}
-
-/*
- * int
- * inet_net_pton(af, src, dst, size)
- *	convert network number from presentation to network format.
- *	accepts hex octets, hex strings, decimal octets, and /CIDR.
- *	"size" is in bytes and describes "dst".
- * return:
- *	number of bits, either imputed classfully or specified with /CIDR,
- *	or -1 if some failure occurred (check errno).  ENOENT means it was
- *	not a valid network specification.
- * author:
- *	Paul Vixie (ISC), June 1996
- */
-int
-inet_net_pton(int af, const char *src, void *dst, size_t size) {
-	switch (af) {
-	case AF_INET:
-		return (inet_net_pton_ipv4(src, dst, size));
-	case AF_INET6:
-		return (inet_net_pton_ipv6(src, dst, size));
-	default:
-		errno = EAFNOSUPPORT;
-		return (-1);
-	}
-}
-
-/*
- * Weak aliases for applications that use certain private entry points,
- * and fail to include <arpa/inet.h>.
- */
-#undef inet_net_pton
-__weak_reference(__inet_net_pton, inet_net_pton);
--- lib/libc/net/addr2ascii.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 1996 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that both the above copyright notice and this
- * permission notice appear in all copies, that both the above
- * copyright notice and this permission notice appear in all
- * supporting documentation, and that the name of M.I.T. not be used
- * in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  M.I.T. makes
- * no representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied
- * warranty.
- * 
- * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
- * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
- * SHALL M.I.T. 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.
- *
- *	$ANA: addr2ascii.c,v 1.1 1996/06/13 18:41:46 wollman Exp $
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/addr2ascii.c,v 1.2 2002/03/22 21:52:28 obrien Exp $");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include <net/if_dl.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/*-
- * Convert a network address from binary to printable numeric format.
- * This API is copied from INRIA's IPv6 implementation, but it is a
- * bit bogus in two ways:
- *
- *	1) There is no value in passing both an address family and
- *	   an address length; either one should imply the other,
- *	   or we should be passing sockaddrs instead.
- *	2) There should by contrast be /added/ a length for the buffer
- *	   that we pass in, so that programmers are spared the need to
- *	   manually calculate (read: ``guess'') the maximum length.
- *
- * Flash: the API is also the same in the NRL implementation, and seems to
- * be some sort of standard, so we appear to be stuck with both the bad
- * naming and the poor choice of arguments.
- */
-char *
-addr2ascii(af, addrp, len, buf)
-	int af;
-	const void *addrp;
-	int len;		/* should be size_t XXX */
-	char *buf;		/* XXX should pass length of buffer */
-{
-	static char staticbuf[64]; /* 64 for AF_LINK > 16 for AF_INET */
-
-	if (!buf)
-		buf = staticbuf;
-
-	switch(af) {
-	case AF_INET:
-		if (len != sizeof(struct in_addr)) {
-			errno = ENAMETOOLONG;
-			return 0;
-		}
-		strcpy(buf, inet_ntoa(*(const struct in_addr *)addrp));
-		break;
-
-	case AF_LINK:
-		if (len != sizeof(struct sockaddr_dl)) {
-			errno = ENAMETOOLONG;
-			return 0;
-		}
-		strcpy(buf, link_ntoa((const struct sockaddr_dl *)addrp));
-		break;
-			
-	default:
-		errno = EPROTONOSUPPORT;
-		return 0;
-	}
-	return buf;
-}
Index: inet_net.3
===================================================================
RCS file: /home/cvs/src/lib/libc/net/inet_net.3,v
retrieving revision 1.2
retrieving revision 1.3
diff -L lib/libc/net/inet_net.3 -L lib/libc/net/inet_net.3 -u -r1.2 -r1.3
--- lib/libc/net/inet_net.3
+++ lib/libc/net/inet_net.3
@@ -14,10 +14,6 @@
 .\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"        This product includes software developed by the NetBSD
-.\"        Foundation, Inc. and its contributors.
 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
 .\"    contributors may be used to endorse or promote products derived
 .\"    from this software without specific prior written permission.
@@ -34,7 +30,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.2.12.1 2006/03/06 14:53:51 ume Exp $
+.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $
 .\"
 .Dd February 26, 2006
 .Dt INET_NET 3
Index: getaddrinfo.c
===================================================================
RCS file: /home/cvs/src/lib/libc/net/getaddrinfo.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L lib/libc/net/getaddrinfo.c -L lib/libc/net/getaddrinfo.c -u -r1.2 -r1.3
--- lib/libc/net/getaddrinfo.c
+++ lib/libc/net/getaddrinfo.c
@@ -33,7 +33,6 @@
  * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator.
  *
  * Issues to be discussed:
- * - Thread safe-ness must be checked.
  * - Return values.  There are nonstandard return values defined and used
  *   in the source code.  This is because RFC2553 is silent about which error
  *   code must be returned for which situation.
@@ -50,20 +49,12 @@
  *   against NULL hostname (3) what is AI_ADDRCONFIG itself.  AF not ready?
  *   non-loopback address configured?  global address configured?
  *
- * OS specific notes for netbsd/openbsd/freebsd4/bsdi4:
- * - To avoid search order issue, we have a big amount of code duplicate
- *   from gethnamaddr.c and some other places.  The issues that there's no
- *   lower layer function to lookup "IPv4 or IPv6" record.  Calling
- *   gethostbyname2 from getaddrinfo will end up in wrong search order, as
- *   presented above.
- *
  * OS specific notes for freebsd4:
  * - FreeBSD supported $GAI.  The code does not.
- * - FreeBSD allowed classful IPv4 numeric (127.1), the code does not.
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/getaddrinfo.c,v 1.69.2.4 2006/03/29 03:35:59 ume Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/net/getaddrinfo.c,v 1.86 2007/09/05 18:08:14 jinmei Exp $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -103,6 +94,9 @@
 #include <nsswitch.h>
 #include "un-namespace.h"
 #include "libc_private.h"
+#ifdef NS_CACHING
+#include "nscache.h"
+#endif
 
 #if defined(__KAME__) && defined(INET6)
 # define FAITH
@@ -232,7 +226,7 @@
 	u_char buf[MAXPACKET];
 } querybuf;
 
-static int str2number(const char *);
+static int str2number(const char *, int *);
 static int explore_null(const struct addrinfo *,
 	const char *, struct addrinfo **);
 static int explore_numeric(const struct addrinfo *, const char *,
@@ -265,9 +259,9 @@
 static int matchlen(struct sockaddr *, struct sockaddr *);
 
 static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
-	const struct addrinfo *);
+	const struct addrinfo *, res_state);
 #if defined(RESOLVSORT)
-static int addr4sort(struct addrinfo *);
+static int addr4sort(struct addrinfo *, res_state);
 #endif
 static int _dns_getaddrinfo(void *, void *, va_list);
 static void _sethtent(FILE **);
@@ -279,11 +273,16 @@
 static struct addrinfo *_yphostent(char *, const struct addrinfo *);
 static int _yp_getaddrinfo(void *, void *, va_list);
 #endif
+#ifdef NS_CACHING
+static int addrinfo_id_func(char *, size_t *, va_list, void *);
+static int addrinfo_marshal_func(char *, size_t *, void *, va_list, void *);
+static int addrinfo_unmarshal_func(char *, size_t, void *, va_list, void *);
+#endif
 
-static int res_queryN(const char *, struct res_target *);
-static int res_searchN(const char *, struct res_target *);
+static int res_queryN(const char *, struct res_target *, res_state);
+static int res_searchN(const char *, struct res_target *, res_state);
 static int res_querydomainN(const char *, const char *,
-	struct res_target *);
+	struct res_target *, res_state);
 
 /* XXX macros that make external reference is BAD. */
 
@@ -327,8 +326,7 @@
 	((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
 
 void
-freeaddrinfo(ai)
-	struct addrinfo *ai;
+freeaddrinfo(struct addrinfo *ai)
 {
 	struct addrinfo *next;
 
@@ -343,8 +341,7 @@
 }
 
 static int
-str2number(p)
-	const char *p;
+str2number(const char *p, int *portp)
 {
 	char *ep;
 	unsigned long v;
@@ -354,17 +351,16 @@
 	ep = NULL;
 	errno = 0;
 	v = strtoul(p, &ep, 10);
-	if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
-		return v;
-	else
+	if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) {
+		*portp = v;
+		return 0;
+	} else
 		return -1;
 }
 
 int
-getaddrinfo(hostname, servname, hints, res)
-	const char *hostname, *servname;
-	const struct addrinfo *hints;
-	struct addrinfo **res;
+getaddrinfo(const char *hostname, const char *servname,
+    const struct addrinfo *hints, struct addrinfo **res)
 {
 	struct addrinfo sentinel;
 	struct addrinfo *cur;
@@ -579,11 +575,28 @@
 			 * If the returned entry is for an active connection,
 			 * and the given name is not numeric, reorder the
 			 * list, so that the application would try the list
-			 * in the most efficient order.
+			 * in the most efficient order.  Since the head entry
+			 * of the original list may contain ai_canonname and
+			 * that entry may be moved elsewhere in the new list,
+			 * we keep the pointer and will  restore it in the new
+			 * head entry.  (Note that RFC3493 requires the head
+			 * entry store it when requested by the caller).
 			 */
 			if (hints == NULL || !(hints->ai_flags & AI_PASSIVE)) {
-				if (!numeric)
+				if (!numeric) {
+					char *canonname;
+
+					canonname =
+					    sentinel.ai_next->ai_canonname;
+					sentinel.ai_next->ai_canonname = NULL;
 					(void)reorder(&sentinel);
+					if (sentinel.ai_next->ai_canonname ==
+					    NULL) {
+						sentinel.ai_next->ai_canonname
+						    = canonname;
+					} else if (canonname != NULL)
+						free(canonname);
+				}
 			}
 			*res = sentinel.ai_next;
 			return SUCCESS;
@@ -599,8 +612,7 @@
 }
 
 static int
-reorder(sentinel)
-	struct addrinfo *sentinel;
+reorder(struct addrinfo *sentinel)
 {
 	struct addrinfo *ai, **aip;
 	struct ai_order *aio;
@@ -655,8 +667,7 @@
 }
 
 static int
-get_addrselectpolicy(head)
-	struct policyhead *head;
+get_addrselectpolicy(struct policyhead *head)
 {
 #ifdef INET6
 	int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_ADDRCTLPOLICY };
@@ -693,8 +704,7 @@
 }
 
 static void
-free_addrselectpolicy(head)
-	struct policyhead *head;
+free_addrselectpolicy(struct policyhead *head)
 {
 	struct policyqueue *ent, *nent;
 
@@ -706,9 +716,7 @@
 }
 
 static struct policyqueue *
-match_addrselectpolicy(addr, head)
-	struct sockaddr *addr;
-	struct policyhead *head;
+match_addrselectpolicy(struct sockaddr *addr, struct policyhead *head)
 {
 #ifdef INET6
 	struct policyqueue *ent, *bestent = NULL;
@@ -775,9 +783,7 @@
 }
 
 static void
-set_source(aio, ph)
-	struct ai_order *aio;
-	struct policyhead *ph;
+set_source(struct ai_order *aio, struct policyhead *ph)
 {
 	struct addrinfo ai = *aio->aio_ai;
 	struct sockaddr_storage ss;
@@ -843,8 +849,7 @@
 }
 
 static int
-matchlen(src, dst)
-	struct sockaddr *src, *dst;
+matchlen(struct sockaddr *src, struct sockaddr *dst)
 {
 	int match = 0;
 	u_char *s, *d;
@@ -883,8 +888,7 @@
 }
 
 static int
-comp_dst(arg1, arg2)
-	const void *arg1, *arg2;
+comp_dst(const void *arg1, const void *arg2)
 {
 	const struct ai_order *dst1 = arg1, *dst2 = arg2;
 
@@ -1000,8 +1004,7 @@
  * library.
  */
 static int
-gai_addr2scopetype(sa)
-	struct sockaddr *sa;
+gai_addr2scopetype(struct sockaddr *sa)
 {
 #ifdef INET6
 	struct sockaddr_in6 *sa6;
@@ -1063,20 +1066,16 @@
  * non-passive socket -> localhost (127.0.0.1 or ::1)
  */
 static int
-explore_null(pai, servname, res)
-	const struct addrinfo *pai;
-	const char *servname;
-	struct addrinfo **res;
+explore_null(const struct addrinfo *pai, const char *servname,
+    struct addrinfo **res)
 {
 	int s;
 	const struct afd *afd;
-	struct addrinfo *cur;
-	struct addrinfo sentinel;
+	struct addrinfo *ai;
 	int error;
 
 	*res = NULL;
-	sentinel.ai_next = NULL;
-	cur = &sentinel;
+	ai = NULL;
 
 	/*
 	 * filter out AFs that are not supported by the kernel
@@ -1100,26 +1099,19 @@
 		return 0;
 
 	if (pai->ai_flags & AI_PASSIVE) {
-		GET_AI(cur->ai_next, afd, afd->a_addrany);
-		/* xxx meaningless?
-		 * GET_CANONNAME(cur->ai_next, "anyaddr");
-		 */
-		GET_PORT(cur->ai_next, servname);
+		GET_AI(ai, afd, afd->a_addrany);
+		GET_PORT(ai, servname);
 	} else {
-		GET_AI(cur->ai_next, afd, afd->a_loopback);
-		/* xxx meaningless?
-		 * GET_CANONNAME(cur->ai_next, "localhost");
-		 */
-		GET_PORT(cur->ai_next, servname);
+		GET_AI(ai, afd, afd->a_loopback);
+		GET_PORT(ai, servname);
 	}
-	cur = cur->ai_next;
 
-	*res = sentinel.ai_next;
+	*res = ai;
 	return 0;
 
 free:
-	if (sentinel.ai_next)
-		freeaddrinfo(sentinel.ai_next);
+	if (ai != NULL)
+		freeaddrinfo(ai);
 	return error;
 }
 
@@ -1127,22 +1119,16 @@
  * numeric hostname
  */
 static int
-explore_numeric(pai, hostname, servname, res, canonname)
-	const struct addrinfo *pai;
-	const char *hostname;
-	const char *servname;
-	struct addrinfo **res;
-	const char *canonname;
+explore_numeric(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res, const char *canonname)
 {
 	const struct afd *afd;
-	struct addrinfo *cur;
-	struct addrinfo sentinel;
+	struct addrinfo *ai;
 	int error;
 	char pton[PTON_MAX];
 
 	*res = NULL;
-	sentinel.ai_next = NULL;
-	cur = &sentinel;
+	ai = NULL;
 
 	/*
 	 * if the servname does not match socktype/protocol, ignore it.
@@ -1155,57 +1141,48 @@
 		return 0;
 
 	switch (afd->a_af) {
-#if 1 /*X/Open spec*/
 	case AF_INET:
-		if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
-			if (pai->ai_family == afd->a_af ||
-			    pai->ai_family == PF_UNSPEC /*?*/) {
-				GET_AI(cur->ai_next, afd, pton);
-				GET_PORT(cur->ai_next, servname);
-				if ((pai->ai_flags & AI_CANONNAME)) {
-					/*
-					 * Set the numeric address itself as
-					 * the canonical name, based on a
-					 * clarification in rfc3493.
-					 */
-					GET_CANONNAME(cur->ai_next, canonname);
-				}
-				while (cur && cur->ai_next)
-					cur = cur->ai_next;
-			} else
-				ERR(EAI_FAMILY);	/*xxx*/
-		}
+		/*
+		 * RFC3493 requires getaddrinfo() to accept AF_INET formats
+		 * that are accepted by inet_addr() and its family.  The
+		 * accepted forms includes the "classful" one, which inet_pton
+		 * does not accept.  So we need to separate the case for
+		 * AF_INET.
+		 */
+		if (inet_aton(hostname, (struct in_addr *)pton) != 1)
+			return 0;
 		break;
-#endif
 	default:
-		if (inet_pton(afd->a_af, hostname, pton) == 1) {
-			if (pai->ai_family == afd->a_af ||
-			    pai->ai_family == PF_UNSPEC /*?*/) {
-				GET_AI(cur->ai_next, afd, pton);
-				GET_PORT(cur->ai_next, servname);
-				if ((pai->ai_flags & AI_CANONNAME)) {
-					/*
-					 * Set the numeric address itself as
-					 * the canonical name, based on a
-					 * clarification in rfc3493.
-					 */
-					GET_CANONNAME(cur->ai_next, canonname);
-				}
-				while (cur && cur->ai_next)
-					cur = cur->ai_next;
-			} else
-				ERR(EAI_FAMILY);	/* XXX */
-		}
+		if (inet_pton(afd->a_af, hostname, pton) != 1)
+			return 0;
 		break;
 	}
 
-	*res = sentinel.ai_next;
+	if (pai->ai_family == afd->a_af) {
+		GET_AI(ai, afd, pton);
+		GET_PORT(ai, servname);
+		if ((pai->ai_flags & AI_CANONNAME)) {
+			/*
+			 * Set the numeric address itself as the canonical
+			 * name, based on a clarification in RFC3493.
+			 */
+			GET_CANONNAME(ai, canonname);
+		}
+	} else {
+		/*
+		 * XXX: This should not happen since we already matched the AF
+		 * by find_afd.
+		 */
+		ERR(EAI_FAMILY);
+	}
+
+	*res = ai;
 	return 0;
 
 free:
 bad:
-	if (sentinel.ai_next)
-		freeaddrinfo(sentinel.ai_next);
+	if (ai != NULL)
+		freeaddrinfo(ai);
 	return error;
 }
 
@@ -1213,11 +1190,8 @@
  * numeric hostname with scope
  */
 static int
-explore_numeric_scope(pai, hostname, servname, res)
-	const struct addrinfo *pai;
-	const char *hostname;
-	const char *servname;
-	struct addrinfo **res;
+explore_numeric_scope(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res)
 {
 #if !defined(SCOPE_DELIMITER) || !defined(INET6)
 	return explore_numeric(pai, hostname, servname, res, hostname);
@@ -1279,10 +1253,7 @@
 }
 
 static int
-get_canonname(pai, ai, str)
-	const struct addrinfo *pai;
-	struct addrinfo *ai;
-	const char *str;
+get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str)
 {
 	if ((pai->ai_flags & AI_CANONNAME) != 0) {
 		ai->ai_canonname = strdup(str);
@@ -1293,10 +1264,7 @@
 }
 
 static struct addrinfo *
-get_ai(pai, afd, addr)
-	const struct addrinfo *pai;
-	const struct afd *afd;
-	const char *addr;
+get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr)
 {
 	char *p;
 	struct addrinfo *ai;
@@ -1364,9 +1332,7 @@
 }
 
 static int
-get_portmatch(ai, servname)
-	const struct addrinfo *ai;
-	const char *servname;
+get_portmatch(const struct addrinfo *ai, const char *servname)
 {
 
 	/* get_port does not touch first argument when matchonly == 1. */
@@ -1375,14 +1341,11 @@
 }
 
 static int
-get_port(ai, servname, matchonly)
-	struct addrinfo *ai;
-	const char *servname;
-	int matchonly;
+get_port(struct addrinfo *ai, const char *servname, int matchonly)
 {
 	const char *proto;
 	struct servent *sp;
-	int port;
+	int port, error;
 	int allownumeric;
 
 	if (servname == NULL)
@@ -1411,8 +1374,8 @@
 		return EAI_SOCKTYPE;
 	}
 
-	port = str2number(servname);
-	if (port >= 0) {
+	error = str2number(servname, &port);
+	if (error == 0) {
 		if (!allownumeric)
 			return EAI_SERVICE;
 		if (port < 0 || port > 65535)
@@ -1457,8 +1420,7 @@
 }
 
 static const struct afd *
-find_afd(af)
-	int af;
+find_afd(int af)
 {
 	const struct afd *afd;
 
@@ -1481,8 +1443,7 @@
  * _dns_getaddrinfo.
  */
 static int
-addrconfig(pai)
-	struct addrinfo *pai;
+addrconfig(struct addrinfo *pai)
 {
 	int s, af;
 
@@ -1517,10 +1478,7 @@
 #ifdef INET6
 /* convert a string to a scope identifier. XXX: IPv6 specific */
 static int
-ip6_str2scopeid(scope, sin6, scopeid)
-	char *scope;
-	struct sockaddr_in6 *sin6;
-	u_int32_t *scopeid;
+ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid)
 {
 	u_long lscopeid;
 	struct in6_addr *a6;
@@ -1564,23 +1522,209 @@
 }
 #endif
 
+
+#ifdef NS_CACHING
+static int
+addrinfo_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 = 0;	/* identifies the getaddrinfo for the cache */
+	char *hostname;
+	struct addrinfo *hints;
+
+	char *p;
+	int ai_flags, ai_family, ai_socktype, ai_protocol;
+	size_t desired_size, size;
+
+	statp = __res_state();
+	res_options = statp->options & (RES_RECURSE | RES_DEFNAMES |
+	    RES_DNSRCH | RES_NOALIASES | RES_USE_INET6);
+
+	hostname = va_arg(ap, char *);
+	hints = va_arg(ap, struct addrinfo *);
+
+	desired_size = sizeof(res_options) + sizeof(int) + sizeof(int) * 4;
+	if (hostname != NULL) {
+		size = strlen(hostname);
+		desired_size += size + 1;
+	} else
+		size = 0;
+
+	if (desired_size > *buffer_size) {
+		*buffer_size = desired_size;
+		return (NS_RETURN);
+	}
+
+	if (hints == NULL)
+		ai_flags = ai_family = ai_socktype = ai_protocol = 0;
+	else {
+		ai_flags = hints->ai_flags;
+		ai_family = hints->ai_family;
+		ai_socktype = hints->ai_socktype;
+		ai_protocol = hints->ai_protocol;
+	}
+
+	p = buffer;
+	memcpy(p, &res_options, sizeof(res_options));
+	p += sizeof(res_options);
+
+	memcpy(p, &op_id, sizeof(int));
+	p += sizeof(int);
+
+	memcpy(p, &ai_flags, sizeof(int));
+	p += sizeof(int);
+
+	memcpy(p, &ai_family, sizeof(int));
+	p += sizeof(int);
+
+	memcpy(p, &ai_socktype, sizeof(int));
+	p += sizeof(int);
+
+	memcpy(p, &ai_protocol, sizeof(int));
+	p += sizeof(int);
+
+	if (hostname != NULL)
+		memcpy(p, hostname, size);
+
+	*buffer_size = desired_size;
+	return (NS_SUCCESS);
+}
+
+static int
+addrinfo_marshal_func(char *buffer, size_t *buffer_size, void *retval,
+    va_list ap, void *cache_mdata)
+{
+	struct addrinfo	*ai, *cai;
+	char *p;
+	size_t desired_size, size, ai_size;
+
+	ai = *((struct addrinfo **)retval);
+
+	desired_size = sizeof(size_t);
+	ai_size = 0;
+	for (cai = ai; cai != NULL; cai = cai->ai_next) {
+		desired_size += sizeof(struct addrinfo) + cai->ai_addrlen;
+		if (cai->ai_canonname != NULL)
+			desired_size += sizeof(size_t) +
+			    strlen(cai->ai_canonname);
+		++ai_size;
+	}
+
+	if (desired_size > *buffer_size) {
+		/* this assignment is here for future use */
+		errno = ERANGE;
+		*buffer_size = desired_size;
+		return (NS_RETURN);
+	}
+
+	memset(buffer, 0, desired_size);
+	p = buffer;
+
+	memcpy(p, &ai_size, sizeof(size_t));
+	p += sizeof(size_t);
+	for (cai = ai; cai != NULL; cai = cai->ai_next) {
+		memcpy(p, cai, sizeof(struct addrinfo));
+		p += sizeof(struct addrinfo);
+
+		memcpy(p, cai->ai_addr, cai->ai_addrlen);
+		p += cai->ai_addrlen;
+
+		if (cai->ai_canonname != NULL) {
+			size = strlen(cai->ai_canonname);
+			memcpy(p, &size, sizeof(size_t));
+			p += sizeof(size_t);
+
+			memcpy(p, cai->ai_canonname, size);
+			p += size;
+		}
+	}
+
+	return (NS_SUCCESS);
+}
+
+static int
+addrinfo_unmarshal_func(char *buffer, size_t buffer_size, void *retval,
+    va_list ap, void *cache_mdata)
+{
+	struct addrinfo	new_ai, *result, *sentinel, *lasts;
+
+	char *p;
+	size_t ai_size, ai_i, size;
+
+	p = buffer;
+	memcpy(&ai_size, p, sizeof(size_t));
+	p += sizeof(size_t);
+
+	result = NULL;
+	lasts = NULL;
+	for (ai_i = 0; ai_i < ai_size; ++ai_i) {
+		memcpy(&new_ai, p, sizeof(struct addrinfo));
+		p += sizeof(struct addrinfo);
+		size = new_ai.ai_addrlen + sizeof(struct addrinfo) +
+			_ALIGNBYTES;
+
+		sentinel = (struct addrinfo *)malloc(size);
+		memset(sentinel, 0, size);
+
+		memcpy(sentinel, &new_ai, sizeof(struct addrinfo));
+		sentinel->ai_addr = (struct sockaddr *)_ALIGN((char *)sentinel +
+		    sizeof(struct addrinfo));
+
+		memcpy(sentinel->ai_addr, p, new_ai.ai_addrlen);
+		p += new_ai.ai_addrlen;
+
+		if (new_ai.ai_canonname != NULL) {
+			memcpy(&size, p, sizeof(size_t));
+			p += sizeof(size_t);
+
+			sentinel->ai_canonname = (char *)malloc(size + 1);
+			memset(sentinel->ai_canonname, 0, size + 1);
+
+			memcpy(sentinel->ai_canonname, p, size);
+			p += size;
+		}
+
+		if (result == NULL) {
+			result = sentinel;
+			lasts = sentinel;
+		} else {
+			lasts->ai_next = sentinel;
+			lasts = sentinel;
+		}
+	}
+
+	*((struct addrinfo **)retval) = result;
+	return (NS_SUCCESS);
+}
+#endif /* NS_CACHING */
+
 /*
  * FQDN hostname, DNS lookup
  */
 static int
-explore_fqdn(pai, hostname, servname, res)
-	const struct addrinfo *pai;
-	const char *hostname;
-	const char *servname;
-	struct addrinfo **res;
+explore_fqdn(const struct addrinfo *pai, const char *hostname,
+    const char *servname, struct addrinfo **res)
 {
 	struct addrinfo *result;
 	struct addrinfo *cur;
 	int error = 0;
+
+#ifdef NS_CACHING
+	static const nss_cache_info cache_info =
+	NS_COMMON_CACHE_INFO_INITIALIZER(
+		hosts, NULL, addrinfo_id_func, addrinfo_marshal_func,
+		addrinfo_unmarshal_func);
+#endif
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_files_getaddrinfo, NULL)
 		{ NSSRC_DNS, _dns_getaddrinfo, NULL },	/* force -DHESIOD */
 		NS_NIS_CB(_yp_getaddrinfo, NULL)
+#ifdef NS_CACHING
+		NS_CACHE_CB(&cache_info)
+#endif
 		{ 0 }
 	};
 
@@ -1628,12 +1772,8 @@
 #endif
 
 static struct addrinfo *
-getanswer(answer, anslen, qname, qtype, pai)
-	const querybuf *answer;
-	int anslen;
-	const char *qname;
-	int qtype;
-	const struct addrinfo *pai;
+getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
+    const struct addrinfo *pai, res_state res)
 {
 	struct addrinfo sentinel, *cur;
 	struct addrinfo ai;
@@ -1674,12 +1814,12 @@
 	ep = hostbuf + sizeof hostbuf;
 	cp = answer->buf + HFIXEDSZ;
 	if (qdcount != 1) {
-		h_errno = NO_RECOVERY;
+		RES_SET_H_ERRNO(res, NO_RECOVERY);
 		return (NULL);
 	}
 	n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
 	if ((n < 0) || !(*name_ok)(bp)) {
-		h_errno = NO_RECOVERY;
+		RES_SET_H_ERRNO(res, NO_RECOVERY);
 		return (NULL);
 	}
 	cp += n + QFIXEDSZ;
@@ -1690,7 +1830,7 @@
 		 */
 		n = strlen(bp) + 1;		/* for the \0 */
 		if (n >= MAXHOSTNAMELEN) {
-			h_errno = NO_RECOVERY;
+			RES_SET_H_ERRNO(res, NO_RECOVERY);
 			return (NULL);
 		}
 		canonname = bp;
@@ -1817,10 +1957,10 @@
 		 * We support only IPv4 address for backward
 		 * compatibility against gethostbyname(3).
 		 */
-		if (_res.nsort && qtype == T_A) {
-			if (addr4sort(&sentinel) < 0) {
+		if (res->nsort && qtype == T_A) {
+			if (addr4sort(&sentinel, res) < 0) {
 				freeaddrinfo(sentinel.ai_next);
-				h_errno = NO_RECOVERY;
+				RES_SET_H_ERRNO(res, NO_RECOVERY);
 				return NULL;
 			}
 		}
@@ -1829,11 +1969,11 @@
 			(void)get_canonname(pai, sentinel.ai_next, qname);
 		else
 			(void)get_canonname(pai, sentinel.ai_next, canonname);
-		h_errno = NETDB_SUCCESS;
+		RES_SET_H_ERRNO(res, NETDB_SUCCESS);
 		return sentinel.ai_next;
 	}
 
-	h_errno = NO_RECOVERY;
+	RES_SET_H_ERRNO(res, NO_RECOVERY);
 	return NULL;
 }
 
@@ -1844,7 +1984,7 @@
 };
 
 static int
-addr4sort(struct addrinfo *sentinel)
+addr4sort(struct addrinfo *sentinel, res_state res)
 {
 	struct addrinfo *ai;
 	struct addr_ptr *addrs, addr;
@@ -1864,9 +2004,9 @@
 	i = 0;
 	for (ai = sentinel->ai_next; ai; ai = ai->ai_next) {
 		sin = (struct sockaddr_in *)ai->ai_addr;
-		for (j = 0; (unsigned)j < _res.nsort; j++) {
-			if (_res.sort_list[j].addr.s_addr == 
-			    (sin->sin_addr.s_addr & _res.sort_list[j].mask))
+		for (j = 0; (unsigned)j < res->nsort; j++) {
+			if (res->sort_list[j].addr.s_addr ==
+			    (sin->sin_addr.s_addr & res->sort_list[j].mask))
 				break;
 		}
 		addrs[i].ai = ai;
@@ -1881,15 +2021,15 @@
 	}
 
 	while (needsort < naddrs) {
-	    for (j = needsort - 1; j >= 0; j--) {
-		if (addrs[j].aval > addrs[j+1].aval) {
-		    addr = addrs[j];
-		    addrs[j] = addrs[j + 1];
-		    addrs[j + 1] = addr;
-		} else
-		    break;
-	    }
-	    needsort++;
+		for (j = needsort - 1; j >= 0; j--) {
+			if (addrs[j].aval > addrs[j+1].aval) {
+				addr = addrs[j];
+				addrs[j] = addrs[j + 1];
+				addrs[j + 1] = addr;
+			} else
+				break;
+		}
+		needsort++;
 	}
 
 	ai = sentinel;
@@ -1905,10 +2045,7 @@
 
 /*ARGSUSED*/
 static int
-_dns_getaddrinfo(rv, cb_data, ap)
-	void	*rv;
-	void	*cb_data;
-	va_list	 ap;
+_dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
 {
 	struct addrinfo *ai;
 	querybuf *buf, *buf2;
@@ -1916,24 +2053,25 @@
 	const struct addrinfo *pai;
 	struct addrinfo sentinel, *cur;
 	struct res_target q, q2;
+	res_state res;
 
 	hostname = va_arg(ap, char *);
 	pai = va_arg(ap, const struct addrinfo *);
 
-	memset(&q, 0, sizeof(q2));
+	memset(&q, 0, sizeof(q));
 	memset(&q2, 0, sizeof(q2));
 	memset(&sentinel, 0, sizeof(sentinel));
 	cur = &sentinel;
 
 	buf = malloc(sizeof(*buf));
 	if (!buf) {
-		h_errno = NETDB_INTERNAL;
+		RES_SET_H_ERRNO(res, NETDB_INTERNAL);
 		return NS_NOTFOUND;
 	}
 	buf2 = malloc(sizeof(*buf2));
 	if (!buf2) {
 		free(buf);
-		h_errno = NETDB_INTERNAL;
+		RES_SET_H_ERRNO(res, NETDB_INTERNAL);
 		return NS_NOTFOUND;
 	}
 
@@ -1970,27 +2108,36 @@
 		free(buf2);
 		return NS_UNAVAIL;
 	}
-	if (res_searchN(hostname, &q) < 0) {
+
+	res = __res_state();
+	if ((res->options & RES_INIT) == 0 && res_ninit(res) == -1) {
+		RES_SET_H_ERRNO(res, NETDB_INTERNAL);
+		free(buf);
+		free(buf2);
+		return NS_NOTFOUND;
+	}
+
+	if (res_searchN(hostname, &q, res) < 0) {
 		free(buf);
 		free(buf2);
 		return NS_NOTFOUND;
 	}
 	/* prefer IPv6 */
 	if (q.next) {
-		ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai);
+		ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai, res);
 		if (ai) {
 			cur->ai_next = ai;
 			while (cur && cur->ai_next)
 				cur = cur->ai_next;
 		}
 	}
-	ai = getanswer(buf, q.n, q.name, q.qtype, pai);
+	ai = getanswer(buf, q.n, q.name, q.qtype, pai, res);
 	if (ai)
 		cur->ai_next = ai;
 	free(buf);
 	free(buf2);
 	if (sentinel.ai_next == NULL)
-		switch (h_errno) {
+		switch (res->res_h_errno) {
 		case HOST_NOT_FOUND:
 			return NS_NOTFOUND;
 		case TRY_AGAIN:
@@ -2097,10 +2244,7 @@
 
 /*ARGSUSED*/
 static int
-_files_getaddrinfo(rv, cb_data, ap)
-	void	*rv;
-	void	*cb_data;
-	va_list	 ap;
+_files_getaddrinfo(void *rv, void *cb_data, va_list ap)
 {
 	const char *name;
 	const struct addrinfo *pai;
@@ -2131,9 +2275,7 @@
 #ifdef YP
 /*ARGSUSED*/
 static struct addrinfo *
-_yphostent(line, pai)
-	char *line;
-	const struct addrinfo *pai;
+_yphostent(char *line, const struct addrinfo *pai)
 {
 	struct addrinfo sentinel, *cur;
 	struct addrinfo hints, *res, *res0;
@@ -2209,10 +2351,7 @@
 
 /*ARGSUSED*/
 static int
-_yp_getaddrinfo(rv, cb_data, ap)
-	void	*rv;
-	void	*cb_data;
-	va_list	 ap;
+_yp_getaddrinfo(void *rv, void *cb_data, va_list ap)
 {
 	struct addrinfo sentinel, *cur;
 	struct addrinfo *ai = NULL;
@@ -2261,7 +2400,7 @@
 	}
 
 	if (sentinel.ai_next == NULL) {
-		h_errno = HOST_NOT_FOUND;
+		RES_SET_H_ERRNO(__res_state(), HOST_NOT_FOUND);
 		return NS_NOTFOUND;
 	}
 	*((struct addrinfo **)rv) = sentinel.ai_next;
@@ -2271,8 +2410,6 @@
 
 /* resolver logic */
 
-extern const char *_res_hostalias(const char *, char *, size_t);
-
 /*
  * Formulate a normal query, send, and await answer.
  * Returned answer is placed in supplied buffer "answer".
@@ -2284,13 +2421,12 @@
  * Caller must parse answer and determine whether it answers the question.
  */
 static int
-res_queryN(name, target)
-	const char *name;	/* domain name */
-	struct res_target *target;
+res_queryN(const char *name, struct res_target *target, res_state res)
 {
 	u_char *buf;
 	HEADER *hp;
 	int n;
+	u_int oflags;
 	struct res_target *t;
 	int rcode;
 	int ancount;
@@ -2300,7 +2436,7 @@
 
 	buf = malloc(MAXPACKET);
 	if (!buf) {
-		h_errno = NETDB_INTERNAL;
+		RES_SET_H_ERRNO(res, NETDB_INTERNAL);
 		return -1;
 	}
 
@@ -2310,50 +2446,65 @@
 		int anslen;
 
 		hp = (HEADER *)(void *)t->answer;
-		hp->rcode = NOERROR;	/* default */
 
 		/* make it easier... */
 		class = t->qclass;
 		type = t->qtype;
 		answer = t->answer;
 		anslen = t->anslen;
+
+		oflags = res->_flags;
+
+again:
+		hp->rcode = NOERROR;	/* default */
+
 #ifdef DEBUG
-		if (_res.options & RES_DEBUG)
+		if (res->options & RES_DEBUG)
 			printf(";; res_query(%s, %d, %d)\n", name, class, type);
 #endif
 
-		n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
+		n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL,
 		    buf, MAXPACKET);
-		if (n > 0 && (_res.options & RES_USE_EDNS0) != 0)
-			n = res_opt(n, buf, MAXPACKET, anslen);
+		if (n > 0 && (res->_flags & RES_F_EDNS0ERR) == 0 &&
+		    (res->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U)
+			n = res_nopt(res, n, buf, MAXPACKET, anslen);
 		if (n <= 0) {
 #ifdef DEBUG
-			if (_res.options & RES_DEBUG)
+			if (res->options & RES_DEBUG)
 				printf(";; res_query: mkquery failed\n");
 #endif
 			free(buf);
-			h_errno = NO_RECOVERY;
+			RES_SET_H_ERRNO(res, NO_RECOVERY);
 			return (n);
 		}
-		n = res_send(buf, n, answer, anslen);
-#if 0
+		n = res_nsend(res, buf, n, answer, anslen);
 		if (n < 0) {
+			/*
+			 * if the query choked with EDNS0, retry
+			 * without EDNS0
+			 */
+			if ((res->options & (RES_USE_EDNS0|RES_USE_DNSSEC))
+			    != 0U &&
+			    ((oflags ^ res->_flags) & RES_F_EDNS0ERR) != 0) {
+				res->_flags |= RES_F_EDNS0ERR;
+				if (res->options & RES_DEBUG)
+					printf(";; res_nquery: retry without EDNS0\n");
+				goto again;
+			}
+			rcode = hp->rcode;	/* record most recent error */
 #ifdef DEBUG
-			if (_res.options & RES_DEBUG)
+			if (res->options & RES_DEBUG)
 				printf(";; res_query: send error\n");
 #endif
-			free(buf);
-			h_errno = TRY_AGAIN;
-			return (n);
+			continue;
 		}
-#endif
 
 		if (n > anslen)
 			hp->rcode = FORMERR; /* XXX not very informative */
-		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
+		if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
 			rcode = hp->rcode;	/* record most recent error */
 #ifdef DEBUG
-			if (_res.options & RES_DEBUG)
+			if (res->options & RES_DEBUG)
 				printf(";; rcode = %u, ancount=%u\n", hp->rcode,
 				    ntohs(hp->ancount));
 #endif
@@ -2370,19 +2521,19 @@
 	if (ancount == 0) {
 		switch (rcode) {
 		case NXDOMAIN:
-			h_errno = HOST_NOT_FOUND;
+			RES_SET_H_ERRNO(res, HOST_NOT_FOUND);
 			break;
 		case SERVFAIL:
-			h_errno = TRY_AGAIN;
+			RES_SET_H_ERRNO(res, TRY_AGAIN);
 			break;
 		case NOERROR:
-			h_errno = NO_DATA;
+			RES_SET_H_ERRNO(res, NO_DATA);
 			break;
 		case FORMERR:
 		case NOTIMP:
 		case REFUSED:
 		default:
-			h_errno = NO_RECOVERY;
+			RES_SET_H_ERRNO(res, NO_RECOVERY);
 			break;
 		}
 		return (-1);
@@ -2397,9 +2548,7 @@
  * is detected.  Error code, if any, is left in h_errno.
  */
 static int
-res_searchN(name, target)
-	const char *name;	/* domain name */
-	struct res_target *target;
+res_searchN(const char *name, struct res_target *target, res_state res)
 {
 	const char *cp, * const *domain;
 	HEADER *hp = (HEADER *)(void *)target->answer;	/*XXX*/
@@ -2410,13 +2559,8 @@
 	int searched = 0;
 	char abuf[MAXDNAME];
 
-	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-		h_errno = NETDB_INTERNAL;
-		return (-1);
-	}
-
 	errno = 0;
-	h_errno = HOST_NOT_FOUND;	/* default, if we never query */
+	RES_SET_H_ERRNO(res, HOST_NOT_FOUND); /* default, if we never query */
 	dots = 0;
 	for (cp = name; *cp; cp++)
 		dots += (*cp == '.');
@@ -2427,8 +2571,9 @@
 	/*
 	 * if there aren't any dots, it could be a user-level alias
 	 */
-	if (!dots && (cp = _res_hostalias(name, abuf, sizeof(abuf))) != NULL)
-		return (res_queryN(cp, target));
+	if (!dots &&
+	    (cp = res_hostalias(res, name, abuf, sizeof(abuf))) != NULL)
+		return (res_queryN(cp, target, res));
 
 	/*
 	 * If there are enough dots in the name, let's just give it a
@@ -2436,15 +2581,15 @@
 	 * Also, query 'as is', if there is a trailing dot in the name.
 	 */
 	saved_herrno = -1;
-	if (dots >= _res.ndots || trailing_dot) {
-		ret = res_querydomainN(name, NULL, target);
+	if (dots >= res->ndots || trailing_dot) {
+		ret = res_querydomainN(name, NULL, target, res);
 		if (ret > 0 || trailing_dot)
 			return (ret);
 		if (errno == ECONNREFUSED) {
-			h_errno = TRY_AGAIN;
+			RES_SET_H_ERRNO(res, TRY_AGAIN);
 			return (-1);
 		}
-		switch (h_errno) {
+		switch (res->res_h_errno) {
 		case NO_DATA:
 		case HOST_NOT_FOUND:
 			break;
@@ -2455,7 +2600,7 @@
 		default:
 			return (-1);
 		}
-		saved_herrno = h_errno;
+		saved_herrno = res->res_h_errno;
 		tried_as_is++;
 	}
 
@@ -2465,11 +2610,11 @@
 	 *	- there is at least one dot, there is no trailing dot,
 	 *	  and RES_DNSRCH is set.
 	 */
-	if ((!dots && (_res.options & RES_DEFNAMES)) ||
-	    (dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
+	if ((!dots && (res->options & RES_DEFNAMES)) ||
+	    (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
 		int done = 0;
 
-		for (domain = (const char * const *)_res.dnsrch;
+		for (domain = (const char * const *)res->dnsrch;
 		   *domain && !done;
 		   domain++) {
 			searched = 1;
@@ -2481,7 +2626,7 @@
 			if (root_on_list && tried_as_is)
 				continue;
 
-			ret = res_querydomainN(name, *domain, target);
+			ret = res_querydomainN(name, *domain, target, res);
 			if (ret > 0)
 				return (ret);
 
@@ -2499,11 +2644,11 @@
 			 * fully-qualified.
 			 */
 			if (errno == ECONNREFUSED) {
-				h_errno = TRY_AGAIN;
+				RES_SET_H_ERRNO(res, TRY_AGAIN);
 				return (-1);
 			}
 
-			switch (h_errno) {
+			switch (res->res_h_errno) {
 			case NO_DATA:
 				got_nodata++;
 				/* FALLTHROUGH */
@@ -2525,12 +2670,12 @@
 			 * if we got here for some reason other than DNSRCH,
 			 * we only wanted one iteration of the loop, so stop.
 			 */
-			if (!(_res.options & RES_DNSRCH))
+			if (!(res->options & RES_DNSRCH))
 			        done++;
 		}
 	}
 
-	switch (h_errno) {
+	switch (res->res_h_errno) {
 	case NO_DATA:
 	case HOST_NOT_FOUND:
 		break;
@@ -2546,9 +2691,9 @@
 	 * If the query has not already been tried as is then try it
 	 * unless RES_NOTLDQUERY is set and there were no dots.
 	 */
-	if ((dots || !searched || !(_res.options & RES_NOTLDQUERY)) &&
+	if ((dots || !searched || !(res->options & RES_NOTLDQUERY)) &&
 	    !(tried_as_is || root_on_list)) {
-		ret = res_querydomainN(name, NULL, target);
+		ret = res_querydomainN(name, NULL, target, res);
 		if (ret > 0)
 			return (ret);
 	}
@@ -2563,11 +2708,11 @@
 	 */
 giveup:
 	if (saved_herrno != -1)
-		h_errno = saved_herrno;
+		RES_SET_H_ERRNO(res, saved_herrno);
 	else if (got_nodata)
-		h_errno = NO_DATA;
+		RES_SET_H_ERRNO(res, NO_DATA);
 	else if (got_servfail)
-		h_errno = TRY_AGAIN;
+		RES_SET_H_ERRNO(res, TRY_AGAIN);
 	return (-1);
 }
 
@@ -2576,16 +2721,15 @@
  * removing a trailing dot from name if domain is NULL.
  */
 static int
-res_querydomainN(name, domain, target)
-	const char *name, *domain;
-	struct res_target *target;
+res_querydomainN(const char *name, const char *domain,
+    struct res_target *target, res_state res)
 {
 	char nbuf[MAXDNAME];
 	const char *longname = nbuf;
 	size_t n, d;
 
 #ifdef DEBUG
-	if (_res.options & RES_DEBUG)
+	if (res->options & RES_DEBUG)
 		printf(";; res_querydomain(%s, %s)\n",
 			name, domain?domain:"<Nil>");
 #endif
@@ -2596,7 +2740,7 @@
 		 */
 		n = strlen(name);
 		if (n >= MAXDNAME) {
-			h_errno = NO_RECOVERY;
+			RES_SET_H_ERRNO(res, NO_RECOVERY);
 			return (-1);
 		}
 		if (n > 0 && name[--n] == '.') {
@@ -2608,10 +2752,10 @@
 		n = strlen(name);
 		d = strlen(domain);
 		if (n + d + 1 >= MAXDNAME) {
-			h_errno = NO_RECOVERY;
+			RES_SET_H_ERRNO(res, NO_RECOVERY);
 			return (-1);
 		}
 		snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
 	}
-	return (res_queryN(longname, target));
+	return (res_queryN(longname, target, res));
 }


More information about the Midnightbsd-cvs mailing list