michael@0: /* $NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $ */ michael@0: michael@0: /* michael@0: * Copyright (c) 1985 michael@0: * The Regents of the University of California. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * 3. All advertising materials mentioning features or use of this software michael@0: * must display the following acknowledgement: michael@0: * This product includes software developed by the University of michael@0: * California, Berkeley and its contributors. michael@0: * 4. Neither the name of the University nor the names of its contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND michael@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT michael@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY michael@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: * SUCH DAMAGE. michael@0: */ michael@0: michael@0: /* michael@0: * Portions Copyright (c) 1993 by Digital Equipment Corporation. michael@0: * michael@0: * Permission to use, copy, modify, and distribute this software for any michael@0: * purpose with or without fee is hereby granted, provided that the above michael@0: * copyright notice and this permission notice appear in all copies, and that michael@0: * the name of Digital Equipment Corporation not be used in advertising or michael@0: * publicity pertaining to distribution of the document or software without michael@0: * specific, written prior permission. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL michael@0: * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES michael@0: * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT michael@0: * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL michael@0: * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR michael@0: * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS michael@0: * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS michael@0: * SOFTWARE. michael@0: */ michael@0: michael@0: /* michael@0: * Portions Copyright (c) 1995 by International Business Machines, Inc. michael@0: * michael@0: * International Business Machines, Inc. (hereinafter called IBM) grants michael@0: * permission under its copyrights to use, copy, modify, and distribute this michael@0: * Software with or without fee, provided that the above copyright notice and michael@0: * all paragraphs of this notice appear in all copies, and that the name of IBM michael@0: * not be used in connection with the marketing of any product incorporating michael@0: * the Software or modifications thereof, without specific, written prior michael@0: * permission. michael@0: * michael@0: * To the extent it has a right to do so, IBM grants an immunity from suit michael@0: * under its patents, if any, for the use, sale or manufacture of products to michael@0: * the extent that such products are used for performing Domain Name System michael@0: * dynamic updates in TCP/IP networks by means of the Software. No immunity is michael@0: * granted for any product per se or for any other function of any product. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, michael@0: * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A michael@0: * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, michael@0: * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING michael@0: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN michael@0: * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. michael@0: */ michael@0: michael@0: /* michael@0: * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") michael@0: * Portions Copyright (c) 1996-1999 by Internet Software Consortium. michael@0: * michael@0: * Permission to use, copy, modify, and distribute this software for any michael@0: * purpose with or without fee is hereby granted, provided that the above michael@0: * copyright notice and this permission notice appear in all copies. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES michael@0: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF michael@0: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR michael@0: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN michael@0: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT michael@0: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. michael@0: */ michael@0: michael@0: /* michael@0: * This version of this file is derived from Android 2.3 "Gingerbread", michael@0: * which contains uncredited changes by Android/Google developers. It has michael@0: * been modified in 2011 for use in the Android build of Mozilla Firefox by michael@0: * Mozilla contributors (including Michael Edwards , michael@0: * and Steve Workman ). michael@0: * These changes are offered under the same license as the original NetBSD michael@0: * file, whose copyright and license are unchanged above. michael@0: */ michael@0: michael@0: #define ANDROID_CHANGES 1 michael@0: #define MOZILLA_NECKO_EXCLUDE_CODE 1 michael@0: michael@0: #include michael@0: #if defined(LIBC_SCCS) && !defined(lint) michael@0: #ifdef notdef michael@0: static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; michael@0: static const char rcsid[] = "Id: res_debug.c,v 1.3.2.5.4.5 2004/07/28 20:16:46 marka Exp"; michael@0: #else michael@0: __RCSID("$NetBSD: res_debug.c,v 1.7 2004/11/07 02:25:01 christos Exp $"); michael@0: #endif michael@0: #endif /* LIBC_SCCS and not lint */ michael@0: michael@0: michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include "arpa_nameser.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include "resolv_private.h" michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: michael@0: michael@0: #ifdef SPRINTF_CHAR michael@0: # define SPRINTF(x) strlen(sprintf/**/x) michael@0: #else michael@0: # define SPRINTF(x) sprintf x michael@0: #endif michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: static const char *precsize_ntoa(u_int32_t); michael@0: #endif michael@0: michael@0: extern const char * const _res_opcodes[]; michael@0: extern const char * const _res_sectioncodes[]; michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: #ifndef _LIBC michael@0: /* michael@0: * Print the current options. michael@0: */ michael@0: void michael@0: fp_resstat(const res_state statp, FILE *file) { michael@0: u_long mask; michael@0: michael@0: fprintf(file, ";; res options:"); michael@0: for (mask = 1; mask != 0U; mask <<= 1) michael@0: if (statp->options & mask) michael@0: fprintf(file, " %s", p_option(mask)); michael@0: putc('\n', file); michael@0: } michael@0: #endif michael@0: #endif michael@0: michael@0: static void michael@0: do_section(const res_state statp, michael@0: ns_msg *handle, ns_sect section, michael@0: int pflag, FILE *file) michael@0: { michael@0: int n, sflag, rrnum; michael@0: int buflen = 2048; michael@0: char *buf; michael@0: ns_opcode opcode; michael@0: ns_rr rr; michael@0: michael@0: /* michael@0: * Print answer records. michael@0: */ michael@0: sflag = (statp->pfcode & pflag); michael@0: if (statp->pfcode && !sflag) michael@0: return; michael@0: michael@0: buf = malloc((size_t)buflen); michael@0: if (buf == NULL) { michael@0: fprintf(file, ";; memory allocation failure\n"); michael@0: return; michael@0: } michael@0: michael@0: opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode); michael@0: rrnum = 0; michael@0: for (;;) { michael@0: if (ns_parserr(handle, section, rrnum, &rr)) { michael@0: if (errno != ENODEV) michael@0: fprintf(file, ";; ns_parserr: %s\n", michael@0: strerror(errno)); michael@0: else if (rrnum > 0 && sflag != 0 && michael@0: (statp->pfcode & RES_PRF_HEAD1)) michael@0: putc('\n', file); michael@0: goto cleanup; michael@0: } michael@0: if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1)) michael@0: fprintf(file, ";; %s SECTION:\n", michael@0: p_section(section, opcode)); michael@0: if (section == ns_s_qd) michael@0: fprintf(file, ";;\t%s, type = %s, class = %s\n", michael@0: ns_rr_name(rr), michael@0: p_type(ns_rr_type(rr)), michael@0: p_class(ns_rr_class(rr))); michael@0: else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { michael@0: u_int32_t ttl = ns_rr_ttl(rr); michael@0: fprintf(file, michael@0: "; EDNS: version: %u, udp=%u, flags=%04x\n", michael@0: (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); michael@0: } else { michael@0: n = ns_sprintrr(handle, &rr, NULL, NULL, michael@0: buf, (u_int)buflen); michael@0: if (n < 0) { michael@0: if (errno == ENOSPC) { michael@0: free(buf); michael@0: buf = NULL; michael@0: if (buflen < 131072) michael@0: buf = malloc((size_t)(buflen += 1024)); michael@0: if (buf == NULL) { michael@0: fprintf(file, michael@0: ";; memory allocation failure\n"); michael@0: return; michael@0: } michael@0: continue; michael@0: } michael@0: fprintf(file, ";; ns_sprintrr: %s\n", michael@0: strerror(errno)); michael@0: goto cleanup; michael@0: } michael@0: fputs(buf, file); michael@0: fputc('\n', file); michael@0: } michael@0: rrnum++; michael@0: } michael@0: cleanup: michael@0: if (buf != NULL) michael@0: free(buf); michael@0: } michael@0: michael@0: /* michael@0: * Print the contents of a query. michael@0: * This is intended to be primarily a debugging routine. michael@0: */ michael@0: void michael@0: res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { michael@0: ns_msg handle; michael@0: int qdcount, ancount, nscount, arcount; michael@0: u_int opcode, rcode, id; michael@0: michael@0: if (ns_initparse(msg, len, &handle) < 0) { michael@0: fprintf(file, ";; ns_initparse: %s\n", strerror(errno)); michael@0: return; michael@0: } michael@0: opcode = ns_msg_getflag(handle, ns_f_opcode); michael@0: rcode = ns_msg_getflag(handle, ns_f_rcode); michael@0: id = ns_msg_id(handle); michael@0: qdcount = ns_msg_count(handle, ns_s_qd); michael@0: ancount = ns_msg_count(handle, ns_s_an); michael@0: nscount = ns_msg_count(handle, ns_s_ns); michael@0: arcount = ns_msg_count(handle, ns_s_ar); michael@0: michael@0: /* michael@0: * Print header fields. michael@0: */ michael@0: if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode) michael@0: fprintf(file, michael@0: ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", michael@0: _res_opcodes[opcode], p_rcode((int)rcode), id); michael@0: if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) michael@0: putc(';', file); michael@0: if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) { michael@0: fprintf(file, "; flags:"); michael@0: if (ns_msg_getflag(handle, ns_f_qr)) michael@0: fprintf(file, " qr"); michael@0: if (ns_msg_getflag(handle, ns_f_aa)) michael@0: fprintf(file, " aa"); michael@0: if (ns_msg_getflag(handle, ns_f_tc)) michael@0: fprintf(file, " tc"); michael@0: if (ns_msg_getflag(handle, ns_f_rd)) michael@0: fprintf(file, " rd"); michael@0: if (ns_msg_getflag(handle, ns_f_ra)) michael@0: fprintf(file, " ra"); michael@0: if (ns_msg_getflag(handle, ns_f_z)) michael@0: fprintf(file, " ??"); michael@0: if (ns_msg_getflag(handle, ns_f_ad)) michael@0: fprintf(file, " ad"); michael@0: if (ns_msg_getflag(handle, ns_f_cd)) michael@0: fprintf(file, " cd"); michael@0: } michael@0: if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) { michael@0: fprintf(file, "; %s: %d", michael@0: p_section(ns_s_qd, (int)opcode), qdcount); michael@0: fprintf(file, ", %s: %d", michael@0: p_section(ns_s_an, (int)opcode), ancount); michael@0: fprintf(file, ", %s: %d", michael@0: p_section(ns_s_ns, (int)opcode), nscount); michael@0: fprintf(file, ", %s: %d", michael@0: p_section(ns_s_ar, (int)opcode), arcount); michael@0: } michael@0: if ((!statp->pfcode) || (statp->pfcode & michael@0: (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { michael@0: putc('\n',file); michael@0: } michael@0: /* michael@0: * Print the various sections. michael@0: */ michael@0: do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file); michael@0: do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file); michael@0: do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file); michael@0: do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file); michael@0: if (qdcount == 0 && ancount == 0 && michael@0: nscount == 0 && arcount == 0) michael@0: putc('\n', file); michael@0: } michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: const u_char * michael@0: p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) { michael@0: char name[MAXDNAME]; michael@0: int n; michael@0: michael@0: if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) michael@0: return (NULL); michael@0: if (name[0] == '\0') michael@0: putc('.', file); michael@0: else michael@0: fputs(name, file); michael@0: return (cp + n); michael@0: } michael@0: michael@0: const u_char * michael@0: p_cdname(const u_char *cp, const u_char *msg, FILE *file) { michael@0: return (p_cdnname(cp, msg, PACKETSZ, file)); michael@0: } michael@0: michael@0: /* Return a fully-qualified domain name from a compressed name (with michael@0: length supplied). */ michael@0: michael@0: const u_char * michael@0: p_fqnname(cp, msg, msglen, name, namelen) michael@0: const u_char *cp, *msg; michael@0: int msglen; michael@0: char *name; michael@0: int namelen; michael@0: { michael@0: int n, newlen; michael@0: michael@0: if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) michael@0: return (NULL); michael@0: newlen = strlen(name); michael@0: if (newlen == 0 || name[newlen - 1] != '.') { michael@0: if (newlen + 1 >= namelen) /* Lack space for final dot */ michael@0: return (NULL); michael@0: else michael@0: strcpy(name + newlen, "."); michael@0: } michael@0: return (cp + n); michael@0: } michael@0: michael@0: /* XXX: the rest of these functions need to become length-limited, too. */ michael@0: michael@0: const u_char * michael@0: p_fqname(const u_char *cp, const u_char *msg, FILE *file) { michael@0: char name[MAXDNAME]; michael@0: const u_char *n; michael@0: michael@0: n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); michael@0: if (n == NULL) michael@0: return (NULL); michael@0: fputs(name, file); michael@0: return (n); michael@0: } michael@0: #endif michael@0: michael@0: /* michael@0: * Names of RR classes and qclasses. Classes and qclasses are the same, except michael@0: * that C_ANY is a qclass but not a class. (You can ask for records of class michael@0: * C_ANY, but you can't have any records of that class in the database.) michael@0: */ michael@0: const struct res_sym __p_class_syms[] = { michael@0: {C_IN, "IN", (char *)0}, michael@0: {C_CHAOS, "CH", (char *)0}, michael@0: {C_CHAOS, "CHAOS", (char *)0}, michael@0: {C_HS, "HS", (char *)0}, michael@0: {C_HS, "HESIOD", (char *)0}, michael@0: {C_ANY, "ANY", (char *)0}, michael@0: {C_NONE, "NONE", (char *)0}, michael@0: {C_IN, (char *)0, (char *)0} michael@0: }; michael@0: michael@0: /* michael@0: * Names of message sections. michael@0: */ michael@0: const struct res_sym __p_default_section_syms[] = { michael@0: {ns_s_qd, "QUERY", (char *)0}, michael@0: {ns_s_an, "ANSWER", (char *)0}, michael@0: {ns_s_ns, "AUTHORITY", (char *)0}, michael@0: {ns_s_ar, "ADDITIONAL", (char *)0}, michael@0: {0, (char *)0, (char *)0} michael@0: }; michael@0: michael@0: const struct res_sym __p_update_section_syms[] = { michael@0: {S_ZONE, "ZONE", (char *)0}, michael@0: {S_PREREQ, "PREREQUISITE", (char *)0}, michael@0: {S_UPDATE, "UPDATE", (char *)0}, michael@0: {S_ADDT, "ADDITIONAL", (char *)0}, michael@0: {0, (char *)0, (char *)0} michael@0: }; michael@0: michael@0: const struct res_sym __p_key_syms[] = { michael@0: {NS_ALG_MD5RSA, "RSA", "RSA KEY with MD5 hash"}, michael@0: {NS_ALG_DH, "DH", "Diffie Hellman"}, michael@0: {NS_ALG_DSA, "DSA", "Digital Signature Algorithm"}, michael@0: {NS_ALG_EXPIRE_ONLY, "EXPIREONLY", "No algorithm"}, michael@0: {NS_ALG_PRIVATE_OID, "PRIVATE", "Algorithm obtained from OID"}, michael@0: {0, NULL, NULL} michael@0: }; michael@0: michael@0: const struct res_sym __p_cert_syms[] = { michael@0: {cert_t_pkix, "PKIX", "PKIX (X.509v3) Certificate"}, michael@0: {cert_t_spki, "SPKI", "SPKI certificate"}, michael@0: {cert_t_pgp, "PGP", "PGP certificate"}, michael@0: {cert_t_url, "URL", "URL Private"}, michael@0: {cert_t_oid, "OID", "OID Private"}, michael@0: {0, NULL, NULL} michael@0: }; michael@0: michael@0: /* michael@0: * Names of RR types and qtypes. Types and qtypes are the same, except michael@0: * that T_ANY is a qtype but not a type. (You can ask for records of type michael@0: * T_ANY, but you can't have any records of that type in the database.) michael@0: */ michael@0: const struct res_sym __p_type_syms[] = { michael@0: {ns_t_a, "A", "address"}, michael@0: {ns_t_ns, "NS", "name server"}, michael@0: {ns_t_md, "MD", "mail destination (deprecated)"}, michael@0: {ns_t_mf, "MF", "mail forwarder (deprecated)"}, michael@0: {ns_t_cname, "CNAME", "canonical name"}, michael@0: {ns_t_soa, "SOA", "start of authority"}, michael@0: {ns_t_mb, "MB", "mailbox"}, michael@0: {ns_t_mg, "MG", "mail group member"}, michael@0: {ns_t_mr, "MR", "mail rename"}, michael@0: {ns_t_null, "NULL", "null"}, michael@0: {ns_t_wks, "WKS", "well-known service (deprecated)"}, michael@0: {ns_t_ptr, "PTR", "domain name pointer"}, michael@0: {ns_t_hinfo, "HINFO", "host information"}, michael@0: {ns_t_minfo, "MINFO", "mailbox information"}, michael@0: {ns_t_mx, "MX", "mail exchanger"}, michael@0: {ns_t_txt, "TXT", "text"}, michael@0: {ns_t_rp, "RP", "responsible person"}, michael@0: {ns_t_afsdb, "AFSDB", "DCE or AFS server"}, michael@0: {ns_t_x25, "X25", "X25 address"}, michael@0: {ns_t_isdn, "ISDN", "ISDN address"}, michael@0: {ns_t_rt, "RT", "router"}, michael@0: {ns_t_nsap, "NSAP", "nsap address"}, michael@0: {ns_t_nsap_ptr, "NSAP_PTR", "domain name pointer"}, michael@0: {ns_t_sig, "SIG", "signature"}, michael@0: {ns_t_key, "KEY", "key"}, michael@0: {ns_t_px, "PX", "mapping information"}, michael@0: {ns_t_gpos, "GPOS", "geographical position (withdrawn)"}, michael@0: {ns_t_aaaa, "AAAA", "IPv6 address"}, michael@0: {ns_t_loc, "LOC", "location"}, michael@0: {ns_t_nxt, "NXT", "next valid name (unimplemented)"}, michael@0: {ns_t_eid, "EID", "endpoint identifier (unimplemented)"}, michael@0: {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"}, michael@0: {ns_t_srv, "SRV", "server selection"}, michael@0: {ns_t_atma, "ATMA", "ATM address (unimplemented)"}, michael@0: {ns_t_tkey, "TKEY", "tkey"}, michael@0: {ns_t_tsig, "TSIG", "transaction signature"}, michael@0: {ns_t_ixfr, "IXFR", "incremental zone transfer"}, michael@0: {ns_t_axfr, "AXFR", "zone transfer"}, michael@0: {ns_t_zxfr, "ZXFR", "compressed zone transfer"}, michael@0: {ns_t_mailb, "MAILB", "mailbox-related data (deprecated)"}, michael@0: {ns_t_maila, "MAILA", "mail agent (deprecated)"}, michael@0: {ns_t_naptr, "NAPTR", "URN Naming Authority"}, michael@0: {ns_t_kx, "KX", "Key Exchange"}, michael@0: {ns_t_cert, "CERT", "Certificate"}, michael@0: {ns_t_a6, "A6", "IPv6 Address"}, michael@0: {ns_t_dname, "DNAME", "dname"}, michael@0: {ns_t_sink, "SINK", "Kitchen Sink (experimental)"}, michael@0: {ns_t_opt, "OPT", "EDNS Options"}, michael@0: {ns_t_any, "ANY", "\"any\""}, michael@0: {0, NULL, NULL} michael@0: }; michael@0: michael@0: /* michael@0: * Names of DNS rcodes. michael@0: */ michael@0: const struct res_sym __p_rcode_syms[] = { michael@0: {ns_r_noerror, "NOERROR", "no error"}, michael@0: {ns_r_formerr, "FORMERR", "format error"}, michael@0: {ns_r_servfail, "SERVFAIL", "server failed"}, michael@0: {ns_r_nxdomain, "NXDOMAIN", "no such domain name"}, michael@0: {ns_r_notimpl, "NOTIMP", "not implemented"}, michael@0: {ns_r_refused, "REFUSED", "refused"}, michael@0: {ns_r_yxdomain, "YXDOMAIN", "domain name exists"}, michael@0: {ns_r_yxrrset, "YXRRSET", "rrset exists"}, michael@0: {ns_r_nxrrset, "NXRRSET", "rrset doesn't exist"}, michael@0: {ns_r_notauth, "NOTAUTH", "not authoritative"}, michael@0: {ns_r_notzone, "NOTZONE", "Not in zone"}, michael@0: {ns_r_max, "", ""}, michael@0: {ns_r_badsig, "BADSIG", "bad signature"}, michael@0: {ns_r_badkey, "BADKEY", "bad key"}, michael@0: {ns_r_badtime, "BADTIME", "bad time"}, michael@0: {0, NULL, NULL} michael@0: }; michael@0: michael@0: int michael@0: sym_ston(const struct res_sym *syms, const char *name, int *success) { michael@0: for (; syms->name != 0; syms++) { michael@0: if (strcasecmp (name, syms->name) == 0) { michael@0: if (success) michael@0: *success = 1; michael@0: return (syms->number); michael@0: } michael@0: } michael@0: if (success) michael@0: *success = 0; michael@0: return (syms->number); /* The default value. */ michael@0: } michael@0: michael@0: const char * michael@0: sym_ntos(const struct res_sym *syms, int number, int *success) { michael@0: static char unname[20]; michael@0: michael@0: for (; syms->name != 0; syms++) { michael@0: if (number == syms->number) { michael@0: if (success) michael@0: *success = 1; michael@0: return (syms->name); michael@0: } michael@0: } michael@0: michael@0: sprintf(unname, "%d", number); /* XXX nonreentrant */ michael@0: if (success) michael@0: *success = 0; michael@0: return (unname); michael@0: } michael@0: michael@0: const char * michael@0: sym_ntop(const struct res_sym *syms, int number, int *success) { michael@0: static char unname[20]; michael@0: michael@0: for (; syms->name != 0; syms++) { michael@0: if (number == syms->number) { michael@0: if (success) michael@0: *success = 1; michael@0: return (syms->humanname); michael@0: } michael@0: } michael@0: sprintf(unname, "%d", number); /* XXX nonreentrant */ michael@0: if (success) michael@0: *success = 0; michael@0: return (unname); michael@0: } michael@0: michael@0: /* michael@0: * Return a string for the type. michael@0: */ michael@0: const char * michael@0: p_type(int type) { michael@0: int success; michael@0: const char *result; michael@0: static char typebuf[20]; michael@0: michael@0: result = sym_ntos(__p_type_syms, type, &success); michael@0: if (success) michael@0: return (result); michael@0: if (type < 0 || type > 0xffff) michael@0: return ("BADTYPE"); michael@0: sprintf(typebuf, "TYPE%d", type); michael@0: return (typebuf); michael@0: } michael@0: michael@0: /* michael@0: * Return a string for the type. michael@0: */ michael@0: const char * michael@0: p_section(int section, int opcode) { michael@0: const struct res_sym *symbols; michael@0: michael@0: switch (opcode) { michael@0: case ns_o_update: michael@0: symbols = __p_update_section_syms; michael@0: break; michael@0: default: michael@0: symbols = __p_default_section_syms; michael@0: break; michael@0: } michael@0: return (sym_ntos(symbols, section, (int *)0)); michael@0: } michael@0: michael@0: /* michael@0: * Return a mnemonic for class. michael@0: */ michael@0: const char * michael@0: p_class(int class) { michael@0: int success; michael@0: const char *result; michael@0: static char classbuf[20]; michael@0: michael@0: result = sym_ntos(__p_class_syms, class, &success); michael@0: if (success) michael@0: return (result); michael@0: if (class < 0 || class > 0xffff) michael@0: return ("BADCLASS"); michael@0: sprintf(classbuf, "CLASS%d", class); michael@0: return (classbuf); michael@0: } michael@0: michael@0: /* michael@0: * Return a mnemonic for an option michael@0: */ michael@0: const char * michael@0: p_option(u_long option) { michael@0: static char nbuf[40]; michael@0: michael@0: switch (option) { michael@0: case RES_INIT: return "init"; michael@0: case RES_DEBUG: return "debug"; michael@0: case RES_AAONLY: return "aaonly(unimpl)"; michael@0: case RES_USEVC: return "usevc"; michael@0: case RES_PRIMARY: return "primry(unimpl)"; michael@0: case RES_IGNTC: return "igntc"; michael@0: case RES_RECURSE: return "recurs"; michael@0: case RES_DEFNAMES: return "defnam"; michael@0: case RES_STAYOPEN: return "styopn"; michael@0: case RES_DNSRCH: return "dnsrch"; michael@0: case RES_INSECURE1: return "insecure1"; michael@0: case RES_INSECURE2: return "insecure2"; michael@0: case RES_NOALIASES: return "noaliases"; michael@0: case RES_USE_INET6: return "inet6"; michael@0: #ifdef RES_USE_EDNS0 /* KAME extension */ michael@0: case RES_USE_EDNS0: return "edns0"; michael@0: #endif michael@0: #ifdef RES_USE_DNAME michael@0: case RES_USE_DNAME: return "dname"; michael@0: #endif michael@0: #ifdef RES_USE_DNSSEC michael@0: case RES_USE_DNSSEC: return "dnssec"; michael@0: #endif michael@0: #ifdef RES_NOTLDQUERY michael@0: case RES_NOTLDQUERY: return "no-tld-query"; michael@0: #endif michael@0: #ifdef RES_NO_NIBBLE2 michael@0: case RES_NO_NIBBLE2: return "no-nibble2"; michael@0: #endif michael@0: /* XXX nonreentrant */ michael@0: default: sprintf(nbuf, "?0x%lx?", (u_long)option); michael@0: return (nbuf); michael@0: } michael@0: } michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: /* michael@0: * Return a mnemonic for a time to live. michael@0: */ michael@0: const char * michael@0: p_time(u_int32_t value) { michael@0: static char nbuf[40]; /* XXX nonreentrant */ michael@0: michael@0: if (ns_format_ttl((u_long)value, nbuf, sizeof nbuf) < 0) michael@0: sprintf(nbuf, "%u", value); michael@0: return (nbuf); michael@0: } michael@0: #endif michael@0: michael@0: /* michael@0: * Return a string for the rcode. michael@0: */ michael@0: const char * michael@0: p_rcode(int rcode) { michael@0: return (sym_ntos(__p_rcode_syms, rcode, (int *)0)); michael@0: } michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: /* michael@0: * Return a string for a res_sockaddr_union. michael@0: */ michael@0: const char * michael@0: p_sockun(union res_sockaddr_union u, char *buf, size_t size) { michael@0: char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"]; michael@0: michael@0: switch (u.sin.sin_family) { michael@0: case AF_INET: michael@0: inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret); michael@0: break; michael@0: #ifdef HAS_INET6_STRUCTS michael@0: case AF_INET6: michael@0: inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret); michael@0: break; michael@0: #endif michael@0: default: michael@0: sprintf(ret, "[af%d]", u.sin.sin_family); michael@0: break; michael@0: } michael@0: if (size > 0U) { michael@0: strncpy(buf, ret, size - 1); michael@0: buf[size - 1] = '0'; michael@0: } michael@0: return (buf); michael@0: } michael@0: #endif michael@0: michael@0: /* michael@0: * routines to convert between on-the-wire RR format and zone file format. michael@0: * Does not contain conversion to/from decimal degrees; divide or multiply michael@0: * by 60*60*1000 for that. michael@0: */ michael@0: michael@0: static const unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, michael@0: 1000000,10000000,100000000,1000000000}; michael@0: michael@0: /* takes an XeY precision/size value, returns a string representation. */ michael@0: static const char * michael@0: precsize_ntoa(prec) michael@0: u_int32_t prec; michael@0: { michael@0: static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */ michael@0: unsigned long val; michael@0: int mantissa, exponent; michael@0: michael@0: mantissa = (int)((prec >> 4) & 0x0f) % 10; michael@0: exponent = (int)((prec >> 0) & 0x0f) % 10; michael@0: michael@0: val = mantissa * poweroften[exponent]; michael@0: michael@0: (void) sprintf(retbuf, "%lu.%.2lu", val/100, val%100); michael@0: return (retbuf); michael@0: } michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ michael@0: static u_int8_t michael@0: precsize_aton(const char **strptr) { michael@0: unsigned int mval = 0, cmval = 0; michael@0: u_int8_t retval = 0; michael@0: const char *cp; michael@0: int exponent; michael@0: int mantissa; michael@0: michael@0: cp = *strptr; michael@0: michael@0: while (isdigit((unsigned char)*cp)) michael@0: mval = mval * 10 + (*cp++ - '0'); michael@0: michael@0: if (*cp == '.') { /* centimeters */ michael@0: cp++; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: cmval = (*cp++ - '0') * 10; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: cmval += (*cp++ - '0'); michael@0: } michael@0: } michael@0: } michael@0: cmval = (mval * 100) + cmval; michael@0: michael@0: for (exponent = 0; exponent < 9; exponent++) michael@0: if (cmval < poweroften[exponent+1]) michael@0: break; michael@0: michael@0: mantissa = cmval / poweroften[exponent]; michael@0: if (mantissa > 9) michael@0: mantissa = 9; michael@0: michael@0: retval = (mantissa << 4) | exponent; michael@0: michael@0: *strptr = cp; michael@0: michael@0: return (retval); michael@0: } michael@0: michael@0: /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ michael@0: static u_int32_t michael@0: latlon2ul(const char **latlonstrptr, int *which) { michael@0: const char *cp; michael@0: u_int32_t retval; michael@0: int deg = 0, min = 0, secs = 0, secsfrac = 0; michael@0: michael@0: cp = *latlonstrptr; michael@0: michael@0: while (isdigit((unsigned char)*cp)) michael@0: deg = deg * 10 + (*cp++ - '0'); michael@0: michael@0: while (isspace((unsigned char)*cp)) michael@0: cp++; michael@0: michael@0: if (!(isdigit((unsigned char)*cp))) michael@0: goto fndhemi; michael@0: michael@0: while (isdigit((unsigned char)*cp)) michael@0: min = min * 10 + (*cp++ - '0'); michael@0: michael@0: while (isspace((unsigned char)*cp)) michael@0: cp++; michael@0: michael@0: if (!(isdigit((unsigned char)*cp))) michael@0: goto fndhemi; michael@0: michael@0: while (isdigit((unsigned char)*cp)) michael@0: secs = secs * 10 + (*cp++ - '0'); michael@0: michael@0: if (*cp == '.') { /* decimal seconds */ michael@0: cp++; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: secsfrac = (*cp++ - '0') * 100; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: secsfrac += (*cp++ - '0') * 10; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: secsfrac += (*cp++ - '0'); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ michael@0: cp++; michael@0: michael@0: while (isspace((unsigned char)*cp)) michael@0: cp++; michael@0: michael@0: fndhemi: michael@0: switch (*cp) { michael@0: case 'N': case 'n': michael@0: case 'E': case 'e': michael@0: retval = ((unsigned)1<<31) michael@0: + (((((deg * 60) + min) * 60) + secs) * 1000) michael@0: + secsfrac; michael@0: break; michael@0: case 'S': case 's': michael@0: case 'W': case 'w': michael@0: retval = ((unsigned)1<<31) michael@0: - (((((deg * 60) + min) * 60) + secs) * 1000) michael@0: - secsfrac; michael@0: break; michael@0: default: michael@0: retval = 0; /* invalid value -- indicates error */ michael@0: break; michael@0: } michael@0: michael@0: switch (*cp) { michael@0: case 'N': case 'n': michael@0: case 'S': case 's': michael@0: *which = 1; /* latitude */ michael@0: break; michael@0: case 'E': case 'e': michael@0: case 'W': case 'w': michael@0: *which = 2; /* longitude */ michael@0: break; michael@0: default: michael@0: *which = 0; /* error */ michael@0: break; michael@0: } michael@0: michael@0: cp++; /* skip the hemisphere */ michael@0: michael@0: while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ michael@0: cp++; michael@0: michael@0: while (isspace((unsigned char)*cp)) /* move to next field */ michael@0: cp++; michael@0: michael@0: *latlonstrptr = cp; michael@0: michael@0: return (retval); michael@0: } michael@0: michael@0: /* converts a zone file representation in a string to an RDATA on-the-wire michael@0: * representation. */ michael@0: int michael@0: loc_aton(ascii, binary) michael@0: const char *ascii; michael@0: u_char *binary; michael@0: { michael@0: const char *cp, *maxcp; michael@0: u_char *bcp; michael@0: michael@0: u_int32_t latit = 0, longit = 0, alt = 0; michael@0: u_int32_t lltemp1 = 0, lltemp2 = 0; michael@0: int altmeters = 0, altfrac = 0, altsign = 1; michael@0: u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */ michael@0: u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */ michael@0: u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */ michael@0: int which1 = 0, which2 = 0; michael@0: michael@0: cp = ascii; michael@0: maxcp = cp + strlen(ascii); michael@0: michael@0: lltemp1 = latlon2ul(&cp, &which1); michael@0: michael@0: lltemp2 = latlon2ul(&cp, &which2); michael@0: michael@0: switch (which1 + which2) { michael@0: case 3: /* 1 + 2, the only valid combination */ michael@0: if ((which1 == 1) && (which2 == 2)) { /* normal case */ michael@0: latit = lltemp1; michael@0: longit = lltemp2; michael@0: } else if ((which1 == 2) && (which2 == 1)) { /* reversed */ michael@0: longit = lltemp1; michael@0: latit = lltemp2; michael@0: } else { /* some kind of brokenness */ michael@0: return (0); michael@0: } michael@0: break; michael@0: default: /* we didn't get one of each */ michael@0: return (0); michael@0: } michael@0: michael@0: /* altitude */ michael@0: if (*cp == '-') { michael@0: altsign = -1; michael@0: cp++; michael@0: } michael@0: michael@0: if (*cp == '+') michael@0: cp++; michael@0: michael@0: while (isdigit((unsigned char)*cp)) michael@0: altmeters = altmeters * 10 + (*cp++ - '0'); michael@0: michael@0: if (*cp == '.') { /* decimal meters */ michael@0: cp++; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: altfrac = (*cp++ - '0') * 10; michael@0: if (isdigit((unsigned char)*cp)) { michael@0: altfrac += (*cp++ - '0'); michael@0: } michael@0: } michael@0: } michael@0: michael@0: alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); michael@0: michael@0: while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ michael@0: cp++; michael@0: michael@0: while (isspace((unsigned char)*cp) && (cp < maxcp)) michael@0: cp++; michael@0: michael@0: if (cp >= maxcp) michael@0: goto defaults; michael@0: michael@0: siz = precsize_aton(&cp); michael@0: michael@0: while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ michael@0: cp++; michael@0: michael@0: while (isspace((unsigned char)*cp) && (cp < maxcp)) michael@0: cp++; michael@0: michael@0: if (cp >= maxcp) michael@0: goto defaults; michael@0: michael@0: hp = precsize_aton(&cp); michael@0: michael@0: while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ michael@0: cp++; michael@0: michael@0: while (isspace((unsigned char)*cp) && (cp < maxcp)) michael@0: cp++; michael@0: michael@0: if (cp >= maxcp) michael@0: goto defaults; michael@0: michael@0: vp = precsize_aton(&cp); michael@0: michael@0: defaults: michael@0: michael@0: bcp = binary; michael@0: *bcp++ = (u_int8_t) 0; /* version byte */ michael@0: *bcp++ = siz; michael@0: *bcp++ = hp; michael@0: *bcp++ = vp; michael@0: PUTLONG(latit,bcp); michael@0: PUTLONG(longit,bcp); michael@0: PUTLONG(alt,bcp); michael@0: michael@0: return (16); /* size of RR in octets */ michael@0: } michael@0: #endif michael@0: michael@0: /* takes an on-the-wire LOC RR and formats it in a human readable format. */ michael@0: const char * michael@0: loc_ntoa(binary, ascii) michael@0: const u_char *binary; michael@0: char *ascii; michael@0: { michael@0: static const char *error = "?"; michael@0: static char tmpbuf[sizeof michael@0: "1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"]; michael@0: const u_char *cp = binary; michael@0: michael@0: int latdeg, latmin, latsec, latsecfrac; michael@0: int longdeg, longmin, longsec, longsecfrac; michael@0: char northsouth, eastwest; michael@0: const char *altsign; michael@0: int altmeters, altfrac; michael@0: michael@0: const u_int32_t referencealt = 100000 * 100; michael@0: michael@0: int32_t latval, longval, altval; michael@0: u_int32_t templ; michael@0: u_int8_t sizeval, hpval, vpval, versionval; michael@0: michael@0: char *sizestr, *hpstr, *vpstr; michael@0: michael@0: versionval = *cp++; michael@0: michael@0: if (ascii == NULL) michael@0: ascii = tmpbuf; michael@0: michael@0: if (versionval) { michael@0: (void) sprintf(ascii, "; error: unknown LOC RR version"); michael@0: return (ascii); michael@0: } michael@0: michael@0: sizeval = *cp++; michael@0: michael@0: hpval = *cp++; michael@0: vpval = *cp++; michael@0: michael@0: GETLONG(templ, cp); michael@0: latval = (templ - ((unsigned)1<<31)); michael@0: michael@0: GETLONG(templ, cp); michael@0: longval = (templ - ((unsigned)1<<31)); michael@0: michael@0: GETLONG(templ, cp); michael@0: if (templ < referencealt) { /* below WGS 84 spheroid */ michael@0: altval = referencealt - templ; michael@0: altsign = "-"; michael@0: } else { michael@0: altval = templ - referencealt; michael@0: altsign = ""; michael@0: } michael@0: michael@0: if (latval < 0) { michael@0: northsouth = 'S'; michael@0: latval = -latval; michael@0: } else michael@0: northsouth = 'N'; michael@0: michael@0: latsecfrac = latval % 1000; michael@0: latval = latval / 1000; michael@0: latsec = latval % 60; michael@0: latval = latval / 60; michael@0: latmin = latval % 60; michael@0: latval = latval / 60; michael@0: latdeg = latval; michael@0: michael@0: if (longval < 0) { michael@0: eastwest = 'W'; michael@0: longval = -longval; michael@0: } else michael@0: eastwest = 'E'; michael@0: michael@0: longsecfrac = longval % 1000; michael@0: longval = longval / 1000; michael@0: longsec = longval % 60; michael@0: longval = longval / 60; michael@0: longmin = longval % 60; michael@0: longval = longval / 60; michael@0: longdeg = longval; michael@0: michael@0: altfrac = altval % 100; michael@0: altmeters = (altval / 100); michael@0: michael@0: sizestr = strdup(precsize_ntoa((u_int32_t)sizeval)); michael@0: hpstr = strdup(precsize_ntoa((u_int32_t)hpval)); michael@0: vpstr = strdup(precsize_ntoa((u_int32_t)vpval)); michael@0: michael@0: sprintf(ascii, michael@0: "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm", michael@0: latdeg, latmin, latsec, latsecfrac, northsouth, michael@0: longdeg, longmin, longsec, longsecfrac, eastwest, michael@0: altsign, altmeters, altfrac, michael@0: (sizestr != NULL) ? sizestr : error, michael@0: (hpstr != NULL) ? hpstr : error, michael@0: (vpstr != NULL) ? vpstr : error); michael@0: michael@0: if (sizestr != NULL) michael@0: free(sizestr); michael@0: if (hpstr != NULL) michael@0: free(hpstr); michael@0: if (vpstr != NULL) michael@0: free(vpstr); michael@0: michael@0: return (ascii); michael@0: } michael@0: michael@0: michael@0: /* Return the number of DNS hierarchy levels in the name. */ michael@0: int michael@0: dn_count_labels(const char *name) { michael@0: int i, len, count; michael@0: michael@0: len = strlen(name); michael@0: for (i = 0, count = 0; i < len; i++) { michael@0: /* XXX need to check for \. or use named's nlabels(). */ michael@0: if (name[i] == '.') michael@0: count++; michael@0: } michael@0: michael@0: /* don't count initial wildcard */ michael@0: if (name[0] == '*') michael@0: if (count) michael@0: count--; michael@0: michael@0: /* don't count the null label for root. */ michael@0: /* if terminating '.' not found, must adjust */ michael@0: /* count to include last label */ michael@0: if (len > 0 && name[len-1] != '.') michael@0: count++; michael@0: return (count); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * Make dates expressed in seconds-since-Jan-1-1970 easy to read. michael@0: * SIG records are required to be printed like this, by the Secure DNS RFC. michael@0: */ michael@0: char * michael@0: p_secstodate (u_long secs) { michael@0: /* XXX nonreentrant */ michael@0: static char output[15]; /* YYYYMMDDHHMMSS and null */ michael@0: time_t myclock = secs; michael@0: struct tm *mytime; michael@0: #ifdef HAVE_TIME_R michael@0: struct tm res; michael@0: michael@0: mytime = gmtime_r(&myclock, &res); michael@0: #else michael@0: mytime = gmtime(&myclock); michael@0: #endif michael@0: mytime->tm_year += 1900; michael@0: mytime->tm_mon += 1; michael@0: sprintf(output, "%04d%02d%02d%02d%02d%02d", michael@0: mytime->tm_year, mytime->tm_mon, mytime->tm_mday, michael@0: mytime->tm_hour, mytime->tm_min, mytime->tm_sec); michael@0: return (output); michael@0: } michael@0: michael@0: #ifndef MOZILLA_NECKO_EXCLUDE_CODE michael@0: u_int16_t michael@0: res_nametoclass(const char *buf, int *successp) { michael@0: unsigned long result; michael@0: char *endptr; michael@0: int success; michael@0: michael@0: result = sym_ston(__p_class_syms, buf, &success); michael@0: if (success) michael@0: goto done; michael@0: michael@0: if (strncasecmp(buf, "CLASS", 5) != 0 || michael@0: !isdigit((unsigned char)buf[5])) michael@0: goto done; michael@0: errno = 0; michael@0: result = strtoul(buf + 5, &endptr, 10); michael@0: if (errno == 0 && *endptr == '\0' && result <= 0xffffU) michael@0: success = 1; michael@0: done: michael@0: if (successp) michael@0: *successp = success; michael@0: return (u_int16_t)(result); michael@0: } michael@0: michael@0: u_int16_t michael@0: res_nametotype(const char *buf, int *successp) { michael@0: unsigned long result; michael@0: char *endptr; michael@0: int success; michael@0: michael@0: result = sym_ston(__p_type_syms, buf, &success); michael@0: if (success) michael@0: goto done; michael@0: michael@0: if (strncasecmp(buf, "type", 4) != 0 || michael@0: !isdigit((unsigned char)buf[4])) michael@0: goto done; michael@0: errno = 0; michael@0: result = strtoul(buf + 4, &endptr, 10); michael@0: if (errno == 0 && *endptr == '\0' && result <= 0xffffU) michael@0: success = 1; michael@0: done: michael@0: if (successp) michael@0: *successp = success; michael@0: return (u_int16_t)(result); michael@0: } michael@0: #endif