diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 41cbc11f2cf1..e1c842014db7 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -1,7 +1,9 @@ /* + * ++Copyright++ 1983, 1993 + * - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * + * 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: @@ -12,12 +14,12 @@ * 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. + * 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 @@ -31,7 +33,7 @@ * 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 @@ -47,9 +49,13 @@ * 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-- + */ + +/* * @(#)inet.h 8.1 (Berkeley) 6/2/93 - * From: Id: inet.h,v 8.5 1997/01/29 08:48:09 vixie Exp $ + * $Id: inet.h,v 1.1.206.1 2004/03/09 08:33:30 marka Exp $ * $FreeBSD$ */ @@ -112,20 +118,22 @@ struct in_addr { /* XXX all new diversions!! argh!! */ #if __BSD_VISIBLE -#define inet_addr __inet_addr -#define inet_aton __inet_aton -#define inet_lnaof __inet_lnaof -#define inet_makeaddr __inet_makeaddr -#define inet_neta __inet_neta -#define inet_netof __inet_netof -#define inet_network __inet_network -#define inet_net_ntop __inet_net_ntop -#define inet_net_pton __inet_net_pton -#define inet_ntoa __inet_ntoa -#define inet_pton __inet_pton -#define inet_ntop __inet_ntop -#define inet_nsap_addr __inet_nsap_addr -#define inet_nsap_ntoa __inet_nsap_ntoa +#define inet_addr __inet_addr +#define inet_aton __inet_aton +#define inet_lnaof __inet_lnaof +#define inet_makeaddr __inet_makeaddr +#define inet_neta __inet_neta +#define inet_netof __inet_netof +#define inet_network __inet_network +#define inet_net_ntop __inet_net_ntop +#define inet_net_pton __inet_net_pton +#define inet_cidr_ntop __inet_cidr_ntop +#define inet_cidr_pton __inet_cidr_pton +#define inet_ntoa __inet_ntoa +#define inet_pton __inet_pton +#define inet_ntop __inet_ntop +#define inet_nsap_addr __inet_nsap_addr +#define inet_nsap_ntoa __inet_nsap_ntoa #endif /* __BSD_VISIBLE */ __BEGIN_DECLS @@ -138,7 +146,7 @@ uint16_t ntohs(uint16_t); #endif in_addr_t inet_addr(const char *); -char *inet_ntoa(struct in_addr); +/*const*/ char *inet_ntoa(struct in_addr); const char *inet_ntop(int, const void * __restrict, char * __restrict, socklen_t); int inet_pton(int, const char * __restrict, void * __restrict); @@ -154,6 +162,8 @@ in_addr_t inet_netof(struct in_addr); in_addr_t inet_network(const char *); char *inet_net_ntop(int, const void *, int, char *, size_t); int inet_net_pton(int, const char *, void *, size_t); +char *inet_cidr_ntop(int, const void *, int, char *, size_t); +int inet_cidr_pton(int, const char *, void *, int *); unsigned inet_nsap_addr(const char *, unsigned char *, int); char *inet_nsap_ntoa(int, const unsigned char *, char *); #endif /* __BSD_VISIBLE */ diff --git a/include/arpa/nameser.h b/include/arpa/nameser.h index 224e24dd7181..f0d4ff94dfa3 100644 --- a/include/arpa/nameser.h +++ b/include/arpa/nameser.h @@ -32,24 +32,24 @@ */ /* - * Copyright (c) 1996 by Internet Software Consortium. + * 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 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. + * 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. */ /* - * From: Id: nameser.h,v 8.16 1998/02/06 00:35:58 halley Exp + * $Id: nameser.h,v 1.2.2.4.4.1 2004/03/09 08:33:30 marka Exp $ * $FreeBSD$ */ @@ -58,25 +58,26 @@ #define BIND_4_COMPAT +#include #include #include /* - * revision information. this is the release date in YYYYMMDD format. - * it can change every day so the right thing to do with it is use it - * in preprocessor commands such as "#if (__NAMESER > 19931104)". do not - * compare for equality; rather, use it to determine whether your libnameser.a - * is new enough to contain a certain feature. + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not + * compare for equality; rather, use it to determine whether your libbind.a + * contains a new enough lib/nameser/ to support the feature you need. */ -/* XXXRTH I made this bigger than __BIND in 4.9.5 T6B */ -#define __NAMESER 19961001 /* New interface version stamp. */ +#define __NAMESER 19991006 /* New interface version stamp. */ /* * Define constants based on RFC 883, RFC 1034, RFC 1035 */ -#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_PACKETSZ 512 /* default UDP packet size */ #define NS_MAXDNAME 1025 /* maximum domain name */ +#define NS_MAXMSG 65535 /* maximum message size */ #define NS_MAXCDNAME 255 /* maximum compressed domain name */ #define NS_MAXLABEL 63 /* maximum length of domain label */ #define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ @@ -116,7 +117,7 @@ typedef struct __ns_msg { const u_char *_sections[ns_s_max]; ns_sect _sect; int _rrnum; - const u_char *_ptr; + const u_char *_msg_ptr; } ns_msg; /* Private data structure - do not use from outside library. */ @@ -124,10 +125,7 @@ struct _ns_flagdata { int mask, shift; }; extern struct _ns_flagdata _ns_flagdata[]; /* Accessor macros - this is part of the public interface. */ -#define ns_msg_getflag(handle, flag) ( \ - ((handle)._flags & _ns_flagdata[flag].mask) \ - >> _ns_flagdata[flag].shift \ - ) + #define ns_msg_id(handle) ((handle)._id + 0) #define ns_msg_base(handle) ((handle)._msg + 0) #define ns_msg_end(handle) ((handle)._eom + 0) @@ -138,18 +136,18 @@ extern struct _ns_flagdata _ns_flagdata[]; * This is a parsed record. It is caller allocated and has no dynamic data. */ typedef struct __ns_rr { - char name[NS_MAXDNAME]; /* XXX need to malloc */ + char name[NS_MAXDNAME]; u_int16_t type; u_int16_t rr_class; u_int32_t ttl; u_int16_t rdlength; - const u_char *rdata; + const u_char * rdata; } ns_rr; /* Accessor macros - this is part of the public interface. */ #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") -#define ns_rr_type(rr) ((rr).type + 0) -#define ns_rr_class(rr) ((rr).rr_class + 0) +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) #define ns_rr_ttl(rr) ((rr).ttl + 0) #define ns_rr_rdlen(rr) ((rr).rdlength + 0) #define ns_rr_rdata(rr) ((rr).rdata + 0) @@ -202,7 +200,13 @@ typedef enum __ns_rcode { ns_r_nxrrset = 8, /* RRset does not exist */ ns_r_notauth = 9, /* Not authoritative for zone */ ns_r_notzone = 10, /* Zone of record different from zone section */ - ns_r_max = 11 + ns_r_max = 11, + /* The following are EDNS extended rcodes */ + ns_r_badvers = 16, + /* The following are TSIG errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 } ns_rcode; /* BIND_UPDATE */ @@ -213,31 +217,40 @@ typedef enum __ns_update_operation { } ns_update_operation; /* - * This RR-like structure is particular to UPDATE. + * This structure is used for TSIG authenticated messages */ -struct ns_updrec { - struct ns_updrec *r_prev; /* prev record */ - struct ns_updrec *r_next; /* next record */ - u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */ - char * r_dname; /* owner of the RR */ - u_int16_t r_class; /* class number */ - u_int16_t r_type; /* type number */ - u_int32_t r_ttl; /* time to live */ - u_char * r_data; /* rdata fields as text string */ - u_int16_t r_size; /* size of r_data field */ - int r_opcode; /* type of operation */ - /* following fields for private use by the resolver/server routines */ - struct ns_updrec *r_grpnext; /* next record when grouped */ - struct databuf *r_dp; /* databuf to process */ - struct databuf *r_deldp; /* databuf's deleted/overwritten */ - u_int16_t r_zone; /* zone number on server */ +struct ns_tsig_key { + char name[NS_MAXDNAME], alg[NS_MAXDNAME]; + unsigned char *data; + int len; }; -typedef struct ns_updrec ns_updrec; +typedef struct ns_tsig_key ns_tsig_key; + +/* + * This structure is used for TSIG authenticated TCP messages + */ +struct ns_tcp_tsig_state { + int counter; + struct dst_key *key; + void *ctx; + unsigned char sig[NS_PACKETSZ]; + int siglen; +}; +typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; + +#define NS_TSIG_FUDGE 300 +#define NS_TSIG_TCP_COUNT 100 +#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" + +#define NS_TSIG_ERROR_NO_TSIG -10 +#define NS_TSIG_ERROR_NO_SPACE -11 +#define NS_TSIG_ERROR_FORMERR -12 /* * Currently defined type values for resources and queries. */ typedef enum __ns_type { + ns_t_invalid = 0, /* Cookie. */ ns_t_a = 1, /* Host address. */ ns_t_ns = 2, /* Authoritative server. */ ns_t_md = 3, /* Mail destination. */ @@ -273,22 +286,42 @@ typedef enum __ns_type { ns_t_srv = 33, /* Server Selection. */ ns_t_atma = 34, /* ATM Address */ ns_t_naptr = 35, /* Naming Authority PoinTeR */ - ns_t_opt = 41, /* OPT pseudo-RR, RFC2761 */ - /* Query type values which do not appear in resource records. */ + ns_t_kx = 36, /* Key Exchange */ + ns_t_cert = 37, /* Certification record */ + ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ + ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ + ns_t_sink = 40, /* Kitchen sink (experimentatl) */ + ns_t_opt = 41, /* EDNS0 option (meta-RR) */ + ns_t_apl = 42, /* Address prefix list (RFC 3123) */ + ns_t_tkey = 249, /* Transaction key */ + ns_t_tsig = 250, /* Transaction signature. */ ns_t_ixfr = 251, /* Incremental zone transfer. */ ns_t_axfr = 252, /* Transfer zone of authority. */ ns_t_mailb = 253, /* Transfer mailbox records. */ ns_t_maila = 254, /* Transfer mail agent records. */ ns_t_any = 255, /* Wildcard match. */ + ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ ns_t_max = 65536 } ns_type; +/* Exclusively a QTYPE? (not also an RTYPE) */ +#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ + (t) == ns_t_mailb || (t) == ns_t_maila) +/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */ +#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) +/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */ +#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) +#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) +#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ + (t) == ns_t_zxfr) + /* * Values for class field */ typedef enum __ns_class { + ns_c_invalid = 0, /* Cookie. */ ns_c_in = 1, /* Internet. */ - /* Class 2 unallocated/unsupported. */ + ns_c_2 = 2, /* unallocated/unsupported. */ ns_c_chaos = 3, /* MIT Chaos-net. */ ns_c_hs = 4, /* MIT Hesiod. */ /* Query class values which do not appear in resource records */ @@ -297,9 +330,24 @@ typedef enum __ns_class { ns_c_max = 65536 } ns_class; -/* - * Flags field of the KEY RR rdata - */ +/* DNSSEC constants. */ + +typedef enum __ns_key_types { + ns_kt_rsa = 1, /* key type RSA/MD5 */ + ns_kt_dh = 2, /* Diffie Hellman */ + ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */ + ns_kt_private = 254 /* Private key type starts with OID */ +} ns_key_types; + +typedef enum __ns_cert_types { + cert_t_pkix = 1, /* PKIX (X.509v3) */ + cert_t_spki = 2, /* SPKI */ + cert_t_pgp = 3, /* PGP */ + cert_t_url = 253, /* URL private type */ + cert_t_oid = 254 /* OID private type */ +} ns_cert_types; + +/* Flags field of the KEY RR rdata. */ #define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ #define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ #define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ @@ -308,35 +356,58 @@ typedef enum __ns_class { /* The type bits can also be interpreted independently, as single bits: */ #define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ #define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ -#define NS_KEY_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */ -#define NS_KEY_RESERVED3 0x1000 /* reserved - must be zero */ +#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ +#define NS_KEY_EXTENDED_FLAGS 0x1000 /* reserved - must be zero */ #define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ -#define NS_KEY_USERACCOUNT 0x0400 /* key is assoc. with a user acct */ -#define NS_KEY_ENTITY 0x0200 /* key is assoc. with entity eg host */ -#define NS_KEY_ZONEKEY 0x0100 /* key is zone key */ -#define NS_KEY_IPSEC 0x0080 /* key is for IPSEC (host or user)*/ -#define NS_KEY_EMAIL 0x0040 /* key is for email (MIME security) */ +#define NS_KEY_RESERVED5 0x0400 /* reserved - must be zero */ +#define NS_KEY_NAME_TYPE 0x0300 /* these bits determine the type */ +#define NS_KEY_NAME_USER 0x0000 /* key is assoc. with user */ +#define NS_KEY_NAME_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define NS_KEY_NAME_ZONE 0x0100 /* key is zone key */ +#define NS_KEY_NAME_RESERVED 0x0300 /* reserved meaning */ +#define NS_KEY_RESERVED8 0x0080 /* reserved - must be zero */ +#define NS_KEY_RESERVED9 0x0040 /* reserved - must be zero */ #define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ #define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ #define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ - -#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED3 | \ +#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ NS_KEY_RESERVED4 | \ + NS_KEY_RESERVED5 | \ + NS_KEY_RESERVED8 | \ + NS_KEY_RESERVED9 | \ NS_KEY_RESERVED10 | \ NS_KEY_RESERVED11 ) +#define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */ /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ #define NS_ALG_MD5RSA 1 /* MD5 with RSA */ +#define NS_ALG_DH 2 /* Diffie Hellman KEY */ +#define NS_ALG_DSA 3 /* DSA KEY */ +#define NS_ALG_DSS NS_ALG_DSA #define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ #define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ +/* Protocol values */ +/* value 0 is reserved */ +#define NS_KEY_PROT_TLS 1 +#define NS_KEY_PROT_EMAIL 2 +#define NS_KEY_PROT_DNSSEC 3 +#define NS_KEY_PROT_IPSEC 4 +#define NS_KEY_PROT_ANY 255 + /* Signatures */ #define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ -#define NS_MD5RSA_MAX_BITS 2552 +#define NS_MD5RSA_MAX_BITS 4096 /* Total of binary mod and exp */ #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) /* Max length of text sig block */ #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) +#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) +#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) + +#define NS_DSA_SIG_SIZE 41 +#define NS_DSA_MIN_SIZE 213 +#define NS_DSA_MAX_BYTES 405 /* Offsets into SIG record rdata to find various values */ #define NS_SIG_TYPE 0 /* Type flags */ @@ -353,38 +424,43 @@ typedef enum __ns_class { #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_MAX 127 +/* + * EDNS0 extended flags, host order. + */ +#define NS_OPT_DNSSEC_OK 0x8000U /* * Inline versions of get/put short/long. Pointer is advanced. */ -#define NS_GET16(s, cp) { \ - register u_char *t_cp = (u_char *)(cp); \ +#define NS_GET16(s, cp) do { \ + register const u_char *t_cp = (const u_char *)(cp); \ (s) = ((u_int16_t)t_cp[0] << 8) \ | ((u_int16_t)t_cp[1]) \ ; \ (cp) += NS_INT16SZ; \ -} +} while (0) -#define NS_GET32(l, cp) { \ - register u_char *t_cp = (u_char *)(cp); \ +#define NS_GET32(l, cp) do { \ + register const u_char *t_cp = (const u_char *)(cp); \ (l) = ((u_int32_t)t_cp[0] << 24) \ | ((u_int32_t)t_cp[1] << 16) \ | ((u_int32_t)t_cp[2] << 8) \ | ((u_int32_t)t_cp[3]) \ ; \ (cp) += NS_INT32SZ; \ -} +} while (0) -#define NS_PUT16(s, cp) { \ +#define NS_PUT16(s, cp) do { \ register u_int16_t t_s = (u_int16_t)(s); \ register u_char *t_cp = (u_char *)(cp); \ *t_cp++ = t_s >> 8; \ *t_cp = t_s; \ (cp) += NS_INT16SZ; \ -} +} while (0) -#define NS_PUT32(l, cp) { \ +#define NS_PUT32(l, cp) do { \ register u_int32_t t_l = (u_int32_t)(l); \ register u_char *t_cp = (u_char *)(cp); \ *t_cp++ = t_l >> 24; \ @@ -392,21 +468,27 @@ typedef enum __ns_class { *t_cp++ = t_l >> 8; \ *t_cp = t_l; \ (cp) += NS_INT32SZ; \ -} +} while (0) /* - * ANSI C identifier hiding. + * ANSI C identifier hiding for bind's lib/nameser. */ +#define ns_msg_getflag __ns_msg_getflag #define ns_get16 __ns_get16 #define ns_get32 __ns_get32 #define ns_put16 __ns_put16 #define ns_put32 __ns_put32 #define ns_initparse __ns_initparse +#define ns_skiprr __ns_skiprr #define ns_parserr __ns_parserr #define ns_sprintrr __ns_sprintrr #define ns_sprintrrf __ns_sprintrrf #define ns_format_ttl __ns_format_ttl #define ns_parse_ttl __ns_parse_ttl +#if 0 +#define ns_datetosecs __ns_datetosecs +#endif +#define ns_name_ntol __ns_name_ntol #define ns_name_ntop __ns_name_ntop #define ns_name_pton __ns_name_pton #define ns_name_unpack __ns_name_unpack @@ -414,13 +496,31 @@ typedef enum __ns_class { #define ns_name_compress __ns_name_compress #define ns_name_uncompress __ns_name_uncompress #define ns_name_skip __ns_name_skip +#define ns_name_rollback __ns_name_rollback +#if 0 +#define ns_sign __ns_sign +#define ns_sign2 __ns_sign2 +#define ns_sign_tcp __ns_sign_tcp +#define ns_sign_tcp2 __ns_sign_tcp2 +#define ns_sign_tcp_init __ns_sign_tcp_init +#define ns_find_tsig __ns_find_tsig +#define ns_verify __ns_verify +#define ns_verify_tcp __ns_verify_tcp +#define ns_verify_tcp_init __ns_verify_tcp_init +#define ns_samedomain __ns_samedomain +#define ns_subdomain __ns_subdomain +#endif +#define ns_makecanon __ns_makecanon +#define ns_samename __ns_samename __BEGIN_DECLS +int ns_msg_getflag(ns_msg, int); u_int ns_get16(const u_char *); u_long ns_get32(const u_char *); void ns_put16(u_int, u_char *); void ns_put32(u_long, u_char *); int ns_initparse(const u_char *, int, ns_msg *); +int ns_skiprr(const u_char *, const u_char *, ns_sect, int); int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); int ns_sprintrr(const ns_msg *, const ns_rr *, const char *, const char *, char *, size_t); @@ -430,6 +530,10 @@ int ns_sprintrrf(const u_char *, size_t, const char *, char *, size_t); int ns_format_ttl(u_long, char *, size_t); int ns_parse_ttl(const char *, u_long *); +#if 0 +u_int32_t ns_datetosecs(const char *cp, int *errp); +#endif +int ns_name_ntol(const u_char *, u_char *, size_t); int ns_name_ntop(const u_char *, char *, size_t); int ns_name_pton(const char *, u_char *, size_t); int ns_name_unpack(const u_char *, const u_char *, @@ -441,6 +545,33 @@ int ns_name_uncompress(const u_char *, const u_char *, int ns_name_compress(const char *, u_char *, size_t, const u_char **, const u_char **); int ns_name_skip(const u_char **, const u_char *); +void ns_name_rollback(const u_char *, const u_char **, + const u_char **); +#if 0 +int ns_sign(u_char *, int *, int, int, void *, + const u_char *, int, u_char *, int *, time_t); +int ns_sign2(u_char *, int *, int, int, void *, + const u_char *, int, u_char *, int *, time_t, + u_char **, u_char **); +int ns_sign_tcp(u_char *, int *, int, int, + ns_tcp_tsig_state *, int); +int ns_sign_tcp2(u_char *, int *, int, int, + ns_tcp_tsig_state *, int, + u_char **, u_char **); +int ns_sign_tcp_init(void *, const u_char *, int, + ns_tcp_tsig_state *); +u_char *ns_find_tsig(u_char *, u_char *); +int ns_verify(u_char *, int *, void *, + const u_char *, int, u_char *, int *, + time_t *, int); +int ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int); +int ns_verify_tcp_init(void *, const u_char *, int, + ns_tcp_tsig_state *); +int ns_samedomain(const char *, const char *); +int ns_subdomain(const char *, const char *); +#endif +int ns_makecanon(const char *, char *, size_t); +int ns_samename(const char *, const char *); __END_DECLS #ifdef BIND_4_COMPAT diff --git a/include/arpa/nameser_compat.h b/include/arpa/nameser_compat.h index e4f8ab844de6..0ff966b1ada3 100644 --- a/include/arpa/nameser_compat.h +++ b/include/arpa/nameser_compat.h @@ -32,7 +32,7 @@ /* * from nameser.h 8.1 (Berkeley) 6/2/93 - * From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp + * $Id: nameser_compat.h,v 1.1.2.3.4.2 2004/07/01 04:43:41 marka Exp $ * $FreeBSD$ */ @@ -107,6 +107,7 @@ typedef struct { #define RRFIXEDSZ NS_RRFIXEDSZ #define INT32SZ NS_INT32SZ #define INT16SZ NS_INT16SZ +#define INT8SZ NS_INT8SZ #define INADDRSZ NS_INADDRSZ #define IN6ADDRSZ NS_IN6ADDRSZ #define INDIR_MASK NS_CMPRSFLGS @@ -134,6 +135,10 @@ typedef struct { #define NXRRSET ns_r_nxrrset #define NOTAUTH ns_r_notauth #define NOTZONE ns_r_notzone +/*#define BADSIG ns_r_badsig*/ +/*#define BADKEY ns_r_badkey*/ +/*#define BADTIME ns_r_badtime*/ + #define DELETE ns_uop_delete #define ADD ns_uop_add @@ -173,7 +178,9 @@ typedef struct { #define T_SRV ns_t_srv #define T_ATMA ns_t_atma #define T_NAPTR ns_t_naptr +#define T_A6 ns_t_a6 #define T_OPT ns_t_opt +#define T_TSIG ns_t_tsig #define T_IXFR ns_t_ixfr #define T_AXFR ns_t_axfr #define T_MAILB ns_t_mailb diff --git a/include/netdb.h b/include/netdb.h index 2e7caae369af..9d1b005ee1f7 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -87,7 +87,7 @@ typedef __uint32_t uint32_t; #define _PATH_PROTOCOLS "/etc/protocols" #define _PATH_SERVICES "/etc/services" -#define h_errno (*__h_error()) +#define h_errno (*__h_errno()) /* * Structures returned by network data base library. All addresses are @@ -257,7 +257,7 @@ void setservent(int); */ /* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ -int * __h_error(void); +int * __h_errno(void); __END_DECLS #endif /* !_NETDB_H_ */ diff --git a/include/resolv.h b/include/resolv.h index 1635040cb0e8..d4a70c251e9b 100644 --- a/include/resolv.h +++ b/include/resolv.h @@ -1,7 +1,7 @@ -/*- - * Copyright (c) 1983, 1987, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * +/* + * Copyright (c) 1983, 1987, 1989 + * 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: @@ -12,12 +12,12 @@ * 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. + * 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 @@ -32,25 +32,25 @@ */ /* - * Portions Copyright (c) 1996 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Portions 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 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. + * 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. */ /* * @(#)resolv.h 8.1 (Berkeley) 6/2/93 - * From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $ + * $Id: resolv.h,v 1.7.2.11.4.3 2005/08/25 04:44:13 marka Exp $ * $FreeBSD$ */ @@ -62,6 +62,7 @@ #include #include #include +#include /* * Revision information. This is the release date in YYYYMMDD format. @@ -71,18 +72,60 @@ * is new enough to contain a certain feature. */ -#define __RES 19960801 +#define __RES 20030124 + +/* + * This used to be defined in res_query.c, now it's in herror.c. + * [XXX no it's not. It's in irs/irs_data.c] + * It was + * never extern'd by any *.h file before it was placed here. For thread + * aware programs, the last h_errno value set is stored in res->h_errno. + * + * XXX: There doesn't seem to be a good reason for exposing RES_SET_H_ERRNO + * (and __h_errno_set) to the public via . + * XXX: __h_errno_set is really part of IRS, not part of the resolver. + * If somebody wants to build and use a resolver that doesn't use IRS, + * what do they do? Perhaps something like + * #ifdef WANT_IRS + * # define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x) + * #else + * # define RES_SET_H_ERRNO(r,x) (h_errno = (r)->res_h_errno = (x)) + * #endif + */ + +#define RES_SET_H_ERRNO(r,x) __h_errno_set(r,x) +struct __res_state; /* forward */ +__BEGIN_DECLS +void __h_errno_set(struct __res_state *, int); +__END_DECLS /* * Resolver configuration file. * Normally not present, but may contain the address of the - * inital name server(s) to query and the domain search list. + * initial name server(s) to query and the domain search list. */ #ifndef _PATH_RESCONF #define _PATH_RESCONF "/etc/resolv.conf" #endif +typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } + res_sendhookact; + +typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *, + const u_char **, int *, + u_char *, int, int *); + +typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *, + const u_char *, int, u_char *, + int, int *); + +struct res_sym { + int number; /* Identifying number, like T_MX */ + const char * name; /* Its symbolic name, like "MX" */ + const char * humanname; /* Its fun name, like "mail exchanger" */ +}; + /* * Global defines and variables for resolver stub. */ @@ -92,16 +135,29 @@ #define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ #define RES_TIMEOUT 5 /* min. seconds between retries */ -#define RES_DFLRETRY 2 /* retries per each name server */ #define MAXRESOLVSORT 10 /* number of net to sort on */ #define RES_MAXNDOTS 15 /* should reflect bit field size */ #define RES_MAXRETRANS 30 /* only for resolv.conf/RES_OPTIONS */ #define RES_MAXRETRY 5 /* only for resolv.conf/RES_OPTIONS */ +#define RES_DFLRETRY 2 /* Default #/tries. */ +#define RES_MAXTIME 65535 /* Infinity, in milliseconds. */ + +struct __res_state_ext; struct __res_state { - int retrans; /* retransmition time interval */ + int retrans; /* retransmission time interval */ int retry; /* number of times to retransmit */ + /* + * XXX: If `sun' is defined, `options' and `pfcode' are + * defined as u_int in original BIND9 distribution. However, + * it breaks binary backward compatibility against FreeBSD's + * resolver. So, we changed not to see `sun'. + */ +#if defined(sun) && 0 + u_int options; /* option flags - see below. */ +#else u_long options; /* option flags - see below. */ +#endif int nscount; /* number of name servers */ struct sockaddr_in nsaddr_list[MAXNS]; /* address of name server */ @@ -109,7 +165,11 @@ struct __res_state { u_short id; /* current message id */ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ char defdname[256]; /* default domain (deprecated) */ +#if defined(sun) && 0 + u_int pfcode; /* RES_PRF_ flags - see below. */ +#else u_long pfcode; /* RES_PRF_ flags - see below. */ +#endif unsigned ndots:4; /* threshold for initial abs. query */ unsigned nsort:4; /* number of elements in sort_list[] */ char unused[3]; @@ -117,24 +177,55 @@ struct __res_state { struct in_addr addr; u_int32_t mask; } sort_list[MAXRESOLVSORT]; - char pad[72]; /* on an i386 this means 512b total */ + res_send_qhook qhook; /* query hook */ + res_send_rhook rhook; /* response hook */ + int res_h_errno; /* last one set for this context */ + int _vcsock; /* PRIVATE: for res_send VC i/o */ + u_int _flags; /* PRIVATE: see below */ + u_int _pad; /* make _u 64 bit aligned */ + union { + /* On an 32-bit arch this means 512b total. */ + char pad[72 - 4*sizeof (int) - 2*sizeof (void *)]; + struct { + u_int16_t nscount; + u_int16_t nstimes[MAXNS]; /* ms. */ + int nssocks[MAXNS]; + struct __res_state_ext *ext; /* extention for IPv6 */ + } _ext; + } _u; }; -/* for INET6 */ -/* - * replacement of __res_state, separated to keep binary compatibility. - */ -struct __res_state_ext { - struct sockaddr_storage nsaddr_list[MAXNS]; - struct { - int af; /* address family for addr, mask */ - union { - struct in_addr ina; - struct in6_addr in6a; - } addr, mask; - } sort_list[MAXRESOLVSORT]; +typedef struct __res_state *res_state; + +union res_sockaddr_union { + struct sockaddr_in sin; +#ifdef IN6ADDR_ANY_INIT + struct sockaddr_in6 sin6; +#endif +#ifdef ISC_ALIGN64 + int64_t __align64; /* 64bit alignment */ +#else + int32_t __align32; /* 32bit alignment */ +#endif + char __space[128]; /* max size */ }; +/* + * Resolver flags (used to be discrete per-module statics ints). + */ +#define RES_F_VC 0x00000001 /* socket is TCP */ +#define RES_F_CONN 0x00000002 /* socket is connected */ +#define RES_F_EDNS0ERR 0x00000004 /* EDNS0 caused errors */ +#define RES_F__UNUSED 0x00000008 /* (unused) */ +#define RES_F_LASTMASK 0x000000F0 /* ordinal server of last res_nsend */ +#define RES_F_LASTSHIFT 4 /* bit position of LASTMASK "flag" */ +#define RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT) + +/* res_findzonecut2() options */ +#define RES_EXHAUSTIVE 0x00000001 /* always do all queries */ +#define RES_IPV4ONLY 0x00000002 /* IPv4 only */ +#define RES_IPV6ONLY 0x00000004 /* IPv6 only */ + /* * Resolver options (keep these in synch with res_debug.c, please) */ @@ -152,11 +243,20 @@ struct __res_state_ext { #define RES_INSECURE2 0x00000800 /* type 2 security disabled */ #define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */ #define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */ -#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */ +#define RES_ROTATE 0x00004000 /* rotate ns list after each query */ +#define RES_NOCHECKNAME 0x00008000 /* do not check names for sanity. */ +#define RES_KEEPTSIG 0x00010000 /* do not strip TSIG records */ +#define RES_BLAST 0x00020000 /* blast all recursive servers */ +#define RES_NOTLDQUERY 0x00100000 /* don't unqualified name as a tld */ +#define RES_USE_DNSSEC 0x00200000 /* use DNSSEC using OK bit in OPT */ +/* #define RES_DEBUG2 0x00400000 */ /* nslookup internal */ /* KAME extensions: use higher bit to avoid conflict with ISC use */ -#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */ +#define RES_USE_DNAME 0x10000000 /* use DNAME */ +#define RES_USE_EDNS0 0x40000000 /* use EDNS0 if configured */ +#define RES_NO_NIBBLE2 0x80000000 /* disable alternate nibble lookup */ -#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \ + RES_DNSRCH | RES_NO_NIBBLE2) /* * Resolver "pfcode" values. Used by dig. @@ -175,94 +275,138 @@ struct __res_state_ext { #define RES_PRF_HEADX 0x00000800 #define RES_PRF_QUERY 0x00001000 #define RES_PRF_REPLY 0x00002000 -#define RES_PRF_INIT 0x00004000 -/* 0x00008000 */ +#define RES_PRF_INIT 0x00004000 +#define RES_PRF_TRUNC 0x00008000 +/* 0x00010000 */ -typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } - res_sendhookact; +/* Things involving an internal (static) resolver context. */ +__BEGIN_DECLS +extern struct __res_state *__res_state(void); +__END_DECLS +#define _res (*__res_state()) -typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *ns, - const u_char **query, - int *querylen, - u_char *ans, - int anssiz, - int *resplen); - -typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *ns, - const u_char *query, - int querylen, - u_char *ans, - int anssiz, - int *resplen); - -struct res_sym { - int number; /* Identifying number, like T_MX */ - char * name; /* Its symbolic name, like "MX" */ - char * humanname; /* Its fun name, like "mail exchanger" */ -}; +#ifndef __BIND_NOSTATIC +#define fp_nquery __fp_nquery +#define fp_query __fp_query +#define hostalias __hostalias +#define p_query __p_query +#define res_close __res_close +#define res_init __res_init +#define res_isourserver __res_isourserver +#define res_mkquery __res_mkquery +#define res_opt __res_opt +#define res_query __res_query +#define res_querydomain __res_querydomain +#define res_search __res_search +#define res_send __res_send +#define res_sendsigned __res_sendsigned __BEGIN_DECLS -extern struct __res_state *___res(void); -extern struct __res_state_ext *___res_ext(void); +void fp_nquery(const u_char *, int, FILE *); +void fp_query(const u_char *, FILE *); +const char * hostalias(const char *); +void p_query(const u_char *); +void res_close(void); +int res_init(void); +int res_isourserver(const struct sockaddr_in *); +int res_mkquery(int, const char *, int, int, const u_char *, + int, const u_char *, u_char *, int); +int res_opt(int, u_char *, int, int); +int res_query(const char *, int, int, u_char *, int); +int res_querydomain(const char *, const char *, int, int, + u_char *, int); +int res_search(const char *, int, int, u_char *, int); +int res_send(const u_char *, int, u_char *, int); +int res_sendsigned(const u_char *, int, ns_tsig_key *, + u_char *, int); __END_DECLS -#define _res (*___res()) -/* for INET6 */ -#define _res_ext (*___res_ext()) +#endif +#if !defined(SHARED_LIBBIND) || defined(LIB) +/* + * If libbind is a shared object (well, DLL anyway) + * these externs break the linker when resolv.h is + * included by a lib client (like named) + * Make them go away if a client is including this + * + */ +extern const struct res_sym __p_key_syms[]; +extern const struct res_sym __p_cert_syms[]; extern const struct res_sym __p_class_syms[]; extern const struct res_sym __p_type_syms[]; +extern const struct res_sym __p_rcode_syms[]; +#endif /* SHARED_LIBBIND */ -/* Private routines shared between libc/net, named, nslookup and others. */ -#define res_hnok __res_hnok -#define res_ownok __res_ownok -#define res_mailok __res_mailok -#define res_dnok __res_dnok -#define sym_ston __sym_ston -#define sym_ntos __sym_ntos -#define sym_ntop __sym_ntop -#define b64_ntop __b64_ntop -#define b64_pton __b64_pton -#define loc_ntoa __loc_ntoa -#define loc_aton __loc_aton -#define fp_resstat __fp_resstat -#define p_query __p_query -#define dn_skipname __dn_skipname -#define fp_resstat __fp_resstat -#define fp_query __fp_query -#define fp_nquery __fp_nquery -#define hostalias __hostalias -#define putlong __putlong -#define putshort __putshort -#define p_class __p_class -#define p_time __p_time -#define p_type __p_type -#define p_query __p_query -#define p_cdnname __p_cdnname -#define p_section __p_section -#define p_cdname __p_cdname -#define p_fqnname __p_fqnname -#define p_fqname __p_fqname -#define p_option __p_option -#define p_secstodate __p_secstodate -#define dn_count_labels __dn_count_labels -#define dn_comp __dn_comp -#define dn_expand __dn_expand -#define res_init __res_init -#define res_randomid __res_randomid -#define res_query __res_query -#define res_search __res_search -#define res_querydomain __res_querydomain -#define res_mkquery __res_mkquery -#define res_send __res_send -#define res_isourserver __res_isourserver -#define res_nameinquery __res_nameinquery -#define res_queriesmatch __res_queriesmatch -#define res_close __res_close -#define res_opt __res_opt -#define res_mkupdate __res_mkupdate -#define res_mkupdrec __res_mkupdrec -#define res_freeupdrec __res_freeupdrec - +#define b64_ntop __b64_ntop +#define b64_pton __b64_pton +#define dn_comp __dn_comp +#define dn_count_labels __dn_count_labels +#define dn_expand __dn_expand +#define dn_skipname __dn_skipname +#define fp_resstat __fp_resstat +#define loc_aton __loc_aton +#define loc_ntoa __loc_ntoa +#define p_cdname __p_cdname +#define p_cdnname __p_cdnname +#define p_class __p_class +#define p_fqname __p_fqname +#define p_fqnname __p_fqnname +#define p_option __p_option +#define p_secstodate __p_secstodate +#define p_section __p_section +#define p_time __p_time +#define p_type __p_type +#define p_rcode __p_rcode +#define p_sockun __p_sockun +#define putlong __putlong +#define putshort __putshort +#define res_dnok __res_dnok +#if 0 +#define res_findzonecut __res_findzonecut +#define res_findzonecut2 __res_findzonecut2 +#endif +#define res_hnok __res_hnok +#define res_hostalias __res_hostalias +#define res_mailok __res_mailok +#define res_nameinquery __res_nameinquery +#define res_nclose __res_nclose +#define res_ninit __res_ninit +#define res_nmkquery __res_nmkquery +#define res_pquery __res_pquery +#define res_nquery __res_nquery +#define res_nquerydomain __res_nquerydomain +#define res_nsearch __res_nsearch +#define res_nsend __res_nsend +#if 0 +#define res_nsendsigned __res_nsendsigned +#endif +#define res_nisourserver __res_nisourserver +#define res_ownok __res_ownok +#define res_queriesmatch __res_queriesmatch +#define res_randomid __res_randomid +#define sym_ntop __sym_ntop +#define sym_ntos __sym_ntos +#define sym_ston __sym_ston +#define res_nopt __res_nopt +#define res_ndestroy __res_ndestroy +#define res_nametoclass __res_nametoclass +#define res_nametotype __res_nametotype +#define res_setservers __res_setservers +#define res_getservers __res_getservers +#define res_buildprotolist __res_buildprotolist +#define res_destroyprotolist __res_destroyprotolist +#define res_destroyservicelist __res_destroyservicelist +#if 0 +#define res_get_nibblesuffix __res_get_nibblesuffix +#define res_get_nibblesuffix2 __res_get_nibblesuffix2 +#endif +#define res_ourserver_p __res_ourserver_p +#define res_protocolname __res_protocolname +#define res_protocolnumber __res_protocolnumber +#define res_send_setqhook __res_send_setqhook +#define res_send_setrhook __res_send_setrhook +#define res_servicename __res_servicename +#define res_servicenumber __res_servicenumber __BEGIN_DECLS int res_hnok(const char *); int res_ownok(const char *); @@ -276,20 +420,20 @@ int b64_pton(char const *, u_char *, size_t); int loc_aton(const char *, u_char *); const char * loc_ntoa(const u_char *, char *); int dn_skipname(const u_char *, const u_char *); -void fp_resstat(struct __res_state *, FILE *); -void fp_query(const u_char *, FILE *); -void fp_nquery(const u_char *, int, FILE *); -const char * hostalias(const char *); void putlong(u_int32_t, u_char *); void putshort(u_int16_t, u_char *); +#ifndef __ultrix__ +u_int16_t _getshort(const u_char *); +u_int32_t _getlong(const u_char *); +#endif const char * p_class(int); const char * p_time(u_int32_t); const char * p_type(int); -void p_query(const u_char *); +const char * p_rcode(int); +const char * p_sockun(union res_sockaddr_union, char *, size_t); const u_char * p_cdnname(const u_char *, const u_char *, int, FILE *); const u_char * p_cdname(const u_char *, const u_char *, FILE *); -const u_char * p_fqnname(const u_char *, const u_char *, - int, char *, int); +const u_char * p_fqnname(const u_char *, const u_char *, int, char *, int); const u_char * p_fqname(const u_char *, const u_char *, FILE *); const char * p_option(u_long); char * p_secstodate(u_long); @@ -297,35 +441,55 @@ int dn_count_labels(const char *); int dn_comp(const char *, u_char *, int, u_char **, u_char **); int dn_expand(const u_char *, const u_char *, const u_char *, char *, int); -int res_init(void); u_int res_randomid(void); -int res_query(const char *, int, int, u_char *, int); -int res_search(const char *, int, int, u_char *, int); -int res_querydomain(const char *, const char *, int, int, - u_char *, int); -int res_mkquery(int, const char *, int, int, const u_char *, - int, const u_char *, u_char *, int); -int res_send(const u_char *, int, u_char *, int); -int res_isourserver(const struct sockaddr_in *); -int res_nameinquery(const char *, int, int, - const u_char *, const u_char *); +int res_nameinquery(const char *, int, int, const u_char *, + const u_char *); int res_queriesmatch(const u_char *, const u_char *, const u_char *, const u_char *); -void res_close(void); -int res_opt(int, u_char *, int, int); const char * p_section(int, int); -/* XXX These must be exported for BIND4 compatibility. */ -void __putlong(u_int32_t, u_char *); -void __putshort(u_int16_t, u_char *); -u_int32_t _getlong(const u_char *); -u_int16_t _getshort(const u_char *); -/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */ -#ifdef _ARPA_NAMESER_H_ -int res_update(ns_updrec *); -int res_mkupdate(ns_updrec *, u_char *, int); -ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long); -void res_freeupdrec(ns_updrec *); +/* Things involving a resolver context. */ +int res_ninit(res_state); +int res_nisourserver(const res_state, const struct sockaddr_in *); +void fp_resstat(const res_state, FILE *); +void res_pquery(const res_state, const u_char *, int, FILE *); +const char * res_hostalias(const res_state, const char *, char *, size_t); +int res_nquery(res_state, const char *, int, int, u_char *, int); +int res_nsearch(res_state, const char *, int, int, u_char *, int); +int res_nquerydomain(res_state, const char *, const char *, + int, int, u_char *, int); +int res_nmkquery(res_state, int, const char *, int, int, + const u_char *, int, const u_char *, + u_char *, int); +int res_nsend(res_state, const u_char *, int, u_char *, int); +#if 0 +int res_nsendsigned(res_state, const u_char *, int, + ns_tsig_key *, u_char *, int); +int res_findzonecut(res_state, const char *, ns_class, int, + char *, size_t, struct in_addr *, int); +int res_findzonecut2(res_state, const char *, ns_class, int, + char *, size_t, + union res_sockaddr_union *, int); #endif +void res_nclose(res_state); +int res_nopt(res_state, int, u_char *, int, int); +void res_send_setqhook(res_send_qhook); +void res_send_setrhook(res_send_rhook); +int __res_vinit(res_state, int); +void res_destroyservicelist(void); +const char * res_servicename(u_int16_t, const char *); +const char * res_protocolname(int); +void res_destroyprotolist(void); +void res_buildprotolist(void); +#if 0 +const char * res_get_nibblesuffix(res_state); +const char * res_get_nibblesuffix2(res_state); +#endif +void res_ndestroy(res_state); +u_int16_t res_nametoclass(const char *, int *); +u_int16_t res_nametotype(const char *, int *); +void res_setservers(res_state, const union res_sockaddr_union *, + int); +int res_getservers(res_state, union res_sockaddr_union *, int); __END_DECLS #endif /* !_RESOLV_H_ */ diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 247e60216ea4..f3a7c03dde1c 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -36,7 +36,10 @@ NOASM= .include "${.CURDIR}/gdtoa/Makefile.inc" .include "${.CURDIR}/gen/Makefile.inc" .include "${.CURDIR}/gmon/Makefile.inc" +.include "${.CURDIR}/inet/Makefile.inc" +.include "${.CURDIR}/isc/Makefile.inc" .include "${.CURDIR}/locale/Makefile.inc" +.include "${.CURDIR}/nameser/Makefile.inc" .include "${.CURDIR}/net/Makefile.inc" .include "${.CURDIR}/nls/Makefile.inc" .include "${.CURDIR}/posix1e/Makefile.inc" @@ -47,6 +50,7 @@ NOASM= .include "${.CURDIR}/quad/Makefile.inc" .endif .include "${.CURDIR}/regex/Makefile.inc" +.include "${.CURDIR}/resolv/Makefile.inc" .include "${.CURDIR}/stdio/Makefile.inc" .include "${.CURDIR}/stdlib/Makefile.inc" .include "${.CURDIR}/stdtime/Makefile.inc" diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 8a8a3816e0e6..3c363cd1400f 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -10,21 +10,22 @@ SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c \ getifaddrs.c getifmaddrs.c getnameinfo.c \ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ getproto.c getprotoent.c getprotoname.c getservbyname.c \ - getservbyport.c getservent.c herror.c inet_addr.c \ - if_indextoname.c if_nameindex.c if_nametoindex.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 ip6opt.c linkaddr.c map_v4v6.c name6.c \ - ns_name.c ns_netint.c ns_parse.c ns_print.c ns_ttl.c \ + getservbyport.c getservent.c \ + if_indextoname.c if_nameindex.c if_nametoindex.c \ + ip6opt.c linkaddr.c map_v4v6.c name6.c \ nsdispatch.c nslexer.c nsparser.c nss_compat.c \ - nsap_addr.c rcmd.c rcmdsh.c recv.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_update.c rthdr.c send.c sockatmark.c vars.c + rcmd.c rcmdsh.c recv.c rthdr.c send.c sockatmark.c vars.c + +# for binary backward compatibility against FreeBSD 6.X and earlier +SRCS+= res_mkupdate.c res_update.c SYM_MAPS+=${.CURDIR}/net/Symbol.map CFLAGS+=-DINET6 -I${.OBJDIR} +# name6.c refers res_private.h +CFLAGS+=-I${.CURDIR}/resolv + YFLAGS+=-p_nsyy LFLAGS+=-P_nsyy diff --git a/lib/libc/net/Symbol.map b/lib/libc/net/Symbol.map index 36d3b4e4103f..1568907e6669 100644 --- a/lib/libc/net/Symbol.map +++ b/lib/libc/net/Symbol.map @@ -44,10 +44,6 @@ FBSD_1.0 { setservent; endservent; getservent; - #h_nerr; # Why is this not staticized in net/herror.c? - h_errlist; - herror; - hstrerror; hesiod_init; hesiod_end; hesiod_to_bind; @@ -62,30 +58,6 @@ FBSD_1.0 { if_nameindex; if_freenameindex; if_nametoindex; - __inet_addr; - __inet_aton; - inet_addr; - inet_aton; - __inet_lnaof; - inet_lnaof; - __inet_makeaddr; - inet_makeaddr; - __inet_net_ntop; - inet_net_ntop; - __inet_net_pton; - inet_net_pton; - __inet_neta; - inet_neta; - __inet_netof; - inet_netof; - __inet_network; - inet_network; - __inet_ntoa; - inet_ntoa; - __inet_ntop; - inet_ntop; - __inet_pton; - inet_pton; inet6_option_space; inet6_option_init; inet6_option_append; @@ -104,28 +76,6 @@ FBSD_1.0 { getipnodebyname; getipnodebyaddr; freehostent; - __ns_name_ntop; - __ns_name_pton; - __ns_name_unpack; - __ns_name_pack; - __ns_name_uncompress; - __ns_name_compress; - __ns_name_skip; - __ns_get16; - __ns_get32; - __ns_put16; - __ns_put32; - __ns_initparse; - __ns_parserr; - _ns_flagdata; - __ns_sprintrr; - __ns_sprintrrf; - __ns_format_ttl; - __ns_parse_ttl; - __inet_nsap_addr; - __inet_nsap_ntoa; - inet_nsap_addr; - inet_nsap_ntoa; __nsdefaultsrc; _nsdbtaddsrc; _nsdbtdump; @@ -140,77 +90,10 @@ FBSD_1.0 { iruserok_sa; rcmdsh; recv; - __dn_expand; - __dn_comp; - __dn_skipname; - __res_hnok; - __res_ownok; - __res_mailok; - __res_dnok; - __putlong; - __putshort; - _getlong; - _getshort; - dn_comp; - dn_expand; - __fp_resstat; - __p_query; - __fp_query; - __fp_nquery; - __p_cdnname; - __p_cdname; - __p_fqnname; - __p_fqname; - __p_class_syms; - __p_type_syms; - __sym_ston; - __sym_ntos; - __sym_ntop; - __p_type; - __p_section; - __p_class; - __p_option; - __p_time; - __loc_aton; - __loc_ntoa; - __dn_count_labels; - __p_secstodate; - fp_resstat; - p_query; - p_fqnname; - sym_ston; - sym_ntos; - sym_ntop; - dn_count_labels; - p_secstodate; - __res_init; - __res_randomid; - ___res; - ___res_ext; - __h_error; - h_errno; - res_init; - __res_mkquery; - res_mkquery; - __res_opt; - __res_mkupdate; - __res_mkupdrec; - __res_freeupdrec; - __res_query; - __res_search; - __res_querydomain; - __hostalias; - res_query; - res_search; - res_querydomain; - __res_isourserver; - __res_nameinquery; - __res_queriesmatch; - __res_send; - __res_close; - _res_close; - res_send; - res_update; # Why is this not __res_update? + #__res_mkupdate; # Obsoleted + #__res_mkupdrec; # Obsoleted + #__res_freeupdrec; # Obsoleted + #res_update; # Obsoleted Why is this not __res_update? inet6_rthdr_space; inet6_rthdr_init; inet6_rthdr_add; diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 9d7eb45d4c0c..148a95e68b7d 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -265,9 +265,9 @@ static struct policyqueue *match_addrselectpolicy(struct sockaddr *, 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 **); @@ -280,10 +280,10 @@ static struct addrinfo *_yphostent(char *, const struct addrinfo *); static int _yp_getaddrinfo(void *, void *, va_list); #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. */ @@ -1628,12 +1628,13 @@ static const char AskedForGot[] = #endif static struct addrinfo * -getanswer(answer, anslen, qname, qtype, pai) +getanswer(answer, anslen, qname, qtype, pai, res) 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 +1675,12 @@ getanswer(answer, anslen, qname, qtype, pai) 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 +1691,7 @@ getanswer(answer, anslen, qname, qtype, pai) */ 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 +1818,10 @@ getanswer(answer, anslen, qname, qtype, pai) * 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 +1830,11 @@ getanswer(answer, anslen, qname, qtype, pai) (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 +1845,7 @@ struct addr_ptr { }; static int -addr4sort(struct addrinfo *sentinel) +addr4sort(struct addrinfo *sentinel, res_state res) { struct addrinfo *ai; struct addr_ptr *addrs, addr; @@ -1864,9 +1865,9 @@ addr4sort(struct addrinfo *sentinel) 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; @@ -1916,6 +1917,7 @@ _dns_getaddrinfo(rv, cb_data, ap) 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 *); @@ -1927,13 +1929,13 @@ _dns_getaddrinfo(rv, cb_data, ap) 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 +1972,36 @@ _dns_getaddrinfo(rv, cb_data, ap) 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: @@ -2261,7 +2272,7 @@ _yp_getaddrinfo(rv, cb_data, ap) } 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 +2282,6 @@ _yp_getaddrinfo(rv, cb_data, ap) /* 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,9 +2293,10 @@ extern const char *_res_hostalias(const char *, char *, size_t); * Caller must parse answer and determine whether it answers the question. */ static int -res_queryN(name, target) +res_queryN(name, target, res) const char *name; /* domain name */ struct res_target *target; + res_state res; { u_char *buf; HEADER *hp; @@ -2300,7 +2310,7 @@ res_queryN(name, target) buf = malloc(MAXPACKET); if (!buf) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(res, NETDB_INTERNAL); return -1; } @@ -2318,32 +2328,32 @@ res_queryN(name, target) answer = t->answer; anslen = t->anslen; #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->options & RES_USE_EDNS0) != 0) + 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); + n = res_nsend(res, buf, n, answer, anslen); #if 0 if (n < 0) { #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; + RES_SET_H_ERRNO(res, TRY_AGAIN); return (n); } #endif @@ -2353,7 +2363,7 @@ res_queryN(name, target) 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 +2380,19 @@ res_queryN(name, target) 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 +2407,10 @@ res_queryN(name, target) * is detected. Error code, if any, is left in h_errno. */ static int -res_searchN(name, target) +res_searchN(name, target, res) const char *name; /* domain name */ struct res_target *target; + res_state res; { const char *cp, * const *domain; HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ @@ -2410,13 +2421,8 @@ res_searchN(name, target) 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 +2433,9 @@ res_searchN(name, target) /* * 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,22 +2443,22 @@ res_searchN(name, target) * 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; default: return (-1); } - saved_herrno = h_errno; + saved_herrno = res->res_h_errno; tried_as_is++; } @@ -2461,11 +2468,11 @@ res_searchN(name, target) * - 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; @@ -2477,7 +2484,7 @@ res_searchN(name, target) 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); @@ -2495,11 +2502,11 @@ res_searchN(name, target) * 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 */ @@ -2521,12 +2528,12 @@ res_searchN(name, target) * 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; @@ -2538,9 +2545,9 @@ res_searchN(name, target) * 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); } @@ -2555,11 +2562,11 @@ res_searchN(name, target) */ 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); } @@ -2568,16 +2575,17 @@ res_searchN(name, target) * removing a trailing dot from name if domain is NULL. */ static int -res_querydomainN(name, domain, target) +res_querydomainN(name, domain, target, res) const char *name, *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:""); #endif @@ -2588,7 +2596,7 @@ res_querydomainN(name, domain, target) */ n = strlen(name); if (n >= MAXDNAME) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(res, NO_RECOVERY); return (-1); } if (n > 0 && name[--n] == '.') { @@ -2600,10 +2608,10 @@ res_querydomainN(name, domain, target) 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)); } diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c index 6cb43f046c60..b4c80d456e1d 100644 --- a/lib/libc/net/gethostbydns.c +++ b/lib/libc/net/gethostbydns.c @@ -88,11 +88,11 @@ static const char AskedForGot[] = "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; #ifdef RESOLVSORT -static void addrsort(char **, int); +static void addrsort(char **, int, res_state); #endif #ifdef DEBUG -static void dprintf(char *, int) __printflike(1, 0); +static void dprintf(char *, int, res_state) __printflike(1, 0); #endif #define MAXPACKET (64*1024) @@ -111,11 +111,12 @@ int _dns_ttl_; #ifdef DEBUG static void -dprintf(msg, num) +dprintf(msg, num, res) char *msg; int num; + res_state res; { - if (_res.options & RES_DEBUG) { + if (res->options & RES_DEBUG) { int save = errno; printf(msg, num); @@ -123,14 +124,14 @@ dprintf(msg, num) } } #else -# define dprintf(msg, num) /*nada*/ +# define dprintf(msg, num, res) /*nada*/ #endif #define BOUNDED_INCR(x) \ do { \ cp += x; \ if (cp > eom) { \ - h_errno = NO_RECOVERY; \ + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); \ return -1; \ } \ } while (0) @@ -138,7 +139,7 @@ dprintf(msg, num) #define BOUNDS_CHECK(ptr, count) \ do { \ if ((ptr) + (count) > eom) { \ - h_errno = NO_RECOVERY; \ + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); \ return -1; \ } \ } while (0) @@ -171,7 +172,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, name_ok = res_dnok; break; default: - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; /* XXX should be abort(); */ } /* @@ -185,12 +186,12 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, cp = answer->buf; BOUNDED_INCR(HFIXEDSZ); if (qdcount != 1) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } n = dn_expand(answer->buf, eom, cp, bp, ep - bp); if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } BOUNDED_INCR(n + QFIXEDSZ); @@ -201,7 +202,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, */ n = strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } he->h_name = bp; @@ -252,7 +253,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, } cp += n; if (cp != erdata) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } /* Store alias. */ @@ -282,7 +283,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, } cp += n; if (cp != erdata) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } /* Get canonical name. */ @@ -321,7 +322,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, #if MULTI_PTRS_ARE_ALIASES cp += n; if (cp != erdata) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } if (!haveanswer) @@ -341,7 +342,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, break; #else he->h_name = bp; - if (_res.options & RES_USE_INET6) { + if (hed->res->options & RES_USE_INET6) { n = strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { had_error++; @@ -350,7 +351,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, bp += n; _map_v4v6_hostent(he, &bp, ep); } - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return 0; #endif case T_A: @@ -376,14 +377,14 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, bp += sizeof(align) - ((u_long)bp % sizeof(align)); if (bp + n >= ep) { - dprintf("size (%d) too big\n", n); + dprintf("size (%d) too big\n", n, hed->res); had_error++; continue; } if (hap >= &hed->h_addr_ptrs[_MAXADDRS-1]) { if (!toobig++) dprintf("Too many addresses (%d)\n", - _MAXADDRS); + _MAXADDRS, hed->res); cp += n; continue; } @@ -391,13 +392,14 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, bp += n; cp += n; if (cp != erdata) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } break; default: - dprintf("Impossible condition (type=%d)\n", type); - h_errno = NO_RECOVERY; + dprintf("Impossible condition (type=%d)\n", type, + hed->res); + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; /* BIND has abort() here, too risky on bad data */ } @@ -413,8 +415,8 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, * in its return structures - should give it the "best" * address in that case, not some random one */ - if (_res.nsort && haveanswer > 1 && qtype == T_A) - addrsort(hed->h_addr_ptrs, haveanswer); + if (hed->res->nsort && haveanswer > 1 && qtype == T_A) + addrsort(hed->h_addr_ptrs, haveanswer, hed->res); # endif /*RESOLVSORT*/ if (!he->h_name) { n = strlen(qname) + 1; /* for the \0 */ @@ -424,13 +426,13 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, he->h_name = bp; bp += n; } - if (_res.options & RES_USE_INET6) + if (hed->res->options & RES_USE_INET6) _map_v4v6_hostent(he, &bp, ep); - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return 0; } no_recovery: - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } @@ -440,11 +442,14 @@ __dns_getanswer(const char *answer, int anslen, const char *qname, int qtype) { struct hostdata *hd; int error; + res_state statp; + statp = __res_state(); if ((hd = __hostdata_init()) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NULL; } + hd->data.res = statp; switch (qtype) { case T_AAAA: hd->host.h_addrtype = AF_INET6; @@ -487,7 +492,7 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) type = T_AAAA; break; default: - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); errno = EAFNOSUPPORT; return NS_UNAVAIL; } @@ -496,17 +501,17 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) he->h_length = size; if ((buf = malloc(sizeof(*buf))) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return NS_NOTFOUND; } - n = res_search(name, C_IN, type, buf->buf, sizeof(buf->buf)); + n = res_nsearch(hed->res, name, C_IN, type, buf->buf, sizeof(buf->buf)); if (n < 0) { free(buf); - dprintf("res_search failed (%d)\n", n); + dprintf("res_nsearch failed (%d)\n", n, hed->res); return (0); } else if (n > sizeof(buf->buf)) { free(buf); - dprintf("static buffer is too small (%d)\n", n); + dprintf("static buffer is too small (%d)\n", n, hed->res); return (0); } error = gethostanswer(buf, n, name, type, he, hed); @@ -538,10 +543,6 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) he = va_arg(ap, struct hostent *); hed = va_arg(ap, struct hostent_data *); - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return NS_UNAVAIL; - } switch (af) { case AF_INET: (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", @@ -563,18 +564,19 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) abort(); } if ((buf = malloc(sizeof(*buf))) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return NS_NOTFOUND; } - n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf->buf, sizeof buf->buf); + n = res_nquery(hed->res, qbuf, C_IN, T_PTR, (u_char *)buf->buf, + sizeof buf->buf); if (n < 0) { free(buf); - dprintf("res_query failed (%d)\n", n); + dprintf("res_nquery failed (%d)\n", n, hed->res); return NS_UNAVAIL; } if (n > sizeof buf->buf) { free(buf); - dprintf("static buffer is too small (%d)\n", n); + dprintf("static buffer is too small (%d)\n", n, hed->res); return NS_UNAVAIL; } if ((error = gethostanswer(buf, n, qbuf, T_PTR, he, hed)) != 0) { @@ -590,9 +592,9 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) */ strncpy(hname2, he->h_name, MAXDNAME); hname2[MAXDNAME] = '\0'; - old_options = _res.options; - _res.options &= ~RES_DNSRCH; - _res.options |= RES_DEFNAMES; + old_options = hed->res->options; + hed->res->options &= ~RES_DNSRCH; + hed->res->options |= RES_DEFNAMES; memset(&rhd, 0, sizeof rhd); if (!(rhe = gethostbyname_r(hname2, &rhd.host, &rhd.data))) { if (inet_ntop(af, addr, numaddr, sizeof(numaddr)) == NULL) @@ -600,11 +602,11 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) syslog(LOG_NOTICE|LOG_AUTH, "gethostbyaddr: No A record for %s (verifying [%s])", hname2, numaddr); - _res.options = old_options; - h_errno = HOST_NOT_FOUND; + hed->res->options = old_options; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return NS_NOTFOUND; } - _res.options = old_options; + hed->res->options = old_options; for (haddr = rhe->h_addr_list; *haddr; haddr++) if (!memcmp(*haddr, addr, INADDRSZ)) break; @@ -614,7 +616,7 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) syslog(LOG_NOTICE|LOG_AUTH, "gethostbyaddr: A record of %s != PTR record [%s]", hname2, numaddr); - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return NS_NOTFOUND; } } @@ -624,20 +626,21 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) memcpy(hed->host_addr, uaddr, len); hed->h_addr_ptrs[0] = (char *)hed->host_addr; hed->h_addr_ptrs[1] = NULL; - if (af == AF_INET && (_res.options & RES_USE_INET6)) { + if (af == AF_INET && (hed->res->options & RES_USE_INET6)) { _map_v4v6_address((char*)hed->host_addr, (char*)hed->host_addr); he->h_addrtype = AF_INET6; he->h_length = IN6ADDRSZ; } - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return (error == 0) ? NS_SUCCESS : NS_NOTFOUND; } #ifdef RESOLVSORT static void -addrsort(ap, num) +addrsort(ap, num, res) char **ap; int num; + res_state res; { int i, j; char **p; @@ -646,9 +649,9 @@ addrsort(ap, num) p = ap; for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _res.nsort; j++) - if (_res.sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) + for (j = 0 ; (unsigned)j < res->nsort; j++) + if (res->sort_list[j].addr.s_addr == + (((struct in_addr *)(*p))->s_addr & res->sort_list[j].mask)) break; aval[i] = j; if (needsort == 0 && i > 0 && j < aval[i-1]) @@ -677,19 +680,26 @@ addrsort(ap, num) } } #endif + void _sethostdnsent(stayopen) int stayopen; { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) + res_state statp; + + statp = __res_state(); + if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) return; if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; + statp->options |= RES_STAYOPEN | RES_USEVC; } void _endhostdnsent() { - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); + res_state statp; + + statp = __res_state(); + statp->options &= ~(RES_STAYOPEN | RES_USEVC); + res_nclose(statp); } diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index d1ef23bc6477..462cd5c665bb 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -99,12 +99,12 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped) char hostbuf[BUFSIZ + 1]; if (!hed->hostf && !(hed->hostf = fopen(_PATH_HOSTS, "r"))) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } again: if (!(p = fgets(hostbuf, sizeof hostbuf, hed->hostf))) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return -1; } if (*p == '#') @@ -146,7 +146,7 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped) *p++ = '\0'; len = strlen(cp) + 1; if (ep - bp < len) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } strlcpy(bp, cp, ep - bp); @@ -170,14 +170,19 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped) cp = p; } *q = NULL; - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return 0; } int gethostent_r(struct hostent *he, struct hostent_data *hed) { - return gethostent_p(he, hed, _res.options & RES_USE_INET6); + hed->res = __res_state(); + if ((hed->res->options & RES_INIT) == 0 && res_ninit(hed->res) == -1) { + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); + return -1; + } + return gethostent_p(he, hed, hed->res->options & RES_USE_INET6); } struct hostent * @@ -212,7 +217,7 @@ _ht_gethostbyname(void *rval, void *cb_data, va_list ap) if (he->h_addrtype != af) continue; if (he->h_addrtype == AF_INET && - _res.options & RES_USE_INET6) { + hed->res->options & RES_USE_INET6) { _map_v4v6_address(he->h_addr, he->h_addr); he->h_length = IN6ADDRSZ; he->h_addrtype = AF_INET6; @@ -248,7 +253,7 @@ _ht_gethostbyaddr(void *rval, void *cb_data, va_list ap) while ((error = gethostent_p(he, hed, 0)) == 0) if (he->h_addrtype == af && !bcmp(he->h_addr, addr, len)) { if (he->h_addrtype == AF_INET && - _res.options & RES_USE_INET6) { + hed->res->options & RES_USE_INET6) { _map_v4v6_address(he->h_addr, he->h_addr); he->h_length = IN6ADDRSZ; he->h_addrtype = AF_INET6; diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c index 1044fd65b406..1475d840af01 100644 --- a/lib/libc/net/gethostbynis.c +++ b/lib/libc/net/gethostbynis.c @@ -67,19 +67,19 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, break; default: errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } if (hed->yp_domain == (char *)NULL) if (yp_get_default_domain (&hed->yp_domain)) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } if (yp_match(hed->yp_domain, map, name, strlen(name), &result, &resultlen)) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return -1; } @@ -101,7 +101,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, addrok = inet_aton(result, (struct in_addr *)hed->host_addr); if (addrok != 1) break; - if (_res.options & RES_USE_INET6) { + if (hed->res->options & RES_USE_INET6) { _map_v4v6_address((char *)hed->host_addr, (char *)hed->host_addr); af = AF_INET6; @@ -113,7 +113,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, break; } if (addrok != 1) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return -1; } he->h_addr_list[1] = NULL; @@ -130,7 +130,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, *p++ = '\0'; size = strlen(cp) + 1; if (ep - bp < size) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(hed->res, NO_RECOVERY); return -1; } strlcpy(bp, cp, ep - bp); @@ -204,15 +204,18 @@ _gethostbynisname(const char *name, int af) struct hostdata *hd; u_long oresopt; int error; + res_state statp; + statp = __res_state(); if ((hd = __hostdata_init()) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NULL; } - oresopt = _res.options; - _res.options &= ~RES_USE_INET6; + hd->data.res = statp; + oresopt = statp->options; + statp->options &= ~RES_USE_INET6; error = _gethostbynisname_r(name, af, &hd->host, &hd->data); - _res.options = oresopt; + statp->options = oresopt; return (error == 0) ? &hd->host : NULL; #else return NULL; @@ -226,15 +229,18 @@ _gethostbynisaddr(const char *addr, int len, int af) struct hostdata *hd; u_long oresopt; int error; + res_state statp; + statp = __res_state(); if ((hd = __hostdata_init()) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NULL; } - oresopt = _res.options; - _res.options &= ~RES_USE_INET6; + hd->data.res = statp; + oresopt = statp->options; + statp->options &= ~RES_USE_INET6; error = _gethostbynisaddr_r(addr, len, af, &hd->host, &hd->data); - _res.options = oresopt; + statp->options = oresopt; return (error == 0) ? &hd->host : NULL; #else return NULL; diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 0646b0cb4b4b..b641f737b5bc 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -51,7 +51,6 @@ extern int _nis_gethostbyname(void *, void *, va_list); extern int _ht_gethostbyaddr(void *, void *, va_list); extern int _dns_gethostbyaddr(void *, void *, va_list); extern int _nis_gethostbyaddr(void *, void *, va_list); -extern const char *_res_hostalias(const char *, char *, size_t); static int gethostbyname_internal(const char *, int, struct hostent *, struct hostent_data *); @@ -112,11 +111,12 @@ gethostbyname_r(const char *name, struct hostent *he, struct hostent_data *hed) { int error; - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; + hed->res = __res_state(); + if ((hed->res->options & RES_INIT) == 0 && res_ninit(hed->res) == -1) { + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } - if (_res.options & RES_USE_INET6) { + if (hed->res->options & RES_USE_INET6) { error = gethostbyname_internal(name, AF_INET6, he, hed); if (error == 0) return 0; @@ -128,8 +128,9 @@ int gethostbyname2_r(const char *name, int af, struct hostent *he, struct hostent_data *hed) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; + hed->res = __res_state(); + if ((hed->res->options & RES_INIT) == 0 && res_ninit(hed->res) == -1) { + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } return gethostbyname_internal(name, af, he, hed); @@ -159,7 +160,7 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, size = IN6ADDRSZ; break; default: - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); errno = EAFNOSUPPORT; return -1; } @@ -173,7 +174,7 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, * function that looks up host names. */ if (!strchr(name, '.') && - (cp = _res_hostalias(name, abuf, sizeof abuf))) + (cp = res_hostalias(hed->res, name, abuf, sizeof abuf))) name = cp; /* @@ -191,7 +192,8 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, * done a lookup. */ if (inet_pton(af, name, hed->host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, + HOST_NOT_FOUND); return -1; } strncpy(hed->hostbuf, name, MAXDNAME); @@ -204,9 +206,9 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, hed->h_addr_ptrs[0] = (char *)hed->host_addr; hed->h_addr_ptrs[1] = NULL; he->h_addr_list = hed->h_addr_ptrs; - if (_res.options & RES_USE_INET6) + if (hed->res->options & RES_USE_INET6) _map_v4v6_hostent(he, &bp, ep); - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return 0; } if (!isdigit((u_char)*cp) && *cp != '.') @@ -224,7 +226,8 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, * done a lookup. */ if (inet_pton(af, name, hed->host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, + HOST_NOT_FOUND); return -1; } strncpy(hed->hostbuf, name, MAXDNAME); @@ -235,7 +238,7 @@ gethostbyname_internal(const char *name, int af, struct hostent *he, hed->h_addr_ptrs[0] = (char *)hed->host_addr; hed->h_addr_ptrs[1] = NULL; he->h_addr_list = hed->h_addr_ptrs; - h_errno = NETDB_SUCCESS; + RES_SET_H_ERRNO(hed->res, NETDB_SUCCESS); return 0; } if (!isxdigit((u_char)*cp) && *cp != ':' && *cp != '.') @@ -264,15 +267,16 @@ gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, { 0 } }; - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; + hed->res = __res_state(); + if ((hed->res->options & RES_INIT) == 0 && res_ninit(hed->res) == -1) { + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } if (af == AF_INET6 && len == IN6ADDRSZ) { addr6 = (const struct in6_addr *)(const void *)uaddr; if (IN6_IS_ADDR_LINKLOCAL(addr6)) { - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(hed->res, HOST_NOT_FOUND); return -1; } if (IN6_IS_ADDR_V4MAPPED(addr6) || @@ -292,12 +296,12 @@ gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, break; default: errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } if (size != len) { errno = EINVAL; - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(hed->res, NETDB_INTERNAL); return -1; } diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c index 7dbb725c1617..06f4243285ca 100644 --- a/lib/libc/net/getnetbydns.c +++ b/lib/libc/net/getnetbydns.c @@ -85,8 +85,6 @@ __FBSDID("$FreeBSD$"); #include "netdb_private.h" #include "res_config.h" -extern int h_errno; - #define BYADDR 0 #define BYNAME 1 @@ -160,7 +158,7 @@ ipreverse(char *in, char *out) static int getnetanswer(querybuf *answer, int anslen, int net_i, struct netent *ne, - struct netent_data *ned) + struct netent_data *ned, res_state statp) { HEADER *hp; @@ -195,9 +193,9 @@ getnetanswer(querybuf *answer, int anslen, int net_i, struct netent *ne, cp = answer->buf + HFIXEDSZ; if (!qdcount) { if (hp->aa) - h_errno = HOST_NOT_FOUND; + RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); else - h_errno = TRY_AGAIN; + RES_SET_H_ERRNO(statp, TRY_AGAIN); return -1; } while (qdcount-- > 0) @@ -243,14 +241,14 @@ getnetanswer(querybuf *answer, int anslen, int net_i, struct netent *ne, in = *ne->n_aliases; n = strlen(ans) + 1; if (ep - bp < n) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); errno = ENOBUFS; return -1; } strlcpy(bp, ans, ep - bp); ne->n_name = bp; if (strlen(in) + 1 > sizeof(aux)) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); errno = ENOBUFS; return -1; } @@ -261,7 +259,7 @@ getnetanswer(querybuf *answer, int anslen, int net_i, struct netent *ne, ne->n_aliases++; return 0; } - h_errno = TRY_AGAIN; + RES_SET_H_ERRNO(statp, TRY_AGAIN); return -1; } @@ -277,6 +275,7 @@ _dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) querybuf *buf; char qbuf[MAXDNAME]; uint32_t net2; + res_state statp; net = va_arg(ap, uint32_t); net_type = va_arg(ap, int); @@ -286,6 +285,12 @@ _dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) if (net_type != AF_INET) return NS_UNAVAIL; + statp = __res_state(); + if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + return NS_UNAVAIL; + } + for (nn = 4, net2 = net; net2; net2 >>= 8) netbr[--nn] = net2 & 0xff; switch (nn) { @@ -305,26 +310,27 @@ _dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) break; } if ((buf = malloc(sizeof(*buf))) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NS_NOTFOUND; } - anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)buf, sizeof(*buf)); + anslen = res_nquery(statp, qbuf, C_IN, T_PTR, (u_char *)buf, + sizeof(*buf)); if (anslen < 0) { free(buf); #ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("res_search failed\n"); + if (statp->options & RES_DEBUG) + printf("res_nsearch failed\n"); #endif return NS_UNAVAIL; } else if (anslen > sizeof(*buf)) { free(buf); #ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("res_search static buffer too small\n"); + if (statp->options & RES_DEBUG) + printf("res_nsearch static buffer too small\n"); #endif return NS_UNAVAIL; } - error = getnetanswer(buf, anslen, BYADDR, ne, ned); + error = getnetanswer(buf, anslen, BYADDR, ne, ned, statp); free(buf); if (error == 0) { /* Strip trailing zeros */ @@ -345,38 +351,41 @@ _dns_getnetbyname(void *rval, void *cb_data, va_list ap) int anslen, error; querybuf *buf; char qbuf[MAXDNAME]; + res_state statp; net = va_arg(ap, const char *); ne = va_arg(ap, struct netent *); ned = va_arg(ap, struct netent_data *); - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; + statp = __res_state(); + if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NS_UNAVAIL; } if ((buf = malloc(sizeof(*buf))) == NULL) { - h_errno = NETDB_INTERNAL; + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return NS_NOTFOUND; } strncpy(qbuf, net, sizeof(qbuf) - 1); qbuf[sizeof(qbuf) - 1] = '\0'; - anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)buf, sizeof(*buf)); + anslen = res_nsearch(statp, qbuf, C_IN, T_PTR, (u_char *)buf, + sizeof(*buf)); if (anslen < 0) { free(buf); #ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("res_search failed\n"); + if (statp->options & RES_DEBUG) + printf("res_nsearch failed\n"); #endif return NS_UNAVAIL; } else if (anslen > sizeof(*buf)) { free(buf); #ifdef DEBUG - if (_res.options & RES_DEBUG) + if (statp->options & RES_DEBUG) printf("res_search static buffer too small\n"); #endif return NS_UNAVAIL; } - error = getnetanswer(buf, anslen, BYNAME, ne, ned); + error = getnetanswer(buf, anslen, BYNAME, ne, ned, statp); free(buf); return (error == 0) ? NS_SUCCESS : NS_NOTFOUND; } @@ -385,13 +394,21 @@ void _setnetdnsent(stayopen) int stayopen; { + res_state statp; + + statp = __res_state(); + if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) + return; if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; + statp->options |= RES_STAYOPEN | RES_USEVC; } void _endnetdnsent() { - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); + res_state statp; + + statp = __res_state(); + statp->options &= ~(RES_STAYOPEN | RES_USEVC); + res_nclose(statp); } diff --git a/lib/libc/net/getnetbyht.c b/lib/libc/net/getnetbyht.c index 4696b1a0ee6f..30422d53ba92 100644 --- a/lib/libc/net/getnetbyht.c +++ b/lib/libc/net/getnetbyht.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -111,7 +112,7 @@ getnetent_r(struct netent *ne, struct netent_data *ned) *cp++ = '\0'; len = strlen(p) + 1; if (ep - bp < len) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(__res_state(), NO_RECOVERY); return -1; } strlcpy(bp, p, ep - bp); diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c index 200e7a4e269b..ea7c3d4eae32 100644 --- a/lib/libc/net/getnetbynis.c +++ b/lib/libc/net/getnetbynis.c @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -88,7 +89,7 @@ _getnetbynis(const char *name, char *map, int af, struct netent *ne, ep = ned->netbuf + sizeof ned->netbuf; len = strlen(result) + 1; if (ep - bp < len) { - h_errno = NO_RECOVERY; + RES_SET_H_ERRNO(__res_state(), NO_RECOVERY); return -1; } strlcpy(bp, result, ep - bp); diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c deleted file mode 100644 index b84c06c1069f..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include "namespace.h" -#include -#include -#include -#include -#include -#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; diff --git a/lib/libc/net/inet_addr.c b/lib/libc/net/inet_addr.c deleted file mode 100644 index eb97f84513e5..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include - -#include -#include - -#include -#include -#include -#include - -/* - * 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 . - */ -#undef inet_addr -__weak_reference(__inet_addr, inet_addr); -#undef inet_aton -__weak_reference(__inet_aton, inet_aton); diff --git a/lib/libc/net/inet_lnaof.c b/lib/libc/net/inet_lnaof.c deleted file mode 100644 index e45ea6e224f6..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -/* - * 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 . - */ -#undef inet_lnaof -__weak_reference(__inet_lnaof, inet_lnaof); diff --git a/lib/libc/net/inet_makeaddr.c b/lib/libc/net/inet_makeaddr.c deleted file mode 100644 index 4e975138c8f0..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -/* - * 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 . - */ -#undef inet_makeaddr -__weak_reference(__inet_makeaddr, inet_makeaddr); diff --git a/lib/libc/net/inet_net_ntop.c b/lib/libc/net/inet_net_ntop.c deleted file mode 100644 index 9258273312ea..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include -#include -#include - -#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 . - */ -#undef inet_net_ntop -__weak_reference(__inet_net_ntop, inet_net_ntop); diff --git a/lib/libc/net/inet_net_pton.c b/lib/libc/net/inet_net_pton.c deleted file mode 100644 index edd4678b2a7d..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#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 . - */ -#undef inet_net_pton -__weak_reference(__inet_net_pton, inet_net_pton); diff --git a/lib/libc/net/inet_neta.c b/lib/libc/net/inet_neta.c deleted file mode 100644 index c91896277909..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include -#include - -#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 . - */ -#undef inet_neta -__weak_reference(__inet_neta, inet_neta); diff --git a/lib/libc/net/inet_network.c b/lib/libc/net/inet_network.c deleted file mode 100644 index 631cb6a1e3ca..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -/* - * 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 . - */ -#undef inet_network -__weak_reference(__inet_network, inet_network); diff --git a/lib/libc/net/inet_ntoa.c b/lib/libc/net/inet_ntoa.c deleted file mode 100644 index 00f5492cdaaf..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -/* - * 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 . - */ -#undef inet_ntoa -__weak_reference(__inet_ntoa, inet_ntoa); diff --git a/lib/libc/net/inet_ntop.c b/lib/libc/net/inet_ntop.c deleted file mode 100644 index d73a33cf2cee..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * 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 . - */ -#undef inet_ntop -__weak_reference(__inet_ntop, inet_ntop); diff --git a/lib/libc/net/inet_pton.c b/lib/libc/net/inet_pton.c deleted file mode 100644 index 78dbf44d23a5..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * 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 . - */ -#undef inet_pton -__weak_reference(__inet_pton, inet_pton); diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 4e85933cc383..7172c2d987cb 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -122,6 +122,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "netdb_private.h" #include "res_config.h" +#include "res_private.h" #ifndef _PATH_HOSTS #define _PATH_HOSTS "/etc/hosts" @@ -199,18 +200,18 @@ struct hp_order { char *aio_h_addr; }; -static struct hostent *_hpcopy(struct hostent *hp, int *errp); -static struct hostent *_hpaddr(int af, const char *name, void *addr, int *errp); -static struct hostent *_hpmerge(struct hostent *hp1, struct hostent *hp2, int *errp); +static struct hostent *_hpcopy(struct hostent *, int *); +static struct hostent *_hpaddr(int, const char *, void *, int *); +static struct hostent *_hpmerge(struct hostent *, struct hostent *, int *); #ifdef INET6 -static struct hostent *_hpmapv6(struct hostent *hp, int *errp); +static struct hostent *_hpmapv6(struct hostent *, int *); #endif -static struct hostent *_hpsort(struct hostent *hp); -static struct hostent *_ghbyname(const char *name, int af, int flags, int *errp); -static char *_hgetword(char **pp); +static struct hostent *_hpsort(struct hostent *, res_state); +static struct hostent *_ghbyname(const char *, int, int, int *); +static char *_hgetword(char **); static int _mapped_addr_enabled(void); -static struct hostent *_hpreorder(struct hostent *hp); +static struct hostent *_hpreorder(struct hostent *); static int get_addrselectpolicy(struct policyhead *); static void free_addrselectpolicy(struct policyhead *); static struct policyqueue *match_addrselectpolicy(struct sockaddr *, @@ -220,7 +221,7 @@ static int matchlen(struct sockaddr *, struct sockaddr *); static int comp_dst(const void *, const void *); static int gai_addr2scopetype(struct sockaddr *); -static FILE *_files_open(int *errp); +static FILE *_files_open(int *); static int _files_ghbyname(void *, void *, va_list); static int _files_ghbyaddr(void *, void *, va_list); #ifdef YP @@ -229,7 +230,7 @@ static int _nis_ghbyaddr(void *, void *, va_list); #endif static int _dns_ghbyname(void *, void *, va_list); static int _dns_ghbyaddr(void *, void *, va_list); -static void _dns_shent(int stayopen) __unused; +static void _dns_shent(int) __unused; static void _dns_ehent(void) __unused; #ifdef ICMPNL static int _icmp_ghbyaddr(void *, void *, va_list); @@ -290,7 +291,7 @@ _ghbyname(const char *name, int af, int flags, int *errp) { struct hostent *hp; int rval; - + static const ns_dtab dtab[] = { NS_FILES_CB(_files_ghbyname, NULL) { NSSRC_DNS, _dns_ghbyname, NULL }, @@ -323,6 +324,7 @@ getipnodebyname(const char *name, int af, int flags, int *errp) { struct hostent *hp; union inx_addr addrbuf; + res_state statp; switch (af) { case AF_INET: @@ -357,6 +359,14 @@ getipnodebyname(const char *name, int af, int flags, int *errp) return _hpaddr(af, name, &addrbuf, errp); } + statp = __res_state(); + if ((statp->options & RES_INIT) == 0) { + if (res_ninit(statp) < 0) { + *errp = NETDB_INTERNAL; + return NULL; + } + } + *errp = HOST_NOT_FOUND; hp = _ghbyname(name, af, flags, errp); @@ -375,7 +385,7 @@ getipnodebyname(const char *name, int af, int flags, int *errp) } } #endif - return _hpreorder(_hpsort(hp)); + return _hpreorder(_hpsort(hp, statp)); } struct hostent * @@ -657,26 +667,27 @@ _hpmapv6(struct hostent *hp, int *errp) * _hpsort: sort address by sortlist */ static struct hostent * -_hpsort(struct hostent *hp) +_hpsort(struct hostent *hp, res_state statp) { int i, j, n; u_char *ap, *sp, *mp, **pp; char t; char order[MAXADDRS]; - int nsort = _res.nsort; + int nsort = statp->nsort; if (hp == NULL || hp->h_addr_list[1] == NULL || nsort == 0) return hp; for (i = 0; (ap = (u_char *)hp->h_addr_list[i]); i++) { for (j = 0; j < nsort; j++) { #ifdef INET6 - if (_res_ext.sort_list[j].af != hp->h_addrtype) + if (statp->_u._ext.ext->sort_list[j].af != + hp->h_addrtype) continue; - sp = (u_char *)&_res_ext.sort_list[j].addr; - mp = (u_char *)&_res_ext.sort_list[j].mask; + sp = (u_char *)&statp->_u._ext.ext->sort_list[j].addr; + mp = (u_char *)&statp->_u._ext.ext->sort_list[j].mask; #else - sp = (u_char *)&_res.sort_list[j].addr; - mp = (u_char *)&_res.sort_list[j].mask; + sp = (u_char *)&statp->sort_list[j].addr; + mp = (u_char *)&statp->sort_list[j].mask; #endif for (n = 0; n < hp->h_length; n++) { if ((ap[n] & mp[n]) != sp[n]) @@ -1708,17 +1719,14 @@ _dns_ghbyname(void *rval, void *cb_data, va_list ap) int qtype; struct hostent hbuf; querybuf *buf; + res_state statp; name = va_arg(ap, const char *); af = va_arg(ap, int); errp = va_arg(ap, int *); - if ((_res.options & RES_INIT) == 0) { - if (res_init() < 0) { - *errp = h_errno; - return NS_UNAVAIL; - } - } + statp = __res_state(); + memset(&hbuf, 0, sizeof(hbuf)); hbuf.h_addrtype = af; hbuf.h_length = ADDRLEN(af); @@ -1741,10 +1749,10 @@ _dns_ghbyname(void *rval, void *cb_data, va_list ap) *errp = NETDB_INTERNAL; return NS_UNAVAIL; } - n = res_search(name, C_IN, qtype, buf->buf, sizeof(buf->buf)); + n = res_nsearch(statp, name, C_IN, qtype, buf->buf, sizeof(buf->buf)); if (n < 0) { free(buf); - *errp = h_errno; + *errp = statp->res_h_errno; return NS_UNAVAIL; } hp = getanswer(buf, n, name, qtype, &hbuf, errp); @@ -1784,6 +1792,7 @@ _dns_ghbyaddr(void *rval, void *cb_data, va_list ap) char *tld6[] = { "ip6.arpa", NULL }; char *tld4[] = { "in-addr.arpa", NULL }; char **tld; + res_state statp; addr = va_arg(ap, const void *); addrlen = va_arg(ap, int); @@ -1811,9 +1820,10 @@ _dns_ghbyaddr(void *rval, void *cb_data, va_list ap) return NS_NOTFOUND; } - if ((_res.options & RES_INIT) == 0) { - if (res_init() < 0) { - *errp = h_errno; + statp = __res_state(); + if ((statp->options & RES_INIT) == 0) { + if (res_ninit(statp) < 0) { + *errp = NETDB_INTERNAL; return NS_UNAVAIL; } } @@ -1863,9 +1873,10 @@ _dns_ghbyaddr(void *rval, void *cb_data, va_list ap) break; } - n = res_query(qbuf, C_IN, T_PTR, buf->buf, sizeof buf->buf); + n = res_nquery(statp, qbuf, C_IN, T_PTR, buf->buf, + sizeof buf->buf); if (n < 0) { - *errp = h_errno; + *errp = statp->res_h_errno; err = NS_UNAVAIL; continue; } else if (n > sizeof(buf->buf)) { @@ -1897,19 +1908,25 @@ _dns_ghbyaddr(void *rval, void *cb_data, va_list ap) static void _dns_shent(int stayopen) { - if ((_res.options & RES_INIT) == 0) { - if (res_init() < 0) + res_state statp; + + statp = __res_state(); + if ((statp->options & RES_INIT) == 0) { + if (res_ninit(statp) < 0) return; } if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; + statp->options |= RES_STAYOPEN | RES_USEVC; } static void _dns_ehent(void) { - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); + res_state statp; + + statp = __res_state(); + statp->options &= ~(RES_STAYOPEN | RES_USEVC); + res_nclose(statp); } #ifdef ICMPNL diff --git a/lib/libc/net/netdb_private.h b/lib/libc/net/netdb_private.h index 0b3278015ab0..cbdcb174ced1 100644 --- a/lib/libc/net/netdb_private.h +++ b/lib/libc/net/netdb_private.h @@ -36,6 +36,8 @@ #define _HOSTBUFSIZE (8 * 1024) #define _NETBUFSIZE 1025 +struct __res_state; + struct hostent_data { uint32_t host_addr[4]; /* IPv4 or IPv6 */ char *h_addr_ptrs[_MAXADDRS + 1]; @@ -43,6 +45,7 @@ struct hostent_data { char hostbuf[_HOSTBUFSIZE]; FILE *hostf; int stayopen; + struct __res_state *res; #ifdef YP char *yp_domain; #endif diff --git a/lib/libc/net/ns_name.c b/lib/libc/net/ns_name.c deleted file mode 100644 index 5422875cc0c6..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include - -#include -#include - -#include -#include -#include - -/* 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); -} diff --git a/lib/libc/net/ns_netint.c b/lib/libc/net/ns_netint.c deleted file mode 100644 index 845a07e94677..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -/* Import. */ - -#include -#include - -#include -#include - -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); -} diff --git a/lib/libc/net/ns_parse.c b/lib/libc/net/ns_parse.c deleted file mode 100644 index 7b32fa4ce98a..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include - -#include -#include - -#include -#include -#include - -/* 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); -} diff --git a/lib/libc/net/ns_print.c b/lib/libc/net/ns_print.c deleted file mode 100644 index 52e5b03c22ed..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -/* Import. */ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#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 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); -} diff --git a/lib/libc/net/ns_ttl.c b/lib/libc/net/ns_ttl.c deleted file mode 100644 index 79083b2e618c..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -/* Import. */ - -#include - -#include -#include -#include -#include - -#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); -} diff --git a/lib/libc/net/nsap_addr.c b/lib/libc/net/nsap_addr.c deleted file mode 100644 index 61b315fd270b..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include - -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 . - */ -#undef inet_nsap_addr -__weak_reference(__inet_nsap_addr, inet_nsap_addr); -#undef inet_nsap_ntoa -__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa); diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c deleted file mode 100644 index 0739188dc24f..000000000000 --- a/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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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