Index: head/include/arpa/inet.h =================================================================== --- head/include/arpa/inet.h (revision 326694) +++ head/include/arpa/inet.h (revision 326695) @@ -1,180 +1,180 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) * * ++Copyright++ 1983, 1993 * - * 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. 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-- */ /*% * @(#)inet.h 8.1 (Berkeley) 6/2/93 * $Id: inet.h,v 1.3 2005/04/27 04:56:16 sra Exp $ * $FreeBSD$ */ #ifndef _ARPA_INET_H_ #define _ARPA_INET_H_ /* External definitions for functions in inet(3). */ #include #include /* Required for byteorder(3) functions. */ #include #define INET_ADDRSTRLEN 16 #define INET6_ADDRSTRLEN 46 #ifndef _UINT16_T_DECLARED typedef __uint16_t uint16_t; #define _UINT16_T_DECLARED #endif #ifndef _UINT32_T_DECLARED typedef __uint32_t uint32_t; #define _UINT32_T_DECLARED #endif #ifndef _IN_ADDR_T_DECLARED typedef uint32_t in_addr_t; #define _IN_ADDR_T_DECLARED #endif #ifndef _IN_PORT_T_DECLARED typedef uint16_t in_port_t; #define _IN_PORT_T_DECLARED #endif #if __BSD_VISIBLE #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #endif /* * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by * POSIX.1-2001. */ #ifndef _SOCKLEN_T_DECLARED typedef __socklen_t socklen_t; #define _SOCKLEN_T_DECLARED #endif #ifndef _STRUCT_IN_ADDR_DECLARED struct in_addr { in_addr_t s_addr; }; #define _STRUCT_IN_ADDR_DECLARED #endif /* 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_cidr_ntop __inet_cidr_ntop #define inet_cidr_pton __inet_cidr_pton #define inet_ntoa __inet_ntoa #define inet_ntoa_r __inet_ntoa_r #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 #ifndef _BYTEORDER_PROTOTYPED #define _BYTEORDER_PROTOTYPED uint32_t htonl(uint32_t); uint16_t htons(uint16_t); uint32_t ntohl(uint32_t); uint16_t ntohs(uint16_t); #endif in_addr_t inet_addr(const char *); /*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); #if __BSD_VISIBLE int inet_aton(const char *, struct in_addr *); in_addr_t inet_lnaof(struct in_addr); struct in_addr inet_makeaddr(in_addr_t, in_addr_t); char * inet_neta(in_addr_t, char *, size_t); 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_ntoa_r(struct in_addr, char *buf, socklen_t size); 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 */ __END_DECLS #ifndef _BYTEORDER_FUNC_DEFINED #define _BYTEORDER_FUNC_DEFINED #define htonl(x) __htonl(x) #define htons(x) __htons(x) #define ntohl(x) __ntohl(x) #define ntohs(x) __ntohs(x) #endif #endif /* !_ARPA_INET_H_ */ /*! \file */ Index: head/include/arpa/nameser.h =================================================================== --- head/include/arpa/nameser.h (revision 326694) +++ head/include/arpa/nameser.h (revision 326695) @@ -1,682 +1,682 @@ -/* +/*- + * SPDX-License-Identifier: (ISC AND BSD-3-Clause) + * * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (C) 1996-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or 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. */ /*- - * SPDX-License-Identifier: BSD-3-Clause - * * Copyright (c) 1983, 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. 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. */ /* * $Id: nameser.h,v 1.16 2009/03/03 01:52:48 each Exp $ * $FreeBSD$ */ #ifndef _ARPA_NAMESER_H_ #define _ARPA_NAMESER_H_ /*! \file */ #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 libbind.a * contains a new enough lib/nameser/ to support the feature you need. */ #define __NAMESER 20090302 /*%< New interface version stamp. */ /* * Define constants based on RFC0883, RFC1034, RFC 1035 */ #define NS_PACKETSZ 512 /*%< default UDP packet size */ #define NS_MAXDNAME 1025 /*%< maximum domain name (presentation format)*/ #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_MAXLABELS 128 /*%< theoretical max #/labels per domain name */ #define NS_MAXNNAME 256 /*%< maximum uncompressed (binary) domain name*/ #define NS_MAXPADDR (sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") #define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */ #define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */ #define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */ #define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */ #define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */ #define NS_INT8SZ 1 /*%< #/bytes of data in a u_int8_t */ #define NS_INADDRSZ 4 /*%< IPv4 T_A */ #define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */ #define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */ #define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */ /* * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() * in synch with it. */ typedef enum __ns_sect { ns_s_qd = 0, /*%< Query: Question. */ ns_s_zn = 0, /*%< Update: Zone. */ ns_s_an = 1, /*%< Query: Answer. */ ns_s_pr = 1, /*%< Update: Prerequisites. */ ns_s_ns = 2, /*%< Query: Name servers. */ ns_s_ud = 2, /*%< Update: Update. */ ns_s_ar = 3, /*%< Query|Update: Additional records. */ ns_s_max = 4 } ns_sect; /*% * Network name (compressed or not) type. Equivalent to a pointer when used * in a function prototype. Can be const'd. */ typedef u_char ns_nname[NS_MAXNNAME]; typedef const u_char *ns_nname_ct; typedef u_char *ns_nname_t; struct ns_namemap { ns_nname_ct base; int len; }; typedef struct ns_namemap *ns_namemap_t; typedef const struct ns_namemap *ns_namemap_ct; /*% * This is a message handle. It is caller allocated and has no dynamic data. * This structure is intended to be opaque to all but ns_parse.c, thus the * leading _'s on the member names. Use the accessor functions, not the _'s. */ typedef struct __ns_msg { const u_char *_msg, *_eom; u_int16_t _id, _flags, _counts[ns_s_max]; const u_char *_sections[ns_s_max]; ns_sect _sect; int _rrnum; const u_char *_msg_ptr; } ns_msg; /* * This is a newmsg handle, used when constructing new messages with * ns_newmsg_init, et al. */ struct ns_newmsg { ns_msg msg; const u_char *dnptrs[25]; const u_char **lastdnptr; }; typedef struct ns_newmsg ns_newmsg; /* Private data structure - do not use from outside library. */ struct _ns_flagdata { int mask, shift; }; extern struct _ns_flagdata _ns_flagdata[]; /* Accessor macros - this is part of the public interface. */ #define ns_msg_id(handle) ((handle)._id + 0) #define ns_msg_base(handle) ((handle)._msg + 0) #define ns_msg_end(handle) ((handle)._eom + 0) #define ns_msg_size(handle) ((handle)._eom - (handle)._msg) #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) /*% * This is a parsed record. It is caller allocated and has no dynamic data. */ typedef struct __ns_rr { 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; } ns_rr; /* * Same thing, but using uncompressed network binary names, and real C types. */ typedef struct __ns_rr2 { ns_nname nname; size_t nnamel; int type; int rr_class; u_int ttl; int rdlength; const u_char * rdata; } ns_rr2; /* Accessor macros - this is part of the public interface. */ #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") #define ns_rr_nname(rr) ((const ns_nname_t)(rr).nname) #define ns_rr_nnamel(rr) ((rr).nnamel + 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) /*% * These don't have to be in the same order as in the packet flags word, * and they can even overlap in some cases, but they will need to be kept * in synch with ns_parse.c:ns_flagdata[]. */ typedef enum __ns_flag { ns_f_qr, /*%< Question/Response. */ ns_f_opcode, /*%< Operation code. */ ns_f_aa, /*%< Authoritative Answer. */ ns_f_tc, /*%< Truncation occurred. */ ns_f_rd, /*%< Recursion Desired. */ ns_f_ra, /*%< Recursion Available. */ ns_f_z, /*%< MBZ. */ ns_f_ad, /*%< Authentic Data (DNSSEC). */ ns_f_cd, /*%< Checking Disabled (DNSSEC). */ ns_f_rcode, /*%< Response code. */ ns_f_max } ns_flag; /*% * Currently defined opcodes. */ typedef enum __ns_opcode { ns_o_query = 0, /*%< Standard query. */ ns_o_iquery = 1, /*%< Inverse query (deprecated/unsupported). */ ns_o_status = 2, /*%< Name server status query (unsupported). */ /* Opcode 3 is undefined/reserved. */ ns_o_notify = 4, /*%< Zone change notification. */ ns_o_update = 5, /*%< Zone update message. */ ns_o_max = 6 } ns_opcode; /*% * Currently defined response codes. */ typedef enum __ns_rcode { ns_r_noerror = 0, /*%< No error occurred. */ ns_r_formerr = 1, /*%< Format error. */ ns_r_servfail = 2, /*%< Server failure. */ ns_r_nxdomain = 3, /*%< Name error. */ ns_r_notimpl = 4, /*%< Unimplemented. */ ns_r_refused = 5, /*%< Operation refused. */ /* these are for BIND_UPDATE */ ns_r_yxdomain = 6, /*%< Name exists */ ns_r_yxrrset = 7, /*%< RRset exists */ 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, /* 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 */ typedef enum __ns_update_operation { ns_uop_delete = 0, ns_uop_add = 1, ns_uop_max = 2 } ns_update_operation; /*% * This structure is used for TSIG authenticated messages */ struct ns_tsig_key { char name[NS_MAXDNAME], alg[NS_MAXDNAME]; unsigned char *data; int len; }; 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. */ ns_t_mf = 4, /*%< Mail forwarder. */ ns_t_cname = 5, /*%< Canonical name. */ ns_t_soa = 6, /*%< Start of authority zone. */ ns_t_mb = 7, /*%< Mailbox domain name. */ ns_t_mg = 8, /*%< Mail group member. */ ns_t_mr = 9, /*%< Mail rename name. */ ns_t_null = 10, /*%< Null resource record. */ ns_t_wks = 11, /*%< Well known service. */ ns_t_ptr = 12, /*%< Domain name pointer. */ ns_t_hinfo = 13, /*%< Host information. */ ns_t_minfo = 14, /*%< Mailbox information. */ ns_t_mx = 15, /*%< Mail routing information. */ ns_t_txt = 16, /*%< Text strings. */ ns_t_rp = 17, /*%< Responsible person. */ ns_t_afsdb = 18, /*%< AFS cell database. */ ns_t_x25 = 19, /*%< X_25 calling address. */ ns_t_isdn = 20, /*%< ISDN calling address. */ ns_t_rt = 21, /*%< Router. */ ns_t_nsap = 22, /*%< NSAP address. */ ns_t_nsap_ptr = 23, /*%< Reverse NSAP lookup (deprecated). */ ns_t_sig = 24, /*%< Security signature. */ ns_t_key = 25, /*%< Security key. */ ns_t_px = 26, /*%< X.400 mail mapping. */ ns_t_gpos = 27, /*%< Geographical position (withdrawn). */ ns_t_aaaa = 28, /*%< IPv6 Address. */ ns_t_loc = 29, /*%< Location Information. */ ns_t_nxt = 30, /*%< Next domain (security). */ ns_t_eid = 31, /*%< Endpoint identifier. */ ns_t_nimloc = 32, /*%< Nimrod Locator. */ ns_t_srv = 33, /*%< Server Selection. */ ns_t_atma = 34, /*%< ATM Address */ ns_t_naptr = 35, /*%< Naming Authority PoinTeR */ ns_t_kx = 36, /*%< Key Exchange */ ns_t_cert = 37, /*%< Certification record */ ns_t_a6 = 38, /*%< IPv6 address (experimental) */ ns_t_dname = 39, /*%< Non-terminal DNAME */ ns_t_sink = 40, /*%< Kitchen sink (experimentatl) */ ns_t_opt = 41, /*%< EDNS0 option (meta-RR) */ ns_t_apl = 42, /*%< Address prefix list (RFC3123) */ ns_t_ds = 43, /*%< Delegation Signer */ ns_t_sshfp = 44, /*%< SSH Fingerprint */ ns_t_ipseckey = 45, /*%< IPSEC Key */ ns_t_rrsig = 46, /*%< RRset Signature */ ns_t_nsec = 47, /*%< Negative security */ ns_t_dnskey = 48, /*%< DNS Key */ ns_t_dhcid = 49, /*%< Dynamic host configuratin identifier */ ns_t_nsec3 = 50, /*%< Negative security type 3 */ ns_t_nsec3param = 51, /*%< Negative security type 3 parameters */ ns_t_hip = 55, /*%< Host Identity Protocol */ ns_t_spf = 99, /*%< Sender Policy Framework */ 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_dlv = 32769, /*%< DNSSEC look-aside validatation. */ 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. */ 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 */ ns_c_none = 254, /*%< for prereq. sections in update requests */ ns_c_any = 255, /*%< Wildcard match. */ ns_c_max = 65536 } ns_class; /* 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 */ #define NS_KEY_TYPE_AUTH_ONLY 0x4000 /*%< Key usable for authentication */ #define NS_KEY_TYPE_NO_KEY 0xC000 /*%< No key usable for either; no key */ /* 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_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_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_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 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 */ #define NS_SIG_ALG 2 /*%< Algorithm */ #define NS_SIG_LABELS 3 /*%< How many labels in name */ #define NS_SIG_OTTL 4 /*%< Original TTL */ #define NS_SIG_EXPIR 8 /*%< Expiration time */ #define NS_SIG_SIGNED 12 /*%< Signature time */ #define NS_SIG_FOOT 16 /*%< Key footprint */ #define NS_SIG_SIGNER 18 /*%< Domain name of who signed it */ /* How RR types are represented as bit-flags in NXT records */ #define NS_NXT_BITS 8 #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 and option codes, host order. */ #define NS_OPT_DNSSEC_OK 0x8000U #define NS_OPT_NSID 3 /*% * Inline versions of get/put short/long. Pointer is advanced. */ #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) 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) 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) do { \ register u_int32_t t_l = (u_int32_t)(l); \ register u_char *t_cp = (u_char *)(cp); \ *t_cp++ = t_l >> 24; \ *t_cp++ = t_l >> 16; \ *t_cp++ = t_l >> 8; \ *t_cp = t_l; \ (cp) += NS_INT32SZ; \ } while (0) /*% * 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_parserr2 __ns_parserr2 #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_pton2 __ns_name_pton2 #define ns_name_unpack __ns_name_unpack #define ns_name_unpack2 __ns_name_unpack2 #define ns_name_pack __ns_name_pack #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 #define ns_name_length __ns_name_length #define ns_name_eq __ns_name_eq #define ns_name_owned __ns_name_owned #define ns_name_map __ns_name_map #define ns_name_labels __ns_name_labels #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 #endif #define ns_samedomain __ns_samedomain #if 0 #define ns_subdomain __ns_subdomain #endif #define ns_makecanon __ns_makecanon #define ns_samename __ns_samename #define ns_newmsg_init __ns_newmsg_init #define ns_newmsg_copy __ns_newmsg_copy #define ns_newmsg_id __ns_newmsg_id #define ns_newmsg_flag __ns_newmsg_flag #define ns_newmsg_q __ns_newmsg_q #define ns_newmsg_rr __ns_newmsg_rr #define ns_newmsg_done __ns_newmsg_done #define ns_rdata_unpack __ns_rdata_unpack #define ns_rdata_equal __ns_rdata_equal #define ns_rdata_refers __ns_rdata_refers __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_parserr2(ns_msg *, ns_sect, int, ns_rr2 *); int ns_sprintrr(const ns_msg *, const ns_rr *, const char *, const char *, char *, size_t); int ns_sprintrrf(const u_char *, size_t, const char *, ns_class, ns_type, u_long, const u_char *, size_t, const char *, 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_pton2(const char *, u_char *, size_t, size_t *); int ns_name_unpack(const u_char *, const u_char *, const u_char *, u_char *, size_t); int ns_name_unpack2(const u_char *, const u_char *, const u_char *, u_char *, size_t, size_t *); int ns_name_pack(const u_char *, u_char *, int, const u_char **, const u_char **); int ns_name_uncompress(const u_char *, const u_char *, const u_char *, char *, size_t); 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 **); ssize_t ns_name_length(ns_nname_ct, size_t); int ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t); int ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int); int ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int); int ns_name_labels(ns_nname_ct, size_t); #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 *); #endif int ns_samedomain(const char *, const char *); #if 0 int ns_subdomain(const char *, const char *); #endif int ns_makecanon(const char *, char *, size_t); int ns_samename(const char *, const char *); int ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *); int ns_newmsg_copy(ns_newmsg *, ns_msg *); void ns_newmsg_id(ns_newmsg *handle, u_int16_t id); void ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value); int ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname, ns_type qtype, ns_class qclass); int ns_newmsg_rr(ns_newmsg *handle, ns_sect sect, ns_nname_ct name, ns_type type, ns_class rr_class, u_int32_t ttl, u_int16_t rdlen, const u_char *rdata); size_t ns_newmsg_done(ns_newmsg *handle); ssize_t ns_rdata_unpack(const u_char *, const u_char *, ns_type, const u_char *, size_t, u_char *, size_t); int ns_rdata_equal(ns_type, const u_char *, size_t, const u_char *, size_t); int ns_rdata_refers(ns_type, const u_char *, size_t, const u_char *); __END_DECLS #ifdef BIND_4_COMPAT #include #endif #endif /* !_ARPA_NAMESER_H_ */ /*! \file */ Index: head/include/ftw.h =================================================================== --- head/include/ftw.h (revision 326694) +++ head/include/ftw.h (revision 326695) @@ -1,62 +1,64 @@ /* $OpenBSD: ftw.h,v 1.1 2003/07/21 21:13:18 millert Exp $ */ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2003 Todd C. Miller * * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. * * Sponsored in part by the Defense Advanced Research Projects * Agency (DARPA) and Air Force Research Laboratory, Air Force * Materiel Command, USAF, under agreement number F39502-99-1-0512. * * $FreeBSD$ */ #ifndef _FTW_H #define _FTW_H #include #include /* * Valid flags for the 3rd argument to the function that is passed as the * second argument to ftw(3) and nftw(3). Say it three times fast! */ #define FTW_F 0 /* File. */ #define FTW_D 1 /* Directory. */ #define FTW_DNR 2 /* Directory without read permission. */ #define FTW_DP 3 /* Directory with subdirectories visited. */ #define FTW_NS 4 /* Unknown type; stat() failed. */ #define FTW_SL 5 /* Symbolic link. */ #define FTW_SLN 6 /* Sym link that names a nonexistent file. */ /* * Flags for use as the 4th argument to nftw(3). These may be ORed together. */ #define FTW_PHYS 0x01 /* Physical walk, don't follow sym links. */ #define FTW_MOUNT 0x02 /* The walk does not cross a mount point. */ #define FTW_DEPTH 0x04 /* Subdirs visited before the dir itself. */ #define FTW_CHDIR 0x08 /* Change to a directory before reading it. */ struct FTW { int base; int level; }; __BEGIN_DECLS int ftw(const char *, int (*)(const char *, const struct stat *, int), int); int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); __END_DECLS #endif /* !_FTW_H */ Index: head/include/hesiod.h =================================================================== --- head/include/hesiod.h (revision 326694) +++ head/include/hesiod.h (revision 326695) @@ -1,93 +1,93 @@ /* $NetBSD: hesiod.h,v 1.3 1999/01/24 23:53:18 lukem Exp $ */ /* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-NetBSD + * SPDX-License-Identifier: (BSD-2-Clause-NetBSD AND ISC) * * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. * 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. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * 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. */ #ifndef _HESIOD_H_ #define _HESIOD_H_ /* Application-visible indication that we have the new interfaces */ #define HESIOD_INTERFACES /* Configuration information. */ #ifndef _PATH_HESIOD_CONF /* Configuration file. */ #define _PATH_HESIOD_CONF "/etc/hesiod.conf" #endif #define DEF_RHS "" /* Defaults if HESIOD_CONF */ #define DEF_LHS "" /* file is not present. */ /* Error codes (for backwards compatibility) */ #define HES_ER_UNINIT -1 /* uninitialized */ #define HES_ER_OK 0 /* no error */ #define HES_ER_NOTFOUND 1 /* Hesiod name not found by server */ #define HES_ER_CONFIG 2 /* local problem (no config file?) */ #define HES_ER_NET 3 /* network problem */ /* Declaration of routines */ #include __BEGIN_DECLS int hesiod_init(void **); char **hesiod_resolve(void *, const char *, const char *); void hesiod_free_list(void *, char **); char *hesiod_to_bind(void *, const char *, const char *); void hesiod_end(void *); /* backwards compatibility */ int hes_init(void); char *hes_to_bind(const char *, const char *); char **hes_resolve(const char *, const char *); int hes_error(void); void hes_free(char **); __END_DECLS #endif /* ! _HESIOD_H_ */ Index: head/include/netdb.h =================================================================== --- head/include/netdb.h (revision 326694) +++ head/include/netdb.h (revision 326695) @@ -1,306 +1,306 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) * * Copyright (c) 1980, 1983, 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. 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-- */ /* * @(#)netdb.h 8.1 (Berkeley) 6/2/93 * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ * $FreeBSD$ */ #ifndef _NETDB_H_ #define _NETDB_H_ #include #include #ifndef _IN_ADDR_T_DECLARED typedef __uint32_t in_addr_t; #define _IN_ADDR_T_DECLARED #endif #ifndef _IN_PORT_T_DECLARED typedef __uint16_t in_port_t; #define _IN_PORT_T_DECLARED #endif #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #ifndef _SOCKLEN_T_DECLARED typedef __socklen_t socklen_t; #define _SOCKLEN_T_DECLARED #endif #ifndef _UINT32_T_DECLARED typedef __uint32_t uint32_t; #define _UINT32_T_DECLARED #endif #ifndef _PATH_HEQUIV # define _PATH_HEQUIV "/etc/hosts.equiv" #endif #define _PATH_HOSTS "/etc/hosts" #define _PATH_NETWORKS "/etc/networks" #define _PATH_PROTOCOLS "/etc/protocols" #define _PATH_SERVICES "/etc/services" #define _PATH_SERVICES_DB "/var/db/services.db" #define h_errno (*__h_errno()) /* * Structures returned by network data base library. All addresses are * supplied in host order, and returned in network order (suitable for * use in system calls). */ struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses from name server */ #define h_addr h_addr_list[0] /* address, for backward compatibility */ }; struct netent { char *n_name; /* official name of net */ char **n_aliases; /* alias list */ int n_addrtype; /* net address type */ uint32_t n_net; /* network # */ }; struct servent { char *s_name; /* official service name */ char **s_aliases; /* alias list */ int s_port; /* port # */ char *s_proto; /* protocol to use */ }; struct protoent { char *p_name; /* official protocol name */ char **p_aliases; /* alias list */ int p_proto; /* protocol # */ }; struct addrinfo { int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ int ai_family; /* AF_xxx */ int ai_socktype; /* SOCK_xxx */ int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ socklen_t ai_addrlen; /* length of ai_addr */ char *ai_canonname; /* canonical name for hostname */ struct sockaddr *ai_addr; /* binary address */ struct addrinfo *ai_next; /* next structure in linked list */ }; #define IPPORT_RESERVED 1024 /* * Error return codes from gethostbyname() and gethostbyaddr() * (left in h_errno). */ #define NETDB_INTERNAL -1 /* see errno */ #define NETDB_SUCCESS 0 /* no problem */ #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ #define NO_DATA 4 /* Valid name, no data record of requested type */ #define NO_ADDRESS NO_DATA /* no address, look for MX record */ /* * Error return codes from getaddrinfo() */ #if 0 /* obsoleted */ #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ #endif #define EAI_AGAIN 2 /* temporary failure in name resolution */ #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ #define EAI_FAMILY 5 /* ai_family not supported */ #define EAI_MEMORY 6 /* memory allocation failure */ #if 0 /* obsoleted */ #define EAI_NODATA 7 /* no address associated with hostname */ #endif #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ #define EAI_SYSTEM 11 /* system error returned in errno */ #define EAI_BADHINTS 12 /* invalid value for hints */ #define EAI_PROTOCOL 13 /* resolved protocol is unknown */ #define EAI_OVERFLOW 14 /* argument buffer overflow */ #define EAI_MAX 15 /* * Flag values for getaddrinfo() */ #define AI_PASSIVE 0x00000001 /* get address to use bind() */ #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ #define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ #define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ /* valid flags for addrinfo (not a standard def, apps should not use it) */ #define AI_MASK \ (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED) #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ /* special recommended flags for getipnodebyname */ #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) /* * Constants for getnameinfo() */ #define NI_MAXHOST 1025 #define NI_MAXSERV 32 /* * Flag values for getnameinfo() */ #define NI_NOFQDN 0x00000001 #define NI_NUMERICHOST 0x00000002 #define NI_NAMEREQD 0x00000004 #define NI_NUMERICSERV 0x00000008 #define NI_DGRAM 0x00000010 #define NI_NUMERICSCOPE 0x00000020 /* * Scope delimit character */ #define SCOPE_DELIMITER '%' __BEGIN_DECLS void endhostent(void); void endnetent(void); void endprotoent(void); void endservent(void); #if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112) struct hostent *gethostbyaddr(const void *, socklen_t, int); struct hostent *gethostbyname(const char *); #endif struct hostent *gethostent(void); struct netent *getnetbyaddr(uint32_t, int); struct netent *getnetbyname(const char *); struct netent *getnetent(void); struct protoent *getprotobyname(const char *); struct protoent *getprotobynumber(int); struct protoent *getprotoent(void); struct servent *getservbyname(const char *, const char *); struct servent *getservbyport(int, const char *); struct servent *getservent(void); void sethostent(int); /* void sethostfile(const char *); */ void setnetent(int); void setprotoent(int); int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **); int getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int); void freeaddrinfo(struct addrinfo *); const char *gai_strerror(int); void setservent(int); #if __BSD_VISIBLE void endnetgrent(void); void freehostent(struct hostent *); int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); struct hostent *gethostbyname2(const char *, int); int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); int gethostent_r(struct hostent *, char *, size_t, struct hostent **, int *); struct hostent *getipnodebyaddr(const void *, size_t, int, int *); struct hostent *getipnodebyname(const char *, int, int, int *); int getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, struct netent**, int *); int getnetbyname_r(const char *, struct netent *, char *, size_t, struct netent **, int *); int getnetent_r(struct netent *, char *, size_t, struct netent **, int *); int getnetgrent(char **, char **, char **); int getnetgrent_r(char **, char **, char **, char *, size_t); int getprotobyname_r(const char *, struct protoent *, char *, size_t, struct protoent **); int getprotobynumber_r(int, struct protoent *, char *, size_t, struct protoent **); int getprotoent_r(struct protoent *, char *, size_t, struct protoent **); int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); int getservent_r(struct servent *, char *, size_t, struct servent **); void herror(const char *); const char *hstrerror(int); int innetgr(const char *, const char *, const char *, const char *); void setnetgrent(const char *); #endif /* * PRIVATE functions specific to the FreeBSD implementation */ /* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ int * __h_errno(void); __END_DECLS #endif /* !_NETDB_H_ */ Index: head/include/readpassphrase.h =================================================================== --- head/include/readpassphrase.h (revision 326694) +++ head/include/readpassphrase.h (revision 326695) @@ -1,47 +1,49 @@ /* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */ /* $FreeBSD$ */ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2000, 2002 Todd C. Miller * * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. * * Sponsored in part by the Defense Advanced Research Projects * Agency (DARPA) and Air Force Research Laboratory, Air Force * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ #ifndef _READPASSPHRASE_H_ #define _READPASSPHRASE_H_ #define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ #define RPP_ECHO_ON 0x01 /* Leave echo on. */ #define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ #define RPP_FORCELOWER 0x04 /* Force input to lower case. */ #define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ #include #include #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif __BEGIN_DECLS char * readpassphrase(const char *, char *, size_t, int); __END_DECLS #endif /* !_READPASSPHRASE_H_ */ Index: head/include/res_update.h =================================================================== --- head/include/res_update.h (revision 326694) +++ head/include/res_update.h (revision 326695) @@ -1,75 +1,77 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium, Inc. * * 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. */ /* * $Id: res_update.h,v 1.3 2005/04/27 04:56:15 sra Exp $ * $FreeBSD$ */ #ifndef __RES_UPDATE_H #define __RES_UPDATE_H /*! \file */ #include #include #include /*% * This RR-like structure is particular to UPDATE. */ struct ns_updrec { struct { struct ns_updrec *prev; struct ns_updrec *next; } r_link, r_glink; ns_sect r_section; /*%< ZONE/PREREQUISITE/UPDATE */ char * r_dname; /*%< owner of the RR */ ns_class r_class; /*%< class number */ ns_type r_type; /*%< type number */ u_int32_t r_ttl; /*%< time to live */ u_char * r_data; /*%< rdata fields as text string */ u_int r_size; /*%< size of r_data field */ int r_opcode; /*%< type of operation */ /* following fields for private use by the resolver/server routines */ struct databuf *r_dp; /*%< databuf to process */ struct databuf *r_deldp; /*%< databuf's deleted/overwritten */ u_int r_zone; /*%< zone number on server */ }; typedef struct ns_updrec ns_updrec; typedef struct { ns_updrec *head; ns_updrec *tail; } ns_updque; #define res_mkupdate __res_mkupdate #define res_update __res_update #define res_mkupdrec __res_mkupdrec #define res_freeupdrec __res_freeupdrec #define res_nmkupdate __res_nmkupdate #define res_nupdate __res_nupdate int res_mkupdate(ns_updrec *, u_char *, int); int res_update(ns_updrec *); ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long); void res_freeupdrec(ns_updrec *); int res_nmkupdate(res_state, ns_updrec *, u_char *, int); int res_nupdate(res_state, ns_updrec *, ns_tsig_key *); #endif /*__RES_UPDATE_H*/ /*! \file */ Index: head/include/resolv.h =================================================================== --- head/include/resolv.h (revision 326694) +++ head/include/resolv.h (revision 326695) @@ -1,505 +1,505 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (ISC AND BSD-3-Clause) * * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (C) 1995-2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or 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. */ /* * 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: * 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. 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. */ /*% * @(#)resolv.h 8.1 (Berkeley) 6/2/93 * $Id: resolv.h,v 1.30 2009/03/03 01:52:48 each Exp $ * $FreeBSD$ */ #ifndef _RESOLV_H_ #define _RESOLV_H_ #include #include #include #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 (__RES > 19931104)". Do not * compare for equality; rather, use it to determine whether your resolver * is new enough to contain a certain feature. */ #define __RES 20090302 /*% * 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 * 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. */ #define MAXNS 3 /*%< max # name servers we'll track */ #define MAXDFLSRCH 3 /*%< # default domain levels to try */ #define MAXDNSRCH 6 /*%< max # domains in search path */ #define LOCALDOMAINPARTS 2 /*%< min levels in name that is "local" */ #define RES_TIMEOUT 5 /*%< min. seconds between retries */ #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; /*%< 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 */ #define nsaddr nsaddr_list[0] /*%< for backward compatibility */ 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]; struct { struct in_addr addr; u_int32_t mask; } sort_list[MAXRESOLVSORT]; 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) - 3*sizeof (void *)]; struct { u_int16_t nscount; u_int16_t nstimes[MAXNS]; /*%< ms. */ int nssocks[MAXNS]; struct __res_state_ext *ext; /*%< extension for IPv6 */ } _ext; } _u; u_char *_rnd; /*%< PRIVATE: random state */ }; 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) */ #define RES_INIT 0x00000001 /*%< address initialized */ #define RES_DEBUG 0x00000002 /*%< print debug messages */ #define RES_AAONLY 0x00000004 /*%< authoritative answers only (!IMPL)*/ #define RES_USEVC 0x00000008 /*%< use virtual circuit */ #define RES_PRIMARY 0x00000010 /*%< query primary server only (!IMPL) */ #define RES_IGNTC 0x00000020 /*%< ignore truncation errors */ #define RES_RECURSE 0x00000040 /*%< recursion desired */ #define RES_DEFNAMES 0x00000080 /*%< use default domain name */ #define RES_STAYOPEN 0x00000100 /*%< Keep TCP socket open */ #define RES_DNSRCH 0x00000200 /*%< search up local domain tree */ #define RES_INSECURE1 0x00000400 /*%< type 1 security disabled */ #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_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_NSID 0x00040000 /*%< request name server ID */ #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_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 | RES_NO_NIBBLE2) /*% * Resolver "pfcode" values. Used by dig. */ #define RES_PRF_STATS 0x00000001 #define RES_PRF_UPDATE 0x00000002 #define RES_PRF_CLASS 0x00000004 #define RES_PRF_CMD 0x00000008 #define RES_PRF_QUES 0x00000010 #define RES_PRF_ANS 0x00000020 #define RES_PRF_AUTH 0x00000040 #define RES_PRF_ADD 0x00000080 #define RES_PRF_HEAD1 0x00000100 #define RES_PRF_HEAD2 0x00000200 #define RES_PRF_TTLID 0x00000400 #define RES_PRF_HEADX 0x00000800 #define RES_PRF_QUERY 0x00001000 #define RES_PRF_REPLY 0x00002000 #define RES_PRF_INIT 0x00004000 #define RES_PRF_TRUNC 0x00008000 /* 0x00010000 */ /* Things involving an internal (static) resolver context. */ __BEGIN_DECLS extern struct __res_state *__res_state(void); __END_DECLS #define _res (*__res_state()) #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 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 #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 */ #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 #endif #define res_findzonecut2 __res_findzonecut2 #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_rndinit __res_rndinit #define res_randomid __res_randomid #define res_nrandomid __res_nrandomid #define sym_ntop __sym_ntop #define sym_ntos __sym_ntos #define sym_ston __sym_ston #define res_nopt __res_nopt #define res_nopt_rdata __res_nopt_rdata #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 #if 0 #define res_buildprotolist __res_buildprotolist #define res_destroyprotolist __res_destroyprotolist #define res_destroyservicelist __res_destroyservicelist #define res_get_nibblesuffix __res_get_nibblesuffix #define res_get_nibblesuffix2 __res_get_nibblesuffix2 #endif #define res_ourserver_p __res_ourserver_p #if 0 #define res_protocolname __res_protocolname #define res_protocolnumber __res_protocolnumber #endif #define res_send_setqhook __res_send_setqhook #define res_send_setrhook __res_send_setrhook #if 0 #define res_servicename __res_servicename #define res_servicenumber __res_servicenumber #endif __BEGIN_DECLS int res_hnok(const char *); int res_ownok(const char *); int res_mailok(const char *); int res_dnok(const char *); int sym_ston(const struct res_sym *, const char *, int *); const char * sym_ntos(const struct res_sym *, int, int *); const char * sym_ntop(const struct res_sym *, int, int *); int b64_ntop(u_char const *, size_t, char *, size_t); 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 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); 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_fqname(const u_char *, const u_char *, FILE *); const char * p_option(u_long); char * p_secstodate(u_long); 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); void res_rndinit(res_state); u_int res_randomid(void); u_int res_nrandomid(res_state); 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 *); const char * p_section(int, int); /* 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); #endif int res_findzonecut2(res_state, const char *, ns_class, int, char *, size_t, union res_sockaddr_union *, int); void res_nclose(res_state); int res_nopt(res_state, int, u_char *, int, int); int res_nopt_rdata(res_state, int, u_char *, int, u_char *, u_short, u_short, u_char *); void res_send_setqhook(res_send_qhook); void res_send_setrhook(res_send_rhook); int __res_vinit(res_state, int); #if 0 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); 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_ */ /*! \file */ Index: head/include/unwind.h =================================================================== --- head/include/unwind.h (revision 326694) +++ head/include/unwind.h (revision 326695) @@ -1,156 +1,160 @@ /* $FreeBSD$ */ -/* libunwind - a platform-independent unwind library +/*- + libunwind - a platform-independent unwind library + + SPDX-License-Identifier: ISC + Copyright (C) 2003 Hewlett-Packard Co Contributed by David Mosberger-Tang This file is part of libunwind. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _UNWIND_H #define _UNWIND_H #include #ifdef __cplusplus extern "C" { #endif /* Minimal interface as per C++ ABI draft standard: http://www.codesourcery.com/cxx-abi/abi-eh.html */ typedef enum { _URC_NO_REASON = 0, _URC_FOREIGN_EXCEPTION_CAUGHT = 1, _URC_FATAL_PHASE2_ERROR = 2, _URC_FATAL_PHASE1_ERROR = 3, _URC_NORMAL_STOP = 4, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8 } _Unwind_Reason_Code; typedef int _Unwind_Action; #define _UA_SEARCH_PHASE 1 #define _UA_CLEANUP_PHASE 2 #define _UA_HANDLER_FRAME 4 #define _UA_FORCE_UNWIND 8 struct _Unwind_Context; /* opaque data-structure */ struct _Unwind_Exception; /* forward-declaration */ typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, struct _Unwind_Exception *); typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action, __int64_t, struct _Unwind_Exception *, struct _Unwind_Context *, void *); /* The C++ ABI requires exception_class, private_1, and private_2 to be of type uint64 and the entire structure to be double-word-aligned, but that seems a bit overly IA-64-specific. Using "unsigned long" instead should give us the desired effect on IA-64, while being more general. */ struct _Unwind_Exception { __int64_t exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; unsigned long private_1; unsigned long private_2; }; extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *); extern void _Unwind_Resume (struct _Unwind_Exception *); extern void _Unwind_DeleteException (struct _Unwind_Exception *); extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int); extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long); extern unsigned long _Unwind_GetIP (struct _Unwind_Context *); extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *); extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long); extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*); extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *); #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) /* Callback for _Unwind_Backtrace(). The backtrace stops immediately if the callback returns any value other than _URC_NO_REASON. */ typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, void *); /* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why _UA_END_OF_STACK exists. */ # define _UA_END_OF_STACK 16 /* If the unwind was initiated due to a forced unwind, resume that operation, else re-raise the exception. This is used by __cxa_rethrow(). */ extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); /* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why _Unwind_GetBSP() exists. */ extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *); /* Return the "canonical frame address" for the given context. This is used by NPTL... */ extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *); /* Return the base-address for data references. */ extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *); /* Return the base-address for text references. */ extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *); /* Call _Unwind_Trace_Fn once for each stack-frame, without doing any cleanup. The first frame for which the callback is invoked is the one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace() returns _URC_END_OF_STACK when the backtrace stopped due to reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it stops for any other reason. */ extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); /* Find the start-address of the procedure containing the specified IP or NULL if it cannot be found (e.g., because the function has no unwind info). Note: there is not necessarily a one-to-one correspondence between source-level functions and procedures: some functions don't have unwind-info and others are split into multiple procedures. */ extern void *_Unwind_FindEnclosingFunction (void *); /* See also Linux Standard Base Spec: http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */ #endif /* _GNU_SOURCE || _BSD_SOURCE */ #ifdef __cplusplus }; #endif #endif /* _UNWIND_H */ Index: head/include/wchar.h =================================================================== --- head/include/wchar.h (revision 326694) +++ head/include/wchar.h (revision 326695) @@ -1,241 +1,241 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause + * SPDX-License-Identifier: (BSD-2-Clause AND BSD-2-Clause-NetBSD) * * Copyright (c)1999 Citrus Project, * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. * * $FreeBSD$ */ /*- * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Julian Coleman. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $NetBSD: wchar.h,v 1.8 2000/12/22 05:31:42 itojun Exp $ */ #ifndef _WCHAR_H_ #define _WCHAR_H_ #include #include #include #include #include <_ctype.h> #ifndef _MBSTATE_T_DECLARED typedef __mbstate_t mbstate_t; #define _MBSTATE_T_DECLARED #endif #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE #ifndef _VA_LIST_DECLARED typedef __va_list va_list; #define _VA_LIST_DECLARED #endif #endif #ifndef __cplusplus #ifndef _WCHAR_T_DECLARED typedef ___wchar_t wchar_t; #define _WCHAR_T_DECLARED #endif #endif #ifndef _WINT_T_DECLARED typedef __wint_t wint_t; #define _WINT_T_DECLARED #endif #define WCHAR_MIN __WCHAR_MIN #define WCHAR_MAX __WCHAR_MAX #ifndef WEOF #define WEOF ((wint_t)-1) #endif #ifndef _STDFILE_DECLARED #define _STDFILE_DECLARED typedef struct __sFILE FILE; #endif struct tm; __BEGIN_DECLS wint_t btowc(int); wint_t fgetwc(FILE *); wchar_t * fgetws(wchar_t * __restrict, int, FILE * __restrict); wint_t fputwc(wchar_t, FILE *); int fputws(const wchar_t * __restrict, FILE * __restrict); int fwide(FILE *, int); int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...); int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...); wint_t getwc(FILE *); wint_t getwchar(void); size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict); int mbsinit(const mbstate_t *); size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, mbstate_t * __restrict); wint_t putwc(wchar_t, FILE *); wint_t putwchar(wchar_t); int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ...); int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); wint_t ungetwc(wint_t, FILE *); int vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list); int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, __va_list); int vwprintf(const wchar_t * __restrict, __va_list); size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); wchar_t *wcschr(const wchar_t *, wchar_t) __pure; int wcscmp(const wchar_t *, const wchar_t *) __pure; int wcscoll(const wchar_t *, const wchar_t *); wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); size_t wcscspn(const wchar_t *, const wchar_t *) __pure; size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict, const struct tm * __restrict); size_t wcslen(const wchar_t *) __pure; wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, size_t); int wcsncmp(const wchar_t *, const wchar_t *, size_t) __pure; wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, size_t); wchar_t *wcspbrk(const wchar_t *, const wchar_t *) __pure; wchar_t *wcsrchr(const wchar_t *, wchar_t) __pure; size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t, mbstate_t * __restrict); size_t wcsspn(const wchar_t *, const wchar_t *) __pure; wchar_t *wcsstr(const wchar_t * __restrict, const wchar_t * __restrict) __pure; size_t wcsxfrm(wchar_t * __restrict, const wchar_t * __restrict, size_t); int wctob(wint_t); double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, wchar_t ** __restrict); long wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int); unsigned long wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int); wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) __pure; int wmemcmp(const wchar_t *, const wchar_t *, size_t) __pure; wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); wchar_t *wmemset(wchar_t *, wchar_t, size_t); int wprintf(const wchar_t * __restrict, ...); int wscanf(const wchar_t * __restrict, ...); #ifndef _STDSTREAM_DECLARED extern FILE *__stdinp; extern FILE *__stdoutp; extern FILE *__stderrp; #define _STDSTREAM_DECLARED #endif #define getwc(fp) fgetwc(fp) #define getwchar() fgetwc(__stdinp) #define putwc(wc, fp) fputwc(wc, fp) #define putwchar(wc) fputwc(wc, __stdoutp) #if __ISO_C_VISIBLE >= 1999 int vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, __va_list); int vwscanf(const wchar_t * __restrict, __va_list); float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict); #ifdef __LONG_LONG_SUPPORTED /* LONGLONG */ long long wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int); /* LONGLONG */ unsigned long long wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int); #endif #endif /* __ISO_C_VISIBLE >= 1999 */ #if __XSI_VISIBLE int wcswidth(const wchar_t *, size_t); int wcwidth(wchar_t); #define wcwidth(_c) __wcwidth(_c) #endif #if __POSIX_VISIBLE >= 200809 size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, size_t, mbstate_t * __restrict); FILE *open_wmemstream(wchar_t **, size_t *); wchar_t *wcpcpy(wchar_t * __restrict, const wchar_t * __restrict); wchar_t *wcpncpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); wchar_t *wcsdup(const wchar_t *) __malloc_like; int wcscasecmp(const wchar_t *, const wchar_t *); int wcsncasecmp(const wchar_t *, const wchar_t *, size_t n); size_t wcsnlen(const wchar_t *, size_t) __pure; size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t, size_t, mbstate_t * __restrict); #endif #if __BSD_VISIBLE wchar_t *fgetwln(FILE * __restrict, size_t * __restrict); size_t wcslcat(wchar_t *, const wchar_t *, size_t); size_t wcslcpy(wchar_t *, const wchar_t *, size_t); #endif #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) #include #endif __END_DECLS #endif /* !_WCHAR_H_ */ Index: head/lib/libc/include/isc/eventlib.h =================================================================== --- head/lib/libc/include/isc/eventlib.h (revision 326694) +++ head/lib/libc/include/isc/eventlib.h (revision 326695) @@ -1,206 +1,208 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1995-1999, 2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or 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. */ /* eventlib.h - exported interfaces for eventlib * vix 09sep95 [initial] * * $Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp $ */ #ifndef _EVENTLIB_H #define _EVENTLIB_H #include #include #include #include #include #ifndef __P # define __EVENTLIB_P_DEFINED # ifdef __STDC__ # define __P(x) x # else # define __P(x) () # endif #endif /* In the absence of branded types... */ typedef struct { void *opaque; } evConnID; typedef struct { void *opaque; } evFileID; typedef struct { void *opaque; } evStreamID; typedef struct { void *opaque; } evTimerID; typedef struct { void *opaque; } evWaitID; typedef struct { void *opaque; } evContext; typedef struct { void *opaque; } evEvent; #define evInitID(id) ((id)->opaque = NULL) #define evTestID(id) ((id).opaque != NULL) typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int, const void *, int)); typedef void (*evFileFunc)__P((evContext, void *, int, int)); typedef void (*evStreamFunc)__P((evContext, void *, int, int)); typedef void (*evTimerFunc)__P((evContext, void *, struct timespec, struct timespec)); typedef void (*evWaitFunc)__P((evContext, void *, const void *)); typedef struct { unsigned char mask[256/8]; } evByteMask; #define EV_BYTEMASK_BYTE(b) ((b) / 8) #define EV_BYTEMASK_MASK(b) (1 << ((b) % 8)) #define EV_BYTEMASK_SET(bm, b) \ ((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b)) #define EV_BYTEMASK_CLR(bm, b) \ ((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b)) #define EV_BYTEMASK_TST(bm, b) \ ((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b)) #define EV_POLL 1 #define EV_WAIT 2 #define EV_NULL 4 #define EV_READ 1 #define EV_WRITE 2 #define EV_EXCEPT 4 #define EV_WASNONBLOCKING 8 /* Internal library use. */ /* eventlib.c */ #define evCreate __evCreate #define evSetDebug __evSetDebug #define evDestroy __evDestroy #define evGetNext __evGetNext #define evDispatch __evDispatch #define evDrop __evDrop #define evMainLoop __evMainLoop #define evHighestFD __evHighestFD #define evGetOption __evGetOption #define evSetOption __evSetOption int evCreate __P((evContext *)); void evSetDebug __P((evContext, int, FILE *)); int evDestroy __P((evContext)); int evGetNext __P((evContext, evEvent *, int)); int evDispatch __P((evContext, evEvent)); void evDrop __P((evContext, evEvent)); int evMainLoop __P((evContext)); int evHighestFD __P((evContext)); int evGetOption __P((evContext *, const char *, int *)); int evSetOption __P((evContext *, const char *, int)); /* ev_connects.c */ #define evListen __evListen #define evConnect __evConnect #define evCancelConn __evCancelConn #define evHold __evHold #define evUnhold __evUnhold #define evTryAccept __evTryAccept int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *)); int evConnect __P((evContext, int, const void *, int, evConnFunc, void *, evConnID *)); int evCancelConn __P((evContext, evConnID)); int evHold __P((evContext, evConnID)); int evUnhold __P((evContext, evConnID)); int evTryAccept __P((evContext, evConnID, int *)); /* ev_files.c */ #define evSelectFD __evSelectFD #define evDeselectFD __evDeselectFD int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *)); int evDeselectFD __P((evContext, evFileID)); /* ev_streams.c */ #define evConsIovec __evConsIovec #define evWrite __evWrite #define evRead __evRead #define evTimeRW __evTimeRW #define evUntimeRW __evUntimeRW #define evCancelRW __evCancelRW struct iovec evConsIovec __P((void *, size_t)); int evWrite __P((evContext, int, const struct iovec *, int, evStreamFunc func, void *, evStreamID *)); int evRead __P((evContext, int, const struct iovec *, int, evStreamFunc func, void *, evStreamID *)); int evTimeRW __P((evContext, evStreamID, evTimerID timer)); int evUntimeRW __P((evContext, evStreamID)); int evCancelRW __P((evContext, evStreamID)); /* ev_timers.c */ #define evConsTime __evConsTime #define evAddTime __evAddTime #define evSubTime __evSubTime #define evCmpTime __evCmpTime #define evTimeSpec __evTimeSpec #define evTimeVal __evTimeVal #define evNowTime __evNowTime #define evUTCTime __evUTCTime #define evLastEventTime __evLastEventTime #define evSetTimer __evSetTimer #define evClearTimer __evClearTimer #define evConfigTimer __evConfigTimer #define evResetTimer __evResetTimer #define evSetIdleTimer __evSetIdleTimer #define evClearIdleTimer __evClearIdleTimer #define evResetIdleTimer __evResetIdleTimer #define evTouchIdleTimer __evTouchIdleTimer struct timespec evConsTime __P((time_t sec, long nsec)); struct timespec evAddTime __P((struct timespec, struct timespec)); struct timespec evSubTime __P((struct timespec, struct timespec)); struct timespec evNowTime __P((void)); struct timespec evUTCTime __P((void)); struct timespec evLastEventTime __P((evContext)); struct timespec evTimeSpec __P((struct timeval)); struct timeval evTimeVal __P((struct timespec)); int evCmpTime __P((struct timespec, struct timespec)); int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec, struct timespec, evTimerID *)); int evClearTimer __P((evContext, evTimerID)); int evConfigTimer __P((evContext, evTimerID, const char *param, int value)); int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *, struct timespec, struct timespec)); int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec, evTimerID *)); int evClearIdleTimer __P((evContext, evTimerID)); int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *, struct timespec)); int evTouchIdleTimer __P((evContext, evTimerID)); /* ev_waits.c */ #define evWaitFor __evWaitFor #define evDo __evDo #define evUnwait __evUnwait #define evDefer __evDefer int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *)); int evDo __P((evContext, const void *)); int evUnwait __P((evContext, evWaitID)); int evDefer __P((evContext, evWaitFunc, void *)); #ifdef __EVENTLIB_P_DEFINED # undef __P #endif #endif /*_EVENTLIB_H*/ /*! \file */ Index: head/lib/libc/include/isc/list.h =================================================================== --- head/lib/libc/include/isc/list.h (revision 326694) +++ head/lib/libc/include/isc/list.h (revision 326695) @@ -1,125 +1,127 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,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. */ /* $FreeBSD$ */ #ifndef LIST_H #define LIST_H 1 #ifdef _LIBC #include #define INSIST(cond) assert(cond) #else #include #endif #define LIST(type) struct { type *head, *tail; } #define INIT_LIST(list) \ do { (list).head = NULL; (list).tail = NULL; } while (0) #define LINK(type) struct { type *prev, *next; } #define INIT_LINK_TYPE(elt, link, type) \ do { \ (elt)->link.prev = (type *)(-1); \ (elt)->link.next = (type *)(-1); \ } while (0) #define INIT_LINK(elt, link) \ INIT_LINK_TYPE(elt, link, void) #define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1) && \ (void *)((elt)->link.next) != (void *)(-1)) #define HEAD(list) ((list).head) #define TAIL(list) ((list).tail) #define EMPTY(list) ((list).head == NULL) #define PREPEND(list, elt, link) \ do { \ INSIST(!LINKED(elt, link));\ if ((list).head != NULL) \ (list).head->link.prev = (elt); \ else \ (list).tail = (elt); \ (elt)->link.prev = NULL; \ (elt)->link.next = (list).head; \ (list).head = (elt); \ } while (0) #define APPEND(list, elt, link) \ do { \ INSIST(!LINKED(elt, link));\ if ((list).tail != NULL) \ (list).tail->link.next = (elt); \ else \ (list).head = (elt); \ (elt)->link.prev = (list).tail; \ (elt)->link.next = NULL; \ (list).tail = (elt); \ } while (0) #define UNLINK_TYPE(list, elt, link, type) \ do { \ INSIST(LINKED(elt, link));\ if ((elt)->link.next != NULL) \ (elt)->link.next->link.prev = (elt)->link.prev; \ else { \ INSIST((list).tail == (elt)); \ (list).tail = (elt)->link.prev; \ } \ if ((elt)->link.prev != NULL) \ (elt)->link.prev->link.next = (elt)->link.next; \ else { \ INSIST((list).head == (elt)); \ (list).head = (elt)->link.next; \ } \ INIT_LINK_TYPE(elt, link, type); \ } while (0) #define UNLINK(list, elt, link) \ UNLINK_TYPE(list, elt, link, void) #define PREV(elt, link) ((elt)->link.prev) #define NEXT(elt, link) ((elt)->link.next) #define INSERT_BEFORE(list, before, elt, link) \ do { \ INSIST(!LINKED(elt, link));\ if ((before)->link.prev == NULL) \ PREPEND(list, elt, link); \ else { \ (elt)->link.prev = (before)->link.prev; \ (before)->link.prev = (elt); \ (elt)->link.prev->link.next = (elt); \ (elt)->link.next = (before); \ } \ } while (0) #define INSERT_AFTER(list, after, elt, link) \ do { \ INSIST(!LINKED(elt, link));\ if ((after)->link.next == NULL) \ APPEND(list, elt, link); \ else { \ (elt)->link.next = (after)->link.next; \ (after)->link.next = (elt); \ (elt)->link.next->link.prev = (elt); \ (elt)->link.prev = (after); \ } \ } while (0) #define ENQUEUE(list, elt, link) APPEND(list, elt, link) #define DEQUEUE(list, elt, link) UNLINK(list, elt, link) #endif /* LIST_H */ /*! \file */ Index: head/lib/libc/include/isc/platform.h =================================================================== --- head/lib/libc/include/isc/platform.h (revision 326694) +++ head/lib/libc/include/isc/platform.h (revision 326695) @@ -1,37 +1,39 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or 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. */ /* $Id: platform.h.in,v 1.2.6.2 2008/01/23 02:15:02 tbox Exp $ */ /* $FreeBSD$ */ /*! \file */ #ifndef ISC_PLATFORM_H #define ISC_PLATFORM_H /* * Define if the OS does not define struct timespec. */ #undef ISC_PLATFORM_NEEDTIMESPEC #ifdef ISC_PLATFORM_NEEDTIMESPEC #include /* For time_t */ struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; #endif #endif Index: head/lib/libc/inet/inet_addr.c =================================================================== --- head/lib/libc/inet/inet_addr.c (revision 326694) +++ head/lib/libc/inet/inet_addr.c (revision 326695) @@ -1,216 +1,216 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) * * 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. 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 (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 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 sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; static const char rcsid[] = "$Id: inet_addr.c,v 1.5 2005/04/27 04:56:19 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include "port_after.h" /*% * Ascii internet address interpretation routine. * The value returned is in network order. */ in_addr_t /* XXX should be struct in_addr :( */ inet_addr(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(const char *cp, struct in_addr *addr) { u_long val; int base, n; char c; u_int8_t parts[4]; u_int8_t *pp = parts; int digit; c = *cp; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ if (!isdigit((unsigned char)c)) return (0); val = 0; base = 10; digit = 0; if (c == '0') { c = *++cp; if (c == 'x' || c == 'X') base = 16, c = *++cp; else { base = 8; digit = 1 ; } } for (;;) { if (isascii(c) && isdigit((unsigned char)c)) { if (base == 8 && (c == '8' || c == '9')) return (0); val = (val * base) + (c - '0'); c = *++cp; digit = 1; } else if (base == 16 && isascii(c) && isxdigit((unsigned char)c)) { val = (val << 4) | (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); c = *++cp; digit = 1; } else break; } if (c == '.') { /* * Internet format: * a.b.c.d * a.b.c (with c treated as 16 bits) * a.b (with b treated as 24 bits) */ if (pp >= parts + 3 || val > 0xffU) return (0); *pp++ = val; c = *++cp; } else break; } /* * Check for trailing characters. */ if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c))) return (0); /* * Did we get a valid digit? */ if (!digit) return (0); /* * Concoct the address according to * the number of parts specified. */ n = pp - parts + 1; switch (n) { case 1: /*%< a -- 32 bits */ break; case 2: /*%< a.b -- 8.24 bits */ if (val > 0xffffffU) return (0); val |= parts[0] << 24; break; case 3: /*%< a.b.c -- 8.8.16 bits */ if (val > 0xffffU) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ if (val > 0xffU) 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); /*! \file */ Index: head/lib/libc/inet/inet_cidr_ntop.c =================================================================== --- head/lib/libc/inet/inet_cidr_ntop.c (revision 326694) +++ head/lib/libc/inet/inet_cidr_ntop.c (revision 326695) @@ -1,265 +1,267 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,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 rcsid[] = "$Id: inet_cidr_ntop.c,v 1.7 2006/10/11 02:18:18 marka Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size); static char * inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size); /*% * char * * inet_cidr_ntop(af, src, bits, dst, size) * convert network address from network to presentation format. * "src"'s size is determined from its "af". * return: * pointer to dst, or NULL if an error occurred (check errno). * note: * 192.5.5.1/28 has a nonzero host part, which means it isn't a network * as called for by inet_net_ntop() but it can be a host address with * an included netmask. * author: * Paul Vixie (ISC), October 1998 */ char * inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { case AF_INET: return (inet_cidr_ntop_ipv4(src, bits, dst, size)); case AF_INET6: return (inet_cidr_ntop_ipv6(src, bits, dst, size)); default: errno = EAFNOSUPPORT; return (NULL); } } static int decoct(const u_char *src, int bytes, char *dst, size_t size) { char *odst = dst; char *t; int b; for (b = 1; b <= bytes; b++) { if (size < sizeof "255.") return (0); t = dst; dst += SPRINTF((dst, "%u", *src++)); if (b != bytes) { *dst++ = '.'; *dst = '\0'; } size -= (size_t)(dst - t); } return (dst - odst); } /*% * static char * * inet_cidr_ntop_ipv4(src, bits, dst, size) * convert IPv4 network address from network to presentation format. * "src"'s size is determined from its "af". * 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), October 1998 */ static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { char *odst = dst; size_t len = 4; size_t b; size_t bytes; if ((bits < -1) || (bits > 32)) { errno = EINVAL; return (NULL); } /* Find number of significant bytes in address. */ if (bits == -1) len = 4; else for (len = 1, b = 1 ; b < 4U; b++) if (*(src + b)) len = b + 1; /* Format whole octets plus nonzero trailing octets. */ bytes = (((bits <= 0) ? 1 : bits) + 7) / 8; if (len > bytes) bytes = len; b = decoct(src, bytes, dst, size); if (b == 0U) goto emsgsize; dst += b; size -= b; if (bits != -1) { /* Format CIDR /width. */ if (size < sizeof "/32") goto emsgsize; dst += SPRINTF((dst, "/%u", bits)); } return (odst); emsgsize: errno = EMSGSIZE; return (NULL); } static char * inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_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/128"]; char *tp; struct { int base, len; } best, cur; u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; int i; if ((bits < -1) || (bits > 128)) { errno = EINVAL; return (NULL); } /* * 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; best.len = 0; cur.base = -1; cur.len = 0; 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 == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { int n; if (src[15] || bits == -1 || bits > 120) n = 4; else if (src[14] || bits > 112) n = 3; else n = 2; n = decoct(src+12, n, tp, sizeof tmp - (tp - tmp)); if (n == 0) { errno = EMSGSIZE; 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'; if (bits != -1) tp += SPRINTF((tp, "/%u", bits)); /* * Check for overflow, copy, and we're done. */ if ((size_t)(tp - tmp) > size) { errno = EMSGSIZE; return (NULL); } strcpy(dst, tmp); return (dst); } /*! \file */ Index: head/lib/libc/inet/inet_cidr_pton.c =================================================================== --- head/lib/libc/inet/inet_cidr_pton.c (revision 326694) +++ head/lib/libc/inet/inet_cidr_pton.c (revision 326695) @@ -1,278 +1,280 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,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 rcsid[] = "$Id: inet_cidr_pton.c,v 1.6 2005/04/27 04:56:19 sra Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif static int inet_cidr_pton_ipv4 (const char *src, u_char *dst, int *bits, int ipv6); static int inet_cidr_pton_ipv6 (const char *src, u_char *dst, int *bits); static int getbits(const char *, int ipv6); /*% * int * inet_cidr_pton(af, src, dst, *bits) * convert network address from presentation to network format. * accepts inet_pton()'s input for this "af" plus trailing "/CIDR". * "dst" is assumed large enough for its "af". "bits" is set to the * /CIDR prefix length, which can have defaults (like /32 for IPv4). * return: * -1 if an error occurred (inspect errno; ENOENT means bad format). * 0 if successful conversion occurred. * note: * 192.5.5.1/28 has a nonzero host part, which means it isn't a network * as called for by inet_net_pton() but it can be a host address with * an included netmask. * author: * Paul Vixie (ISC), October 1998 */ int inet_cidr_pton(int af, const char *src, void *dst, int *bits) { switch (af) { case AF_INET: return (inet_cidr_pton_ipv4(src, dst, bits, 0)); case AF_INET6: return (inet_cidr_pton_ipv6(src, dst, bits)); default: errno = EAFNOSUPPORT; return (-1); } } static const char digits[] = "0123456789"; static int inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { const u_char *odst = dst; int n, ch, tmp, bits; size_t size = 4; /* Get the mantissa. */ while (ch = *src++, (isascii(ch) && isdigit(ch))) { 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; } /* Get the prefix length if any. */ bits = -1; if (ch == '/' && dst > odst) { bits = getbits(src, ipv6); if (bits == -2) goto enoent; } else if (ch != '\0') goto enoent; /* Prefix length can default to /32 only if all four octets spec'd. */ if (bits == -1) { if (dst - odst == 4) bits = ipv6 ? 128 : 32; else goto enoent; } /* If nothing was written to the destination, we found no address. */ if (dst == odst) goto enoent; /* If prefix length overspecifies mantissa, life is bad. */ if (((bits - (ipv6 ? 96 : 0)) / 8) > (dst - odst)) goto enoent; /* Extend address to four octets. */ while (size-- > 0U) *dst++ = 0; *pbits = bits; return (0); enoent: errno = ENOENT; return (-1); emsgsize: errno = EMSGSIZE; return (-1); } static int inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { 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 bits; 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; bits = -1; 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; } else if (*src == '\0') { return (0); } 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_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { tp += NS_INADDRSZ; saw_xdigit = 0; break; /*%< '\\0' was seen by inet_pton4(). */ } if (ch == '/') { bits = getbits(src, 1); if (bits == -2) goto enoent; break; } goto enoent; } if (saw_xdigit) { if (tp + NS_INT16SZ > endp) goto emsgsize; *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) goto enoent; for (i = 1; i <= n; i++) { endp[- i] = colonp[n - i]; colonp[n - i] = 0; } tp = endp; } memcpy(dst, tmp, NS_IN6ADDRSZ); *pbits = bits; return (0); enoent: errno = ENOENT; return (-1); emsgsize: errno = EMSGSIZE; return (-1); } static int getbits(const char *src, int ipv6) { int bits = 0; char *cp, ch; if (*src == '\0') /*%< syntax */ return (-2); do { ch = *src++; cp = strchr(digits, ch); if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; bits += cp - digits; if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); if (bits > (ipv6 ? 128 : 32)) /*%< range error */ return (-2); } while (*src != '\0'); return (bits); } /*! \file */ Index: head/lib/libc/inet/inet_net_ntop.c =================================================================== --- head/lib/libc/inet/inet_net_ntop.c (revision 326694) +++ head/lib/libc/inet/inet_net_ntop.c (revision 326695) @@ -1,279 +1,281 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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 rcsid[] = "$Id: inet_net_ntop.c,v 1.5 2006/06/20 02:50:14 marka Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif static char * inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size); static char * inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size); /*% * char * * inet_net_ntop(af, src, bits, dst, size) * convert network number from network to presentation format. * generates CIDR style result always. * return: * pointer to dst, or NULL if an error occurred (check errno). * author: * Paul Vixie (ISC), July 1996 */ char * inet_net_ntop(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(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); /*! \file */ Index: head/lib/libc/inet/inet_net_pton.c =================================================================== --- head/lib/libc/inet/inet_net_pton.c (revision 326694) +++ head/lib/libc/inet/inet_net_pton.c (revision 326695) @@ -1,416 +1,418 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1996, 1998, 1999, 2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and/or 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 rcsid[] = "$Id: inet_net_pton.c,v 1.10 2008/11/14 02:36:51 marka Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif /*% * static int * inet_net_pton_ipv4(src, dst, size) * convert IPv4 network number from presentation to network format. * accepts hex octets, hex strings, decimal octets, and /CIDR. * "size" is in bytes and describes "dst". * return: * number of bits, either imputed classfully or specified with /CIDR, * or -1 if some failure occurred (check errno). ENOENT means it was * not an IPv4 network specification. * note: * network byte order assumed. this means 192.5.5.240/28 has * 0b11110000 in its fourth octet. * author: * Paul Vixie (ISC), June 1996 */ static int inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; int n, ch, tmp = 0, dirty, bits; const u_char *odst = dst; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && isascii((unsigned char)(src[1])) && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ if (size <= 0U) goto emsgsize; dirty = 0; src++; /*%< skip x or X. */ while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) { if (isupper(ch)) ch = tolower(ch); n = strchr(xdigits, ch) - xdigits; assert(n >= 0 && n <= 15); if (dirty == 0) tmp = n; else tmp = (tmp << 4) | n; if (++dirty == 2) { if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; dirty = 0; } } if (dirty) { /*%< Odd trailing nybble? */ if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) (tmp << 4); } } else if (isascii(ch) && isdigit(ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; do { n = strchr(digits, ch) - digits; assert(n >= 0 && n <= 9); tmp *= 10; tmp += n; if (tmp > 255) goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') break; if (ch != '.') goto enoent; ch = *src++; if (!isascii(ch) || !isdigit(ch)) goto enoent; } } else goto enoent; bits = -1; if (ch == '/' && isascii((unsigned char)(src[0])) && isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ ch = *src++; /*%< Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; assert(n >= 0 && n <= 9); bits *= 10; bits += n; if (bits > 32) goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); if (ch != '\0') goto enoent; } /* 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); /*! \file */ Index: head/lib/libc/inet/inet_neta.c =================================================================== --- head/lib/libc/inet/inet_neta.c (revision 326694) +++ head/lib/libc/inet/inet_neta.c (revision 326695) @@ -1,95 +1,97 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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 rcsid[] = "$Id: inet_neta.c,v 1.3 2005/04/27 04:56:20 sra Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif /*% * char * * inet_neta(src, dst, size) * format an in_addr_t network number into presentation format. * return: * pointer to dst, or NULL if an error occurred (check errno). * note: * format of ``src'' is as for inet_network(). * author: * Paul Vixie (ISC), July 1996 */ char * inet_neta(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); /*! \file */ Index: head/lib/libc/inet/inet_ntop.c =================================================================== --- head/lib/libc/inet/inet_ntop.c (revision 326694) +++ head/lib/libc/inet/inet_ntop.c (revision 326695) @@ -1,204 +1,206 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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 rcsid[] = "$Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include "port_after.h" /*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size); static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); /* const 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 * 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"; char tmp[sizeof "255.255.255.255"]; int l; l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); if (l <= 0 || (socklen_t) l >= size) { errno = ENOSPC; return (NULL); } strlcpy(dst, tmp, size); 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; best.len = 0; cur.base = -1; cur.len = 0; 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 == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) { errno = ENOSPC; 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); /*! \file */ Index: head/lib/libc/inet/inet_pton.c =================================================================== --- head/lib/libc/inet/inet_pton.c (revision 326694) +++ head/lib/libc/inet/inet_pton.c (revision 326695) @@ -1,224 +1,226 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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 rcsid[] = "$Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include "port_after.h" /*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ static int inet_pton4(const char *src, u_char *dst); static int inet_pton6(const char *src, u_char *dst); /* int * inet_pton(af, src, dst) * convert from presentation format (which usually means ASCII printable) * to network format (which is usually some kind of binary format). * return: * 1 if the address was valid for the specified address family * 0 if the address wasn't valid (`dst' is untouched in this case) * -1 if some other error occurred (`dst' is untouched in this case, too) * author: * Paul Vixie, 1996. */ int inet_pton(int af, const char * __restrict src, void * __restrict dst) { switch (af) { case AF_INET: return (inet_pton4(src, dst)); case AF_INET6: return (inet_pton6(src, dst)); default: errno = EAFNOSUPPORT; return (-1); } /* NOTREACHED */ } /* int * inet_pton4(src, dst) * like inet_aton() but without all the hexadecimal and shorthand. * return: * 1 if `src' is a valid dotted quad, else 0. * notice: * does not touch `dst' unless it's returning 1. * author: * Paul Vixie, 1996. */ static int inet_pton4(const char *src, u_char *dst) { static const char digits[] = "0123456789"; int saw_digit, octets, ch; u_char tmp[NS_INADDRSZ], *tp; saw_digit = 0; octets = 0; *(tp = tmp) = 0; while ((ch = *src++) != '\0') { const char *pch; if ((pch = strchr(digits, ch)) != NULL) { u_int new = *tp * 10 + (pch - digits); if (saw_digit && *tp == 0) return (0); if (new > 255) return (0); *tp = new; if (!saw_digit) { if (++octets > 4) return (0); saw_digit = 1; } } else if (ch == '.' && saw_digit) { if (octets == 4) return (0); *++tp = 0; saw_digit = 0; } else return (0); } if (octets < 4) return (0); memcpy(dst, tmp, NS_INADDRSZ); return (1); } /* int * inet_pton6(src, dst) * convert presentation level address to network order binary form. * return: * 1 if `src' is a valid [RFC1884 2.2] address, else 0. * notice: * (1) does not touch `dst' unless it's returning 1. * (2) :: in a full address is silently ignored. * credit: * inspired by Mark Andrews. * author: * Paul Vixie, 1996. */ static int inet_pton6(const char *src, u_char *dst) { static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; const char *xdigits, *curtok; int ch, seen_xdigits; 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; seen_xdigits = 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 (++seen_xdigits > 4) return (0); continue; } if (ch == ':') { curtok = src; if (!seen_xdigits) { if (colonp) return (0); colonp = tp; continue; } else if (*src == '\0') { return (0); } if (tp + NS_INT16SZ > endp) return (0); *tp++ = (u_char) (val >> 8) & 0xff; *tp++ = (u_char) val & 0xff; seen_xdigits = 0; val = 0; continue; } if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { tp += NS_INADDRSZ; seen_xdigits = 0; break; /*%< '\\0' was seen by inet_pton4(). */ } return (0); } if (seen_xdigits) { 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); /*! \file */ Index: head/lib/libc/inet/nsap_addr.c =================================================================== --- head/lib/libc/inet/nsap_addr.c (revision 326694) +++ head/lib/libc/inet/nsap_addr.c (revision 326695) @@ -1,121 +1,123 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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 rcsid[] = "$Id: nsap_addr.c,v 1.5 2005/07/28 06:51:48 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include "port_after.h" static char xtob(int c) { return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); } u_int inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) { u_char c, nib; u_int len = 0; if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X')) return (0); ascii += 2; 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(int binlen, const u_char *binary, char *ascii) { int nib; int i; char *tmpbuf = inet_nsap_ntoa_tmpbuf; char *start; if (ascii) start = ascii; else { ascii = tmpbuf; start = tmpbuf; } *ascii++ = '0'; *ascii++ = 'x'; 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); /*! \file */ Index: head/lib/libc/nameser/ns_name.c =================================================================== --- head/lib/libc/nameser/ns_name.c (revision 326694) +++ head/lib/libc/nameser/ns_name.c (revision 326695) @@ -1,1156 +1,1158 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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. */ #ifndef lint static const char rcsid[] = "$Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif #define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ #define DNS_LABELTYPE_BITSTRING 0x41 /* Data. */ static const char digits[] = "0123456789"; static const char digitvalue[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/ }; /* 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 *); static int encode_bitsring(const char **, const char *, unsigned char **, unsigned char **, unsigned const char *); static int labellen(const u_char *); static int decode_bitstring(const unsigned char **, char *, const char *); /* Public. */ /*% * Convert an encoded domain name to printable ascii as per RFC1035. * return: *\li Number of bytes written to buffer, or -1 (with errno set) * * notes: *\li The root is returned as "." *\li 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; int l; cp = src; dn = dst; eom = dst + dstsiz; while ((n = *cp++) != 0) { if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Some kind of compression pointer. */ errno = EMSGSIZE; return (-1); } if (dn != dst) { if (dn >= eom) { errno = EMSGSIZE; return (-1); } *dn++ = '.'; } if ((l = labellen(cp - 1)) < 0) { errno = EMSGSIZE; /*%< XXX */ return (-1); } if (dn + l >= eom) { errno = EMSGSIZE; return (-1); } if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) { int m; if (n != DNS_LABELTYPE_BITSTRING) { /* XXX: labellen should reject this case */ errno = EINVAL; return (-1); } if ((m = decode_bitstring(&cp, dn, eom)) < 0) { errno = EMSGSIZE; return (-1); } dn += m; continue; } for ((void)NULL; l > 0; l--) { 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); } /*% * Convert a ascii string into an encoded domain name as per RFC1035. * * return: * *\li -1 if it fails *\li 1 if string was fully qualified *\li 0 is string was not fully qualified * * notes: *\li Enforces label and domain length limits. */ int ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { return (ns_name_pton2(src, dst, dstsiz, NULL)); } /* * ns_name_pton2(src, dst, dstsiz, *dstlen) * Convert a 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 * side effects: * fills in *dstlen (if non-NULL) * notes: * Enforces label and domain length limits. */ int ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { u_char *label, *bp, *eom; int c, n, escaped, e = 0; char *cp; escaped = 0; bp = dst; eom = dst + dstsiz; label = bp++; while ((c = *src++) != 0) { if (escaped) { if (c == '[') { /*%< start a bit string label */ if ((cp = strchr(src, ']')) == NULL) { errno = EINVAL; /*%< ??? */ return (-1); } if ((e = encode_bitsring(&src, cp + 2, &label, &bp, eom)) != 0) { errno = e; return (-1); } escaped = 0; label = bp++; if ((c = *src++) == 0) goto done; else if (c != '.') { errno = EINVAL; return (-1); } continue; } else 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); } if (dstlen != NULL) *dstlen = (bp - dst); return (1); } if (c == 0 || *src == '.') { 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); } done: 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); } if (dstlen != NULL) *dstlen = (bp - dst); return (0); } /*% * Convert a network strings labels into all lowercase. * * return: *\li Number of bytes written to buffer, or -1 (with errno set) * * notes: *\li Enforces label and domain length limits. */ int ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) { const u_char *cp; u_char *dn, *eom; u_char c; u_int n; int l; cp = src; dn = dst; eom = dst + dstsiz; if (dn >= eom) { errno = EMSGSIZE; return (-1); } while ((n = *cp++) != 0) { if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Some kind of compression pointer. */ errno = EMSGSIZE; return (-1); } *dn++ = n; if ((l = labellen(cp - 1)) < 0) { errno = EMSGSIZE; return (-1); } if (dn + l >= eom) { errno = EMSGSIZE; return (-1); } for ((void)NULL; l > 0; l--) { c = *cp++; if (isascii(c) && isupper(c)) *dn++ = tolower(c); else *dn++ = c; } } *dn++ = '\0'; return (dn - dst); } /*% * Unpack a domain name from a message, source may be compressed. * * return: *\li -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) { return (ns_name_unpack2(msg, eom, src, dst, dstsiz, NULL)); } /* * ns_name_unpack2(msg, eom, src, dst, dstsiz, *dstlen) * Unpack a domain name from a message, source may be compressed. * return: * -1 if it fails, or consumed octets if it succeeds. * side effect: * fills in *dstlen (if non-NULL). */ int ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { const u_char *srcp, *dstlim; u_char *dstp; int n, len, checked, l; 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: case NS_TYPE_ELT: /* Limit checks. */ if ((l = labellen(srcp - 1)) < 0) { errno = EMSGSIZE; return (-1); } if (dstp + l + 1 >= dstlim || srcp + l >= eom) { errno = EMSGSIZE; return (-1); } checked += l + 1; *dstp++ = n; memcpy(dstp, srcp, l); dstp += l; srcp += l; break; case NS_CMPRSFLGS: if (srcp >= eom) { errno = EMSGSIZE; return (-1); } if (len < 0) len = srcp - src + 1; l = ((n & 0x3f) << 8) | (*srcp & 0xff); if (l >= eom - msg) { /*%< Out of range. */ errno = EMSGSIZE; return (-1); } srcp = msg + l; 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 (dstlen != NULL) *dstlen = dstp - dst; if (len < 0) len = srcp - src; return (len); } /*% * Pack domain name 'domain' into 'comp_dn'. * * return: *\li Size of the compressed name, or -1. * * notes: *\li 'dnptrs' is an array of pointers to previous compressed names. *\li dnptrs[0] is a pointer to the beginning of the message. The array * ends with NULL. *\li 'lastdnptr' is a pointer to the end of the array pointed to * by 'dnptrs'. * * Side effects: *\li 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, first = 1; 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 { int l0; n = *srcp; if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { errno = EMSGSIZE; return (-1); } if ((l0 = labellen(srcp)) < 0) { errno = EINVAL; return (-1); } l += l0 + 1; if (l > MAXCDNAME) { errno = EMSGSIZE; return (-1); } srcp += l0 + 1; } while (n != 0); /* from here on we need to reset compression pointer array on error */ 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) { goto cleanup; } *dstp++ = (l >> 8) | NS_CMPRSFLGS; *dstp++ = l % 256; return (dstp - dst); } /* Not found, save it. */ if (lastdnptr != NULL && cpp < lastdnptr - 1 && (dstp - msg) < 0x4000 && first) { *cpp++ = dstp; *cpp = NULL; first = 0; } } /* copy label to buffer */ if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Should not happen. */ goto cleanup; } n = labellen(srcp); if (dstp + 1 + n >= eob) { goto cleanup; } memcpy(dstp, srcp, n + 1); srcp += n + 1; dstp += n + 1; } while (n != 0); if (dstp > eob) { cleanup: if (msg != NULL) *lpp = NULL; errno = EMSGSIZE; return (-1); } return (dstp - dst); } /*% * Expand compressed domain name to presentation format. * * return: *\li Number of bytes read out of `src', or -1 (with errno set). * * note: *\li 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); } /*% * Compress a domain name into wire format, using compression pointers. * * return: *\li Number of bytes consumed in `dst' or -1 (with errno set). * * notes: *\li 'dnptrs' is an array of pointers to previous compressed names. *\li dnptrs[0] is a pointer to the beginning of the message. *\li 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. *\li 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)); } /*% * Reset dnptrs so that there are no active references to pointers at or * after src. */ void ns_name_rollback(const u_char *src, const u_char **dnptrs, const u_char **lastdnptr) { while (dnptrs < lastdnptr && *dnptrs != NULL) { if (*dnptrs >= src) { *dnptrs = NULL; break; } dnptrs++; } } /*% * Advance *ptrptr to skip over the compressed name it points at. * * return: *\li 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; int l; 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_TYPE_ELT: /*%< EDNS0 extended label */ if ((l = labellen(cp - 1)) < 0) { errno = EMSGSIZE; /*%< XXX */ return (-1); } cp += l; 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); } /* Find the number of octets an nname takes up, including the root label. * (This is basically ns_name_skip() without compression-pointer support.) * ((NOTE: can only return zero if passed-in namesiz argument is zero.)) */ ssize_t ns_name_length(ns_nname_ct nname, size_t namesiz) { ns_nname_ct orig = nname; u_int n; while (namesiz-- > 0 && (n = *nname++) != 0) { if ((n & NS_CMPRSFLGS) != 0) { errno = EISDIR; return (-1); } if (n > namesiz) { errno = EMSGSIZE; return (-1); } nname += n; namesiz -= n; } return (nname - orig); } /* Compare two nname's for equality. Return -1 on error (setting errno). */ int ns_name_eq(ns_nname_ct a, size_t as, ns_nname_ct b, size_t bs) { ns_nname_ct ae = a + as, be = b + bs; int ac, bc; while (ac = *a, bc = *b, ac != 0 && bc != 0) { if ((ac & NS_CMPRSFLGS) != 0 || (bc & NS_CMPRSFLGS) != 0) { errno = EISDIR; return (-1); } if (a + ac >= ae || b + bc >= be) { errno = EMSGSIZE; return (-1); } if (ac != bc || strncasecmp((const char *) ++a, (const char *) ++b, ac) != 0) return (0); a += ac, b += bc; } return (ac == 0 && bc == 0); } /* Is domain "A" owned by (at or below) domain "B"? */ int ns_name_owned(ns_namemap_ct a, int an, ns_namemap_ct b, int bn) { /* If A is shorter, it cannot be owned by B. */ if (an < bn) return (0); /* If they are unequal before the length of the shorter, A cannot... */ while (bn > 0) { if (a->len != b->len || strncasecmp((const char *) a->base, (const char *) b->base, a->len) != 0) return (0); a++, an--; b++, bn--; } /* A might be longer or not, but either way, B owns it. */ return (1); } /* Build an array of tuples from an nname, top-down order. * Return the number of tuples (labels) thus discovered. */ int ns_name_map(ns_nname_ct nname, size_t namelen, ns_namemap_t map, int mapsize) { u_int n; int l; n = *nname++; namelen--; /* Root zone? */ if (n == 0) { /* Extra data follows name? */ if (namelen > 0) { errno = EMSGSIZE; return (-1); } return (0); } /* Compression pointer? */ if ((n & NS_CMPRSFLGS) != 0) { errno = EISDIR; return (-1); } /* Label too long? */ if (n > namelen) { errno = EMSGSIZE; return (-1); } /* Recurse to get rest of name done first. */ l = ns_name_map(nname + n, namelen - n, map, mapsize); if (l < 0) return (-1); /* Too many labels? */ if (l >= mapsize) { errno = ENAMETOOLONG; return (-1); } /* We're on our way back up-stack, store current map data. */ map[l].base = nname; map[l].len = n; return (l + 1); } /* Count the labels in a domain name. Root counts, so COM. has two. This * is to make the result comparable to the result of ns_name_map(). */ int ns_name_labels(ns_nname_ct nname, size_t namesiz) { int ret = 0; u_int n; while (namesiz-- > 0 && (n = *nname++) != 0) { if ((n & NS_CMPRSFLGS) != 0) { errno = EISDIR; return (-1); } if (n > namesiz) { errno = EMSGSIZE; return (-1); } nname += n; namesiz -= n; ret++; } return (ret + 1); } /* Private. */ /*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this characted special ("in need of quoting") ? * * return: *\li boolean. */ static int special(int ch) { switch (ch) { case 0x22: /*%< '"' */ case 0x2E: /*%< '.' */ case 0x3B: /*%< ';' */ case 0x5C: /*%< '\\' */ case 0x28: /*%< '(' */ case 0x29: /*%< ')' */ /* Special modifiers in zone files. */ case 0x40: /*%< '@' */ case 0x24: /*%< '$' */ return (1); default: return (0); } } /*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this character visible and not a space when printed ? * * return: *\li 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); } /*% * Search for the counted-label name in an array of compressed names. * * return: *\li offset from msg if found, or -1. * * notes: *\li dnptrs is the pointer to the first name on the list, *\li 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++) { sp = *cpp; /* * terminate search on: * root label * compression pointer * unusable offset */ while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 && (sp - msg) < 0x4000) { dn = domain; cp = sp; while ((n = *cp++) != 0) { /* * check for indirection */ switch (n & NS_CMPRSFLGS) { case 0: /*%< normal case, n == len */ n = labellen(cp - 1); /*%< XXX */ 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: ; sp += *sp + 1; } } errno = ENOENT; return (-1); } static int decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) { const unsigned char *cp = *cpp; char *beg = dn, tc; int b, blen, plen, i; if ((blen = (*cp & 0xff)) == 0) blen = 256; plen = (blen + 3) / 4; plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); if (dn + plen >= eom) return (-1); cp++; i = SPRINTF((dn, "\\[x")); if (i < 0) return (-1); dn += i; for (b = blen; b > 7; b -= 8, cp++) { i = SPRINTF((dn, "%02x", *cp & 0xff)); if (i < 0) return (-1); dn += i; } if (b > 4) { tc = *cp++; i = SPRINTF((dn, "%02x", tc & (0xff << (8 - b)))); if (i < 0) return (-1); dn += i; } else if (b > 0) { tc = *cp++; i = SPRINTF((dn, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); if (i < 0) return (-1); dn += i; } i = SPRINTF((dn, "/%d]", blen)); if (i < 0) return (-1); dn += i; *cpp = cp; return (dn - beg); } static int encode_bitsring(const char **bp, const char *end, unsigned char **labelp, unsigned char ** dst, unsigned const char *eom) { int afterslash = 0; const char *cp = *bp; unsigned char *tp; char c; const char *beg_blen; char *end_blen = NULL; int value = 0, count = 0, tbcount = 0, blen = 0; beg_blen = end_blen = NULL; /* a bitstring must contain at least 2 characters */ if (end - cp < 2) return (EINVAL); /* XXX: currently, only hex strings are supported */ if (*cp++ != 'x') return (EINVAL); if (!isxdigit((*cp) & 0xff)) /*%< reject '\[x/BLEN]' */ return (EINVAL); for (tp = *dst + 1; cp < end && tp < eom; cp++) { switch((c = *cp)) { case ']': /*%< end of the bitstring */ if (afterslash) { if (beg_blen == NULL) return (EINVAL); blen = (int)strtol(beg_blen, &end_blen, 10); if (*end_blen != ']') return (EINVAL); } if (count) *tp++ = ((value << 4) & 0xff); cp++; /*%< skip ']' */ goto done; case '/': afterslash = 1; break; default: if (afterslash) { if (!isdigit(c&0xff)) return (EINVAL); if (beg_blen == NULL) { if (c == '0') { /* blen never begings with 0 */ return (EINVAL); } beg_blen = cp; } } else { if (!isxdigit(c&0xff)) return (EINVAL); value <<= 4; value += digitvalue[(int)c]; count += 4; tbcount += 4; if (tbcount > 256) return (EINVAL); if (count == 8) { *tp++ = value; count = 0; } } break; } } done: if (cp >= end || tp >= eom) return (EMSGSIZE); /* * bit length validation: * If a is present, the number of digits in the * MUST be just sufficient to contain the number of bits specified * by the . If there are insignificant bits in a final * hexadecimal or octal digit, they MUST be zero. * RFC2673, Section 3.2. */ if (blen > 0) { int traillen; if (((blen + 3) & ~3) != tbcount) return (EINVAL); traillen = tbcount - blen; /*%< between 0 and 3 */ if (((value << (8 - traillen)) & 0xff) != 0) return (EINVAL); } else blen = tbcount; if (blen == 256) blen = 0; /* encode the type and the significant bit fields */ **labelp = DNS_LABELTYPE_BITSTRING; **dst = blen; *bp = cp; *dst = tp; return (0); } static int labellen(const u_char *lp) { int bitlen; u_char l = *lp; if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* should be avoided by the caller */ return (-1); } if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) { if (l == DNS_LABELTYPE_BITSTRING) { if ((bitlen = *(lp + 1)) == 0) bitlen = 256; return ((bitlen + 7 ) / 8 + 1); } return (-1); /*%< unknwon ELT */ } return (l); } /*! \file */ Index: head/lib/libc/nameser/ns_netint.c =================================================================== --- head/lib/libc/nameser/ns_netint.c (revision 326694) +++ head/lib/libc/nameser/ns_netint.c (revision 326695) @@ -1,60 +1,62 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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. */ #ifndef lint static const char rcsid[] = "$Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp $"; #endif #include __FBSDID("$FreeBSD$"); /* Import. */ #include "port_before.h" #include #include "port_after.h" /* Public. */ 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); } /*! \file */ Index: head/lib/libc/nameser/ns_parse.c =================================================================== --- head/lib/libc/nameser/ns_parse.c (revision 326694) +++ head/lib/libc/nameser/ns_parse.c (revision 326695) @@ -1,277 +1,279 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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. */ #ifndef lint static const char rcsid[] = "$Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp $"; #endif #include __FBSDID("$FreeBSD$"); /* Import. */ #include "port_before.h" #include #include #include #include #include #include #include "port_after.h" /* Forward. */ static void setsection(ns_msg *msg, ns_sect sect); /* Macros. */ #if !defined(SOLARIS2) || defined(__COVERITY__) #define RETERR(err) do { errno = (err); return (-1); } while (0) #else #define RETERR(err) \ do { errno = (err); if (errno == errno) return (-1); } while (0) #endif #define PARSE_FMT_PRESO 0 /* Parse using presentation-format names */ #define PARSE_FMT_WIRE 1 /* Parse using network-format names */ /* Public. */ /* 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). */ }; int ns_msg_getflag(ns_msg handle, int flag) { return(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift); } int ns_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) RETERR(EMSGSIZE); ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/; if (section != ns_s_qd) { if (ptr + NS_INT32SZ + NS_INT16SZ > eom) RETERR(EMSGSIZE); ptr += NS_INT32SZ/*TTL*/; NS_GET16(rdlength, ptr); ptr += rdlength/*RData*/; } } if (ptr > eom) RETERR(EMSGSIZE); return (ptr - optr); } int ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { const u_char *eom = msg + msglen; int i; handle->_msg = msg; handle->_eom = eom; if (msg + NS_INT16SZ > eom) RETERR(EMSGSIZE); NS_GET16(handle->_id, msg); if (msg + NS_INT16SZ > eom) RETERR(EMSGSIZE); NS_GET16(handle->_flags, msg); for (i = 0; i < ns_s_max; i++) { if (msg + NS_INT16SZ > eom) RETERR(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 = ns_skiprr(msg, eom, (ns_sect)i, handle->_counts[i]); if (b < 0) return (-1); handle->_sections[i] = msg; msg += b; } if (msg != eom) RETERR(EMSGSIZE); setsection(handle, ns_s_max); return (0); } int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { int b; int tmp; /* Make section right. */ tmp = section; if (tmp < 0 || section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); /* Make rrnum right. */ if (rrnum == -1) rrnum = handle->_rrnum; if (rrnum < 0 || rrnum >= handle->_counts[(int)section]) RETERR(ENODEV); if (rrnum < handle->_rrnum) setsection(handle, section); if (rrnum > handle->_rrnum) { b = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); if (b < 0) return (-1); handle->_msg_ptr += b; handle->_rrnum = rrnum; } /* Do the parse. */ b = dn_expand(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); if (b < 0) return (-1); handle->_msg_ptr += b; if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); NS_GET16(rr->type, handle->_msg_ptr); NS_GET16(rr->rr_class, handle->_msg_ptr); if (section == ns_s_qd) { rr->ttl = 0; rr->rdlength = 0; rr->rdata = NULL; } else { if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); NS_GET32(rr->ttl, handle->_msg_ptr); NS_GET16(rr->rdlength, handle->_msg_ptr); if (handle->_msg_ptr + rr->rdlength > handle->_eom) RETERR(EMSGSIZE); rr->rdata = handle->_msg_ptr; handle->_msg_ptr += rr->rdlength; } if (++handle->_rrnum > handle->_counts[(int)section]) setsection(handle, (ns_sect)((int)section + 1)); /* All done. */ return (0); } /* * This is identical to the above but uses network-format (uncompressed) names. */ int ns_parserr2(ns_msg *handle, ns_sect section, int rrnum, ns_rr2 *rr) { int b; int tmp; /* Make section right. */ if ((tmp = section) < 0 || section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); /* Make rrnum right. */ if (rrnum == -1) rrnum = handle->_rrnum; if (rrnum < 0 || rrnum >= handle->_counts[(int)section]) RETERR(ENODEV); if (rrnum < handle->_rrnum) setsection(handle, section); if (rrnum > handle->_rrnum) { b = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); if (b < 0) return (-1); handle->_msg_ptr += b; handle->_rrnum = rrnum; } /* Do the parse. */ b = ns_name_unpack2(handle->_msg, handle->_eom, handle->_msg_ptr, rr->nname, NS_MAXNNAME, &rr->nnamel); if (b < 0) return (-1); handle->_msg_ptr += b; if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); NS_GET16(rr->type, handle->_msg_ptr); NS_GET16(rr->rr_class, handle->_msg_ptr); if (section == ns_s_qd) { rr->ttl = 0; rr->rdlength = 0; rr->rdata = NULL; } else { if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); NS_GET32(rr->ttl, handle->_msg_ptr); NS_GET16(rr->rdlength, handle->_msg_ptr); if (handle->_msg_ptr + rr->rdlength > handle->_eom) RETERR(EMSGSIZE); rr->rdata = handle->_msg_ptr; handle->_msg_ptr += rr->rdlength; } if (++handle->_rrnum > handle->_counts[(int)section]) setsection(handle, (ns_sect)((int)section + 1)); /* All done. */ return (0); } /* Private. */ static void setsection(ns_msg *msg, ns_sect sect) { msg->_sect = sect; if (sect == ns_s_max) { msg->_rrnum = -1; msg->_msg_ptr = NULL; } else { msg->_rrnum = 0; msg->_msg_ptr = msg->_sections[(int)sect]; } } /*! \file */ Index: head/lib/libc/nameser/ns_print.c =================================================================== --- head/lib/libc/nameser/ns_print.c (revision 326694) +++ head/lib/libc/nameser/ns_print.c (revision 326695) @@ -1,1254 +1,1256 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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. */ #ifndef lint static const char rcsid[] = "$Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp $"; #endif #include __FBSDID("$FreeBSD$"); /* Import. */ #include "port_before.h" #include #include #include #include #include #ifdef _LIBC #include #define INSIST(cond) assert(cond) #else #include #include #endif #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif /* 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) static const char base32hex[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv"; /* Public. */ /*% * Convert an RR to presentation format. * * return: *\li 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); } /*% * Convert the fields of an RR into presentation format. * * return: *\li 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 && ns_samename(name_ctx, name) == 1) { T(addstr("\t\t\t", 3, &buf, &buflen)); } else { len = prune_origin(name, origin); if (*name == '\0') { goto root; } else if (len == 0) { T(addstr("@\t\t\t", 4, &buf, &buflen)); } else { T(addstr(name, len, &buf, &buflen)); /* Origin not used or not root, and no trailing dot? */ if (((origin == NULL || origin[0] == '\0') || (origin[0] != '.' && origin[1] != '\0' && name[len] == '\0')) && name[len - 1] != '.') { root: 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 != (size_t)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: case ns_t_dname: 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, optional in ISDN records. */ if (type == ns_t_isdn && rdata == edata) break; 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: case ns_t_kx: { u_int t; if (rdlen < (size_t)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 < (size_t)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: case ns_t_spf: 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[2+255*3]; (void) inet_nsap_ntoa(rdlen, rdata, t); T(addstr(t, strlen(t), &buf, &buflen)); break; } case ns_t_aaaa: if (rdlen != (size_t)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 < 2U*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 < 3U*NS_INT16SZ) 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 < 1U + NS_INT32SZ) 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: case ns_t_dnskey: { char base64_key[NS_MD5RSA_MAX_BASE64]; u_int keyflags, protocol, algorithm, key_id; const char *leader; int n; if (rdlen < 0U + NS_INT16SZ + NS_INT8SZ + NS_INT8SZ) goto formerr; /* Key flags, Protocol, Algorithm. */ #ifndef _LIBC key_id = dst_s_dns_key_id(rdata, edata-rdata); #else key_id = 0; #endif 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)); n = SPRINTF((tmp, " ; key_tag= %u", key_id)); T(addstr(tmp, n, &buf, &buflen)); break; } case ns_t_sig: case ns_t_rrsig: { char base64_key[NS_MD5RSA_MAX_BASE64]; u_int type, algorithm, labels, footprint; const char *leader; u_long t; int n; if (rdlen < 22U) 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 %d %lu ", p_type(type), algorithm, labels, 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; } case ns_t_cert: { u_int c_type, key_tag, alg; int n; unsigned int siz; char base64_cert[8192], tmp[40]; const char *leader; c_type = ns_get16(rdata); rdata += NS_INT16SZ; key_tag = ns_get16(rdata); rdata += NS_INT16SZ; alg = (u_int) *rdata++; len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg)); T(addstr(tmp, len, &buf, &buflen)); siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_cert) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { len = b64_ntop(rdata, edata-rdata, base64_cert, siz); if (len < 0) goto formerr; else 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_cert + n, MIN(len - n, 48), &buf, &buflen)); } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); } break; } case ns_t_tkey: { /* KJD - need to complete this */ u_long t; int mode, err, keysize; /* Algorithm name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); T(addstr(" ", 1, &buf, &buflen)); /* Inception. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); T(addstr(tmp, len, &buf, &buflen)); /* Experation. */ t = ns_get32(rdata); rdata += NS_INT32SZ; len = SPRINTF((tmp, "%s ", p_secstodate(t))); T(addstr(tmp, len, &buf, &buflen)); /* Mode , Error, Key Size. */ /* Priority, Weight, Port. */ mode = ns_get16(rdata); rdata += NS_INT16SZ; err = ns_get16(rdata); rdata += NS_INT16SZ; keysize = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize)); T(addstr(tmp, len, &buf, &buflen)); /* XXX need to dump key, print otherdata length & other data */ break; } case ns_t_tsig: { /* BEW - need to complete this */ int n; T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen)); T(addstr(" ", 1, &buf, &buflen)); rdata += 8; /*%< time */ n = ns_get16(rdata); rdata += INT16SZ; rdata += n; /*%< sig */ n = ns_get16(rdata); rdata += INT16SZ; /*%< original id */ sprintf(buf, "%d", ns_get16(rdata)); rdata += INT16SZ; addlen(strlen(buf), &buf, &buflen); break; } case ns_t_a6: { struct in6_addr a; int pbyte, pbit; /* prefix length */ if (rdlen == 0U) goto formerr; len = SPRINTF((tmp, "%d ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); pbit = *rdata; if (pbit > 128) goto formerr; pbyte = (pbit & ~7) / 8; rdata++; /* address suffix: provided only when prefix len != 128 */ if (pbit < 128) { if (rdata + pbyte >= edata) goto formerr; memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte); (void) inet_ntop(AF_INET6, &a, buf, buflen); addlen(strlen(buf), &buf, &buflen); rdata += sizeof(a) - pbyte; } /* prefix name: provided only when prefix len > 0 */ if (pbit == 0) break; if (rdata >= edata) goto formerr; T(addstr(" ", 1, &buf, &buflen)); T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); break; } case ns_t_opt: { len = SPRINTF((tmp, "%u bytes", class)); T(addstr(tmp, len, &buf, &buflen)); break; } case ns_t_ds: case ns_t_dlv: case ns_t_sshfp: { u_int t; if (type == ns_t_ds || type == ns_t_dlv) { if (rdlen < 4U) goto formerr; t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); T(addstr(tmp, len, &buf, &buflen)); } else if (rdlen < 2U) goto formerr; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; while (rdata < edata) { len = SPRINTF((tmp, "%02X", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; } break; } case ns_t_nsec3: case ns_t_nsec3param: { u_int t, w, l, j, k, c; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; t = ns_get16(rdata); rdata += NS_INT16SZ; len = SPRINTF((tmp, "%u ", t)); T(addstr(tmp, len, &buf, &buflen)); t = *rdata++; if (t == 0) { T(addstr("-", 1, &buf, &buflen)); } else { while (t-- > 0) { len = SPRINTF((tmp, "%02X", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; } } if (type == ns_t_nsec3param) break; T(addstr(" ", 1, &buf, &buflen)); t = *rdata++; while (t > 0) { switch (t) { case 1: tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; tmp[1] = base32hex[((rdata[0]<<2)&0x1c)]; tmp[2] = tmp[3] = tmp[4] = '='; tmp[5] = tmp[6] = tmp[7] = '='; break; case 2: tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| ((rdata[1]>>6)&0x03)]; tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; tmp[3] = base32hex[((rdata[1]<<4)&0x10)]; tmp[4] = tmp[5] = tmp[6] = tmp[7] = '='; break; case 3: tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| ((rdata[1]>>6)&0x03)]; tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; tmp[3] = base32hex[((rdata[1]<<4)&0x10)| ((rdata[2]>>4)&0x0f)]; tmp[4] = base32hex[((rdata[2]<<1)&0x1e)]; tmp[5] = tmp[6] = tmp[7] = '='; break; case 4: tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| ((rdata[1]>>6)&0x03)]; tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; tmp[3] = base32hex[((rdata[1]<<4)&0x10)| ((rdata[2]>>4)&0x0f)]; tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| ((rdata[3]>>7)&0x01)]; tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; tmp[6] = base32hex[(rdata[3]<<3)&0x18]; tmp[7] = '='; break; default: tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| ((rdata[1]>>6)&0x03)]; tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; tmp[3] = base32hex[((rdata[1]<<4)&0x10)| ((rdata[2]>>4)&0x0f)]; tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| ((rdata[3]>>7)&0x01)]; tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; tmp[6] = base32hex[((rdata[3]<<3)&0x18)| ((rdata[4]>>5)&0x07)]; tmp[7] = base32hex[(rdata[4]&0x1f)]; break; } T(addstr(tmp, 8, &buf, &buflen)); if (t >= 5) { rdata += 5; t -= 5; } else { rdata += t; t -= t; } } while (rdata < edata) { w = *rdata++; l = *rdata++; for (j = 0; j < l; j++) { if (rdata[j] == 0) continue; for (k = 0; k < 8; k++) { if ((rdata[j] & (0x80 >> k)) == 0) continue; c = w * 256 + j * 8 + k; len = SPRINTF((tmp, " %s", p_type(c))); T(addstr(tmp, len, &buf, &buflen)); } } rdata += l; } break; } case ns_t_nsec: { u_int w, l, j, k, c; T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); while (rdata < edata) { w = *rdata++; l = *rdata++; for (j = 0; j < l; j++) { if (rdata[j] == 0) continue; for (k = 0; k < 8; k++) { if ((rdata[j] & (0x80 >> k)) == 0) continue; c = w * 256 + j * 8 + k; len = SPRINTF((tmp, " %s", p_type(c))); T(addstr(tmp, len, &buf, &buflen)); } } rdata += l; } break; } case ns_t_dhcid: { int n; unsigned int siz; char base64_dhcid[8192]; const char *leader; siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_dhcid) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { len = b64_ntop(rdata, edata-rdata, base64_dhcid, siz); if (len < 0) goto formerr; else 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_dhcid + n, MIN(len - n, 48), &buf, &buflen)); } if (len > 15) T(addstr(" )", 2, &buf, &buflen)); } break; } case ns_t_ipseckey: { int n; unsigned int siz; char base64_key[8192]; const char *leader; if (rdlen < 2) goto formerr; switch (rdata[1]) { case 0: case 3: if (rdlen < 3) goto formerr; break; case 1: if (rdlen < 7) goto formerr; break; case 2: if (rdlen < 19) goto formerr; break; default: comment = "unknown IPSECKEY gateway type"; goto hexify; } len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; len = SPRINTF((tmp, "%u ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); rdata++; switch (rdata[-2]) { case 0: T(addstr(".", 1, &buf, &buflen)); break; case 1: (void) inet_ntop(AF_INET, rdata, buf, buflen); addlen(strlen(buf), &buf, &buflen); rdata += 4; break; case 2: (void) inet_ntop(AF_INET6, rdata, buf, buflen); addlen(strlen(buf), &buf, &buflen); rdata += 16; break; case 3: T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); break; } if (rdata >= edata) break; siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_key) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { len = b64_ntop(rdata, edata-rdata, base64_key, siz); if (len < 0) goto formerr; else 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)); } } case ns_t_hip: { unsigned int i, hip_len, algorithm, key_len; char base64_key[NS_MD5RSA_MAX_BASE64]; unsigned int siz; const char *leader = "\n\t\t\t\t\t"; hip_len = *rdata++; algorithm = *rdata++; key_len = ns_get16(rdata); rdata += NS_INT16SZ; siz = key_len*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_key) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { len = sprintf(tmp, "( %u ", algorithm); T(addstr(tmp, len, &buf, &buflen)); for (i = 0; i < hip_len; i++) { len = sprintf(tmp, "%02X", *rdata); T(addstr(tmp, len, &buf, &buflen)); rdata++; } T(addstr(leader, strlen(leader), &buf, &buflen)); len = b64_ntop(rdata, key_len, base64_key, siz); if (len < 0) goto formerr; T(addstr(base64_key, len, &buf, &buflen)); rdata += key_len; while (rdata < edata) { T(addstr(leader, strlen(leader), &buf, &buflen)); T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); } T(addstr(" )", 2, &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, "\\# %u%s\t; %s", (unsigned)(edata - rdata), rdlen != 0U ? " (" : "", 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 && ns_samename(name, origin) == 1) 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 (**buf == '\0') { goto root; } else if (newlen == 0U) { /* Use "@" instead of name. */ if (newlen + 2 > *buflen) goto enospc; /* No room for "@\0". */ (*buf)[newlen++] = '@'; (*buf)[newlen] = '\0'; } else { if (((origin == NULL || origin[0] == '\0') || (origin[0] != '.' && origin[1] != '\0' && (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') { /* No trailing dot. */ root: 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) { INSIST(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); } /*! \file */ Index: head/lib/libc/nameser/ns_samedomain.c =================================================================== --- head/lib/libc/nameser/ns_samedomain.c (revision 326694) +++ head/lib/libc/nameser/ns_samedomain.c (revision 326695) @@ -1,211 +1,213 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995,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. */ #ifndef lint static const char rcsid[] = "$Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp $"; #endif #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include "port_after.h" /*% * Check whether a name belongs to a domain. * * Inputs: *\li a - the domain whose ancestry is being verified *\li b - the potential ancestor we're checking against * * Return: *\li boolean - is a at or below b? * * Notes: *\li Trailing dots are first removed from name and domain. * Always compare complete subdomains, not only whether the * domain name is the trailing string of the given name. * *\li "host.foobar.top" lies in "foobar.top" and in "top" and in "" * but NOT in "bar.top" */ int ns_samedomain(const char *a, const char *b) { size_t la, lb; int diff, i, escaped; const char *cp; la = strlen(a); lb = strlen(b); /* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */ if (la != 0U && a[la - 1] == '.') { escaped = 0; /* Note this loop doesn't get executed if la==1. */ for (i = la - 2; i >= 0; i--) if (a[i] == '\\') { if (escaped) escaped = 0; else escaped = 1; } else break; if (!escaped) la--; } /* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */ if (lb != 0U && b[lb - 1] == '.') { escaped = 0; /* note this loop doesn't get executed if lb==1 */ for (i = lb - 2; i >= 0; i--) if (b[i] == '\\') { if (escaped) escaped = 0; else escaped = 1; } else break; if (!escaped) lb--; } /* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */ if (lb == 0U) return (1); /* 'b' longer than 'a' means 'a' can't be in 'b'. */ if (lb > la) return (0); /* 'a' and 'b' being equal at this point indicates sameness. */ if (lb == la) return (strncasecmp(a, b, lb) == 0); /* Ok, we know la > lb. */ diff = la - lb; /* * If 'a' is only 1 character longer than 'b', then it can't be * a subdomain of 'b' (because of the need for the '.' label * separator). */ if (diff < 2) return (0); /* * If the character before the last 'lb' characters of 'b' * isn't '.', then it can't be a match (this lets us avoid * having "foobar.com" match "bar.com"). */ if (a[diff - 1] != '.') return (0); /* * We're not sure about that '.', however. It could be escaped * and thus not a really a label separator. */ escaped = 0; for (i = diff - 2; i >= 0; i--) if (a[i] == '\\') { if (escaped) escaped = 0; else escaped = 1; } else break; if (escaped) return (0); /* Now compare aligned trailing substring. */ cp = a + diff; return (strncasecmp(cp, b, lb) == 0); } #ifndef _LIBC /*% * is "a" a subdomain of "b"? */ int ns_subdomain(const char *a, const char *b) { return (ns_samename(a, b) != 1 && ns_samedomain(a, b)); } #endif /*% * make a canonical copy of domain name "src" * * notes: * \code * foo -> foo. * foo. -> foo. * foo.. -> foo. * foo\. -> foo\.. * foo\\. -> foo\\. * \endcode */ int ns_makecanon(const char *src, char *dst, size_t dstsize) { size_t n = strlen(src); if (n + sizeof "." > dstsize) { /*%< Note: sizeof == 2 */ errno = EMSGSIZE; return (-1); } strcpy(dst, src); while (n >= 1U && dst[n - 1] == '.') /*%< Ends in "." */ if (n >= 2U && dst[n - 2] == '\\' && /*%< Ends in "\." */ (n < 3U || dst[n - 3] != '\\')) /*%< But not "\\." */ break; else dst[--n] = '\0'; dst[n++] = '.'; dst[n] = '\0'; return (0); } /*% * determine whether domain name "a" is the same as domain name "b" * * return: *\li -1 on error *\li 0 if names differ *\li 1 if names are the same */ int ns_samename(const char *a, const char *b) { char ta[NS_MAXDNAME], tb[NS_MAXDNAME]; if (ns_makecanon(a, ta, sizeof ta) < 0 || ns_makecanon(b, tb, sizeof tb) < 0) return (-1); if (strcasecmp(ta, tb) == 0) return (1); else return (0); } /*! \file */ Index: head/lib/libc/nameser/ns_ttl.c =================================================================== --- head/lib/libc/nameser/ns_ttl.c (revision 326694) +++ head/lib/libc/nameser/ns_ttl.c (revision 326695) @@ -1,164 +1,166 @@ -/* +/*- + * SPDX-License-Identifier: ISC + * * 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. */ #ifndef lint static const char rcsid[] = "$Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp $"; #endif #include __FBSDID("$FreeBSD$"); /* Import. */ #include "port_before.h" #include #include #include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif /* 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; } else if (!dirty) goto einval; *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); } /*! \file */ Index: head/lib/libc/resolv/herror.c =================================================================== --- head/lib/libc/resolv/herror.c (revision 326694) +++ head/lib/libc/resolv/herror.c (revision 326695) @@ -1,127 +1,127 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) * * 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. 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. */ /* * 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 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 sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "$Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include "namespace.h" #include #include #include #include #include #include #include #include #include "un-namespace.h" #include "port_after.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 = { nitems(h_errlist) }; #undef h_errno int h_errno; /*% * herror -- * print the error indicated by the h_errno value. */ void herror(const char *s) { struct iovec iov[4], *v = iov; char *t; if (s != NULL && *s != '\0') { DE_CONST(s, t); v->iov_base = t; v->iov_len = strlen(t); v++; DE_CONST(": ", t); v->iov_base = t; v->iov_len = 2; v++; } DE_CONST(hstrerror(*__h_errno()), t); v->iov_base = t; v->iov_len = strlen(v->iov_base); v++; DE_CONST("\n", t); v->iov_base = t; v->iov_len = 1; _writev(STDERR_FILENO, iov, (v - iov) + 1); } /*% * hstrerror -- * return the string associated with a given "host" errno value. */ const char * hstrerror(int err) { if (err < 0) return ("Resolver internal error"); else if (err < h_nerr) return (h_errlist[err]); return ("Unknown resolver error"); } /*! \file */ Index: head/lib/libc/resolv/res_comp.c =================================================================== --- head/lib/libc/resolv/res_comp.c (revision 326694) +++ head/lib/libc/resolv/res_comp.c (revision 326695) @@ -1,278 +1,278 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-3-Clause AND ISC) * * 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. 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 (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 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 sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "$Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include "port_before.h" #include #include #include #include #include #include #include #include #include "port_after.h" /*% * Expand compressed domain name 'src' to full domain name. * * \li 'msg' is a pointer to the beginning of the message, * \li 'eom' points to the first location after the message, * \li 'dst' is a pointer to a buffer of size 'dstsiz' for the result. * \li 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'. * * \li Return the size of the compressed name or -1. * \li '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 underscorechar(c) ((c) == 0x5f) #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) #ifdef RES_ENFORCE_RFC1034 #define borderchar(c) (alphachar(c) || digitchar(c)) #else #define borderchar(c) (alphachar(c) || digitchar(c) || underscorechar(c)) #endif #define middlechar(c) (borderchar(c) || hyphenchar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int res_hnok(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(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(const char *dn) { int ch, escaped = 0; /* "." is a valid missing representation */ if (*dn == '\0') return (1); /* otherwise