3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)res_debug.c 8.1 (Berkeley) 6/4/93
30 * $FreeBSD: src/lib/libc/net/res_debug.c,v 1.18.2.1 2001/06/15 22:08:28 ume Exp $
31 * $DragonFly: src/lib/libc/net/res_debug.c,v 1.3 2005/09/19 09:34:53 asmodai Exp $
35 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
37 * Permission to use, copy, modify, and distribute this software for any
38 * purpose with or without fee is hereby granted, provided that the above
39 * copyright notice and this permission notice appear in all copies, and that
40 * the name of Digital Equipment Corporation not be used in advertising or
41 * publicity pertaining to distribution of the document or software without
42 * specific, written prior permission.
44 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
47 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 * Portions Copyright (c) 1995 by International Business Machines, Inc.
57 * International Business Machines, Inc. (hereinafter called IBM) grants
58 * permission under its copyrights to use, copy, modify, and distribute this
59 * Software with or without fee, provided that the above copyright notice and
60 * all paragraphs of this notice appear in all copies, and that the name of IBM
61 * not be used in connection with the marketing of any product incorporating
62 * the Software or modifications thereof, without specific, written prior
65 * To the extent it has a right to do so, IBM grants an immunity from suit
66 * under its patents, if any, for the use, sale or manufacture of products to
67 * the extent that such products are used for performing Domain Name System
68 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
69 * granted for any product per se or for any other function of any product.
71 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
72 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
73 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
74 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
75 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
76 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
80 * Portions Copyright (c) 1996 by Internet Software Consortium.
82 * Permission to use, copy, modify, and distribute this software for any
83 * purpose with or without fee is hereby granted, provided that the above
84 * copyright notice and this permission notice appear in all copies.
86 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
87 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
88 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
89 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
90 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
91 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
92 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
96 #include <sys/types.h>
97 #include <sys/param.h>
98 #include <sys/socket.h>
100 #include <netinet/in.h>
101 #include <arpa/inet.h>
102 #include <arpa/nameser.h>
114 #define SPRINTF(x) sprintf x
116 extern const char *_res_opcodes[];
117 extern const char *_res_resultcodes[];
118 extern const char *_res_sectioncodes[];
121 * Print the current options.
124 fp_resstat(struct __res_state *statp, FILE *file) {
127 fprintf(file, ";; res options:");
130 for (mask = 1; mask != 0; mask <<= 1)
131 if (statp->options & mask)
132 fprintf(file, " %s", p_option(mask));
137 do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
139 char buf[2048]; /* XXX need to malloc */
144 * Print answer records.
146 sflag = (_res.pfcode & pflag);
147 if (_res.pfcode && !sflag)
150 opcode = ns_msg_getflag(*handle, ns_f_opcode);
153 if (ns_parserr(handle, section, rrnum, &rr)) {
155 fprintf(file, ";; ns_parserr: %s\n",
157 else if (rrnum > 0 && sflag != 0 &&
158 (_res.pfcode & RES_PRF_HEAD1))
162 if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
163 fprintf(file, ";; %s SECTION:\n",
164 p_section(section, opcode));
165 if (section == ns_s_qd)
166 fprintf(file, ";;\t%s, type = %s, class = %s\n",
168 p_type(ns_rr_type(rr)),
169 p_class(ns_rr_class(rr)));
171 n = ns_sprintrr(handle, &rr, NULL, NULL,
174 fprintf(file, ";; ns_sprintrr: %s\n",
186 p_query(const u_char *msg) {
187 fp_query(msg, stdout);
191 fp_query(const u_char *msg, FILE *file) {
192 fp_nquery(msg, PACKETSZ, file);
196 * Print the contents of a query.
197 * This is intended to be primarily a debugging routine.
200 fp_nquery(const u_char *msg, int len, FILE *file) {
202 int n, qdcount, ancount, nscount, arcount;
203 u_int opcode, rcode, id;
205 if ((_res.options & RES_INIT) == 0 && res_init() == -1)
208 if (ns_initparse(msg, len, &handle) < 0) {
209 fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
212 opcode = ns_msg_getflag(handle, ns_f_opcode);
213 rcode = ns_msg_getflag(handle, ns_f_rcode);
214 id = ns_msg_id(handle);
215 qdcount = ns_msg_count(handle, ns_s_qd);
216 ancount = ns_msg_count(handle, ns_s_an);
217 nscount = ns_msg_count(handle, ns_s_ns);
218 arcount = ns_msg_count(handle, ns_s_ar);
221 * Print header fields.
223 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
225 ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
226 _res_opcodes[opcode], _res_resultcodes[rcode], id);
227 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
229 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
230 fprintf(file, "; flags:");
231 if (ns_msg_getflag(handle, ns_f_qr))
232 fprintf(file, " qr");
233 if (ns_msg_getflag(handle, ns_f_aa))
234 fprintf(file, " aa");
235 if (ns_msg_getflag(handle, ns_f_tc))
236 fprintf(file, " tc");
237 if (ns_msg_getflag(handle, ns_f_rd))
238 fprintf(file, " rd");
239 if (ns_msg_getflag(handle, ns_f_ra))
240 fprintf(file, " ra");
241 if (ns_msg_getflag(handle, ns_f_z))
242 fprintf(file, " ??");
243 if (ns_msg_getflag(handle, ns_f_ad))
244 fprintf(file, " ad");
245 if (ns_msg_getflag(handle, ns_f_cd))
246 fprintf(file, " cd");
248 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
249 fprintf(file, "; %s: %d",
250 p_section(ns_s_qd, opcode), qdcount);
251 fprintf(file, ", %s: %d",
252 p_section(ns_s_an, opcode), ancount);
253 fprintf(file, ", %s: %d",
254 p_section(ns_s_ns, opcode), nscount);
255 fprintf(file, ", %s: %d",
256 p_section(ns_s_ar, opcode), arcount);
258 if ((!_res.pfcode) || (_res.pfcode &
259 (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
263 * Print the various sections.
265 do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
266 do_section(&handle, ns_s_an, RES_PRF_ANS, file);
267 do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
268 do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
269 if (qdcount == 0 && ancount == 0 &&
270 nscount == 0 && arcount == 0)
275 p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
279 if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
289 p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
290 return (p_cdnname(cp, msg, PACKETSZ, file));
293 /* Return a fully-qualified domain name from a compressed name (with
297 p_fqnname(cp, msg, msglen, name, namelen)
298 const u_char *cp, *msg;
305 if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
307 newlen = strlen(name);
308 if (newlen == 0 || name[newlen - 1] != '.') {
309 if (newlen + 1 >= namelen) /* Lack space for final dot */
312 strcpy(name + newlen, ".");
317 /* XXX: the rest of these functions need to become length-limited, too. */
320 p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
324 n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
332 * Names of RR classes and qclasses. Classes and qclasses are the same, except
333 * that C_ANY is a qclass but not a class. (You can ask for records of class
334 * C_ANY, but you can't have any records of that class in the database.)
336 const struct res_sym __p_class_syms[] = {
347 * Names of message sections.
349 const struct res_sym __p_default_section_syms[] = {
352 {ns_s_ns, "AUTHORITY"},
353 {ns_s_ar, "ADDITIONAL"},
357 const struct res_sym __p_update_section_syms[] = {
359 {S_PREREQ, "PREREQUISITE"},
360 {S_UPDATE, "UPDATE"},
361 {S_ADDT, "ADDITIONAL"},
366 * Names of RR types and qtypes. Types and qtypes are the same, except
367 * that T_ANY is a qtype but not a type. (You can ask for records of type
368 * T_ANY, but you can't have any records of that type in the database.)
370 const struct res_sym __p_type_syms[] = {
371 {T_A, "A", "address"},
372 {T_NS, "NS", "name server"},
373 {T_MD, "MD", "mail destination (deprecated)"},
374 {T_MF, "MF", "mail forwarder (deprecated)"},
375 {T_CNAME, "CNAME", "canonical name"},
376 {T_SOA, "SOA", "start of authority"},
377 {T_MB, "MB", "mailbox"},
378 {T_MG, "MG", "mail group member"},
379 {T_MR, "MR", "mail rename"},
380 {T_NULL, "NULL", "null"},
381 {T_WKS, "WKS", "well-known service (deprecated)"},
382 {T_PTR, "PTR", "domain name pointer"},
383 {T_HINFO, "HINFO", "host information"},
384 {T_MINFO, "MINFO", "mailbox information"},
385 {T_MX, "MX", "mail exchanger"},
386 {T_TXT, "TXT", "text"},
387 {T_RP, "RP", "responsible person"},
388 {T_AFSDB, "AFSDB", "DCE or AFS server"},
389 {T_X25, "X25", "X25 address"},
390 {T_ISDN, "ISDN", "ISDN address"},
391 {T_RT, "RT", "router"},
392 {T_NSAP, "NSAP", "nsap address"},
393 {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
394 {T_SIG, "SIG", "signature"},
395 {T_KEY, "KEY", "key"},
396 {T_PX, "PX", "mapping information"},
397 {T_GPOS, "GPOS", "geographical position (withdrawn)"},
398 {T_AAAA, "AAAA", "IPv6 address"},
399 {T_LOC, "LOC", "location"},
400 {T_NXT, "NXT", "next valid name (unimplemented)"},
401 {T_EID, "EID", "endpoint identifier (unimplemented)"},
402 {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
403 {T_SRV, "SRV", "server selection"},
404 {T_ATMA, "ATMA", "ATM address (unimplemented)"},
405 {T_IXFR, "IXFR", "incremental zone transfer"},
406 {T_AXFR, "AXFR", "zone transfer"},
407 {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
408 {T_MAILA, "MAILA", "mail agent (deprecated)"},
409 {T_NAPTR, "NAPTR", "URN Naming Authority"},
410 {T_ANY, "ANY", "\"any\""},
415 sym_ston(const struct res_sym *syms, const char *name, int *success) {
416 for ((void)NULL; syms->name != 0; syms++) {
417 if (strcasecmp (name, syms->name) == 0) {
420 return (syms->number);
425 return (syms->number); /* The default value. */
429 sym_ntos(const struct res_sym *syms, int number, int *success) {
430 static char unname[20];
432 for ((void)NULL; syms->name != 0; syms++) {
433 if (number == syms->number) {
440 sprintf(unname, "%d", number);
447 sym_ntop(const struct res_sym *syms, int number, int *success) {
448 static char unname[20];
450 for ((void)NULL; syms->name != 0; syms++) {
451 if (number == syms->number) {
454 return (syms->humanname);
457 sprintf(unname, "%d", number);
464 * Return a string for the type.
468 return (sym_ntos(__p_type_syms, type, (int *)0));
472 * Return a string for the type.
475 p_section(int section, int opcode) {
476 const struct res_sym *symbols;
480 symbols = __p_update_section_syms;
483 symbols = __p_default_section_syms;
486 return (sym_ntos(symbols, section, (int *)0));
490 * Return a mnemonic for class.
494 return (sym_ntos(__p_class_syms, class, (int *)0));
498 * Return a mnemonic for an option
501 p_option(u_long option) {
502 static char nbuf[40];
505 case RES_INIT: return "init";
506 case RES_DEBUG: return "debug";
507 case RES_AAONLY: return "aaonly(unimpl)";
508 case RES_USEVC: return "usevc";
509 case RES_PRIMARY: return "primry(unimpl)";
510 case RES_IGNTC: return "igntc";
511 case RES_RECURSE: return "recurs";
512 case RES_DEFNAMES: return "defnam";
513 case RES_STAYOPEN: return "styopn";
514 case RES_DNSRCH: return "dnsrch";
515 case RES_INSECURE1: return "insecure1";
516 case RES_INSECURE2: return "insecure2";
517 case RES_NOALIASES: return "noaliases";
518 case RES_USE_INET6: return "inet6";
519 case RES_NOTLDQUERY: return "no-tld-query";
520 case RES_USE_EDNS0: return "edns0";
521 default: sprintf(nbuf, "?0x%lx?", (u_long)option);
527 * Return a mnemonic for a time to live.
530 p_time(u_int32_t value) {
531 static char nbuf[40];
533 if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
534 sprintf(nbuf, "%u", value);
540 * routines to convert between on-the-wire RR format and zone file format.
541 * Does not contain conversion to/from decimal degrees; divide or multiply
542 * by 60*60*1000 for that.
545 static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
546 1000000,10000000,100000000,1000000000};
548 /* takes an XeY precision/size value, returns a string representation. */
553 static char retbuf[sizeof "90000000.00"];
555 int mantissa, exponent;
557 mantissa = (int)((prec >> 4) & 0x0f) % 10;
558 exponent = (int)((prec >> 0) & 0x0f) % 10;
560 val = mantissa * poweroften[exponent];
562 (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
566 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
568 precsize_aton(strptr)
571 unsigned int mval = 0, cmval = 0;
579 while (isdigit((unsigned char)*cp))
580 mval = mval * 10 + (*cp++ - '0');
582 if (*cp == '.') { /* centimeters */
584 if (isdigit((unsigned char)*cp)) {
585 cmval = (*cp++ - '0') * 10;
586 if (isdigit((unsigned char)*cp)) {
587 cmval += (*cp++ - '0');
591 cmval = (mval * 100) + cmval;
593 for (exponent = 0; exponent < 9; exponent++)
594 if (cmval < poweroften[exponent+1])
597 mantissa = cmval / poweroften[exponent];
601 retval = (mantissa << 4) | exponent;
608 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
610 latlon2ul(latlonstrptr,which)
616 int deg = 0, min = 0, secs = 0, secsfrac = 0;
620 while (isdigit((unsigned char)*cp))
621 deg = deg * 10 + (*cp++ - '0');
623 while (isspace((unsigned char)*cp))
626 if (!(isdigit((unsigned char)*cp)))
629 while (isdigit((unsigned char)*cp))
630 min = min * 10 + (*cp++ - '0');
632 while (isspace((unsigned char)*cp))
635 if (!(isdigit((unsigned char)*cp)))
638 while (isdigit((unsigned char)*cp))
639 secs = secs * 10 + (*cp++ - '0');
641 if (*cp == '.') { /* decimal seconds */
643 if (isdigit((unsigned char)*cp)) {
644 secsfrac = (*cp++ - '0') * 100;
645 if (isdigit((unsigned char)*cp)) {
646 secsfrac += (*cp++ - '0') * 10;
647 if (isdigit((unsigned char)*cp)) {
648 secsfrac += (*cp++ - '0');
654 while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
657 while (isspace((unsigned char)*cp))
664 retval = ((unsigned)1<<31)
665 + (((((deg * 60) + min) * 60) + secs) * 1000)
670 retval = ((unsigned)1<<31)
671 - (((((deg * 60) + min) * 60) + secs) * 1000)
675 retval = 0; /* invalid value -- indicates error */
682 *which = 1; /* latitude */
686 *which = 2; /* longitude */
689 *which = 0; /* error */
693 cp++; /* skip the hemisphere */
695 while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
698 while (isspace((unsigned char)*cp)) /* move to next field */
706 /* converts a zone file representation in a string to an RDATA on-the-wire
709 loc_aton(ascii, binary)
713 const char *cp, *maxcp;
716 u_int32_t latit = 0, longit = 0, alt = 0;
717 u_int32_t lltemp1 = 0, lltemp2 = 0;
718 int altmeters = 0, altfrac = 0, altsign = 1;
719 u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
720 u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
721 u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
722 int which1 = 0, which2 = 0;
725 maxcp = cp + strlen(ascii);
727 lltemp1 = latlon2ul(&cp, &which1);
729 lltemp2 = latlon2ul(&cp, &which2);
731 switch (which1 + which2) {
732 case 3: /* 1 + 2, the only valid combination */
733 if ((which1 == 1) && (which2 == 2)) { /* normal case */
736 } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
739 } else { /* some kind of brokenness */
743 default: /* we didn't get one of each */
756 while (isdigit((unsigned char)*cp))
757 altmeters = altmeters * 10 + (*cp++ - '0');
759 if (*cp == '.') { /* decimal meters */
761 if (isdigit((unsigned char)*cp)) {
762 altfrac = (*cp++ - '0') * 10;
763 if (isdigit((unsigned char)*cp)) {
764 altfrac += (*cp++ - '0');
769 alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
771 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
774 while (isspace((unsigned char)*cp) && (cp < maxcp))
780 siz = precsize_aton(&cp);
782 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
785 while (isspace((unsigned char)*cp) && (cp < maxcp))
791 hp = precsize_aton(&cp);
793 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
796 while (isspace((unsigned char)*cp) && (cp < maxcp))
802 vp = precsize_aton(&cp);
807 *bcp++ = (u_int8_t) 0; /* version byte */
815 return (16); /* size of RR in octets */
818 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
820 loc_ntoa(binary, ascii)
821 const u_char *binary;
824 static char *error = "?";
825 const u_char *cp = binary;
827 int latdeg, latmin, latsec, latsecfrac;
828 int longdeg, longmin, longsec, longsecfrac;
829 char northsouth, eastwest;
830 int altmeters, altfrac, altsign;
832 const u_int32_t referencealt = 100000 * 100;
834 int32_t latval, longval, altval;
836 u_int8_t sizeval, hpval, vpval, versionval;
838 char *sizestr, *hpstr, *vpstr;
843 (void) sprintf(ascii, "; error: unknown LOC RR version");
853 latval = (templ - ((unsigned)1<<31));
856 longval = (templ - ((unsigned)1<<31));
859 if (templ < referencealt) { /* below WGS 84 spheroid */
860 altval = referencealt - templ;
863 altval = templ - referencealt;
873 latsecfrac = latval % 1000;
874 latval = latval / 1000;
875 latsec = latval % 60;
876 latval = latval / 60;
877 latmin = latval % 60;
878 latval = latval / 60;
887 longsecfrac = longval % 1000;
888 longval = longval / 1000;
889 longsec = longval % 60;
890 longval = longval / 60;
891 longmin = longval % 60;
892 longval = longval / 60;
895 altfrac = altval % 100;
896 altmeters = (altval / 100) * altsign;
898 if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
900 if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
902 if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
906 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
907 latdeg, latmin, latsec, latsecfrac, northsouth,
908 longdeg, longmin, longsec, longsecfrac, eastwest,
909 altmeters, altfrac, sizestr, hpstr, vpstr);
911 if (sizestr != error)
922 /* Return the number of DNS hierarchy levels in the name. */
924 dn_count_labels(const char *name) {
928 for (i = 0, count = 0; i < len; i++) {
929 /* XXX need to check for \. or use named's nlabels(). */
934 /* don't count initial wildcard */
939 /* don't count the null label for root. */
940 /* if terminating '.' not found, must adjust */
941 /* count to include last label */
942 if (len > 0 && name[len-1] != '.')
949 * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
950 * SIG records are required to be printed like this, by the Secure DNS RFC.
953 p_secstodate (u_long secs) {
954 static char output[15]; /* YYYYMMDDHHMMSS and null */
958 time = gmtime(&clock);
959 time->tm_year += 1900;
961 sprintf(output, "%04d%02d%02d%02d%02d%02d",
962 time->tm_year, time->tm_mon, time->tm_mday,
963 time->tm_hour, time->tm_min, time->tm_sec);
968 * Weak aliases for applications that use certain private entry points,
969 * and fail to include <resolv.h>.
972 __weak_reference(__fp_resstat, fp_resstat);
974 __weak_reference(__p_query, p_query);
976 __weak_reference(__p_fqnname, p_fqnname);
978 __weak_reference(__sym_ston, sym_ston);
980 __weak_reference(__sym_ntos, sym_ntos);
982 __weak_reference(__sym_ntop, sym_ntop);
983 #undef dn_count_labels
984 __weak_reference(__dn_count_labels, dn_count_labels);
986 __weak_reference(__p_secstodate, p_secstodate);