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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)res_debug.c 8.1 (Berkeley) 6/4/93
34 * $FreeBSD: src/lib/libc/net/res_debug.c,v 1.18.2.1 2001/06/15 22:08:28 ume Exp $
35 * $DragonFly: src/lib/libcr/net/Attic/res_debug.c,v 1.2 2003/06/17 04:26:44 dillon Exp $
39 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
41 * Permission to use, copy, modify, and distribute this software for any
42 * purpose with or without fee is hereby granted, provided that the above
43 * copyright notice and this permission notice appear in all copies, and that
44 * the name of Digital Equipment Corporation not be used in advertising or
45 * publicity pertaining to distribution of the document or software without
46 * specific, written prior permission.
48 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
49 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
50 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
51 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
52 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
53 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
54 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
59 * Portions Copyright (c) 1995 by International Business Machines, Inc.
61 * International Business Machines, Inc. (hereinafter called IBM) grants
62 * permission under its copyrights to use, copy, modify, and distribute this
63 * Software with or without fee, provided that the above copyright notice and
64 * all paragraphs of this notice appear in all copies, and that the name of IBM
65 * not be used in connection with the marketing of any product incorporating
66 * the Software or modifications thereof, without specific, written prior
69 * To the extent it has a right to do so, IBM grants an immunity from suit
70 * under its patents, if any, for the use, sale or manufacture of products to
71 * the extent that such products are used for performing Domain Name System
72 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
73 * granted for any product per se or for any other function of any product.
75 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
76 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
77 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
78 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
79 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
80 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
84 * Portions Copyright (c) 1996 by Internet Software Consortium.
86 * Permission to use, copy, modify, and distribute this software for any
87 * purpose with or without fee is hereby granted, provided that the above
88 * copyright notice and this permission notice appear in all copies.
90 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
91 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
92 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
93 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
94 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
95 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
96 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
100 #include <sys/types.h>
101 #include <sys/param.h>
102 #include <sys/socket.h>
104 #include <netinet/in.h>
105 #include <arpa/inet.h>
106 #include <arpa/nameser.h>
118 #define SPRINTF(x) sprintf x
120 extern const char *_res_opcodes[];
121 extern const char *_res_resultcodes[];
122 extern const char *_res_sectioncodes[];
125 * Print the current options.
128 fp_resstat(struct __res_state *statp, FILE *file) {
131 fprintf(file, ";; res options:");
134 for (mask = 1; mask != 0; mask <<= 1)
135 if (statp->options & mask)
136 fprintf(file, " %s", p_option(mask));
141 do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
143 char buf[2048]; /* XXX need to malloc */
148 * Print answer records.
150 sflag = (_res.pfcode & pflag);
151 if (_res.pfcode && !sflag)
154 opcode = ns_msg_getflag(*handle, ns_f_opcode);
157 if (ns_parserr(handle, section, rrnum, &rr)) {
159 fprintf(file, ";; ns_parserr: %s\n",
161 else if (rrnum > 0 && sflag != 0 &&
162 (_res.pfcode & RES_PRF_HEAD1))
166 if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
167 fprintf(file, ";; %s SECTION:\n",
168 p_section(section, opcode));
169 if (section == ns_s_qd)
170 fprintf(file, ";;\t%s, type = %s, class = %s\n",
172 p_type(ns_rr_type(rr)),
173 p_class(ns_rr_class(rr)));
175 n = ns_sprintrr(handle, &rr, NULL, NULL,
178 fprintf(file, ";; ns_sprintrr: %s\n",
190 p_query(const u_char *msg) {
191 fp_query(msg, stdout);
195 fp_query(const u_char *msg, FILE *file) {
196 fp_nquery(msg, PACKETSZ, file);
200 * Print the contents of a query.
201 * This is intended to be primarily a debugging routine.
204 fp_nquery(const u_char *msg, int len, FILE *file) {
206 int n, qdcount, ancount, nscount, arcount;
207 u_int opcode, rcode, id;
209 if ((_res.options & RES_INIT) == 0 && res_init() == -1)
212 if (ns_initparse(msg, len, &handle) < 0) {
213 fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
216 opcode = ns_msg_getflag(handle, ns_f_opcode);
217 rcode = ns_msg_getflag(handle, ns_f_rcode);
218 id = ns_msg_id(handle);
219 qdcount = ns_msg_count(handle, ns_s_qd);
220 ancount = ns_msg_count(handle, ns_s_an);
221 nscount = ns_msg_count(handle, ns_s_ns);
222 arcount = ns_msg_count(handle, ns_s_ar);
225 * Print header fields.
227 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
229 ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
230 _res_opcodes[opcode], _res_resultcodes[rcode], id);
231 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
233 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
234 fprintf(file, "; flags:");
235 if (ns_msg_getflag(handle, ns_f_qr))
236 fprintf(file, " qr");
237 if (ns_msg_getflag(handle, ns_f_aa))
238 fprintf(file, " aa");
239 if (ns_msg_getflag(handle, ns_f_tc))
240 fprintf(file, " tc");
241 if (ns_msg_getflag(handle, ns_f_rd))
242 fprintf(file, " rd");
243 if (ns_msg_getflag(handle, ns_f_ra))
244 fprintf(file, " ra");
245 if (ns_msg_getflag(handle, ns_f_z))
246 fprintf(file, " ??");
247 if (ns_msg_getflag(handle, ns_f_ad))
248 fprintf(file, " ad");
249 if (ns_msg_getflag(handle, ns_f_cd))
250 fprintf(file, " cd");
252 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
253 fprintf(file, "; %s: %d",
254 p_section(ns_s_qd, opcode), qdcount);
255 fprintf(file, ", %s: %d",
256 p_section(ns_s_an, opcode), ancount);
257 fprintf(file, ", %s: %d",
258 p_section(ns_s_ns, opcode), nscount);
259 fprintf(file, ", %s: %d",
260 p_section(ns_s_ar, opcode), arcount);
262 if ((!_res.pfcode) || (_res.pfcode &
263 (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
267 * Print the various sections.
269 do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
270 do_section(&handle, ns_s_an, RES_PRF_ANS, file);
271 do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
272 do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
273 if (qdcount == 0 && ancount == 0 &&
274 nscount == 0 && arcount == 0)
279 p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
283 if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
293 p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
294 return (p_cdnname(cp, msg, PACKETSZ, file));
297 /* Return a fully-qualified domain name from a compressed name (with
301 p_fqnname(cp, msg, msglen, name, namelen)
302 const u_char *cp, *msg;
309 if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
311 newlen = strlen(name);
312 if (newlen == 0 || name[newlen - 1] != '.') {
313 if (newlen + 1 >= namelen) /* Lack space for final dot */
316 strcpy(name + newlen, ".");
321 /* XXX: the rest of these functions need to become length-limited, too. */
324 p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
328 n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
336 * Names of RR classes and qclasses. Classes and qclasses are the same, except
337 * that C_ANY is a qclass but not a class. (You can ask for records of class
338 * C_ANY, but you can't have any records of that class in the database.)
340 const struct res_sym __p_class_syms[] = {
351 * Names of message sections.
353 const struct res_sym __p_default_section_syms[] = {
356 {ns_s_ns, "AUTHORITY"},
357 {ns_s_ar, "ADDITIONAL"},
361 const struct res_sym __p_update_section_syms[] = {
363 {S_PREREQ, "PREREQUISITE"},
364 {S_UPDATE, "UPDATE"},
365 {S_ADDT, "ADDITIONAL"},
370 * Names of RR types and qtypes. Types and qtypes are the same, except
371 * that T_ANY is a qtype but not a type. (You can ask for records of type
372 * T_ANY, but you can't have any records of that type in the database.)
374 const struct res_sym __p_type_syms[] = {
375 {T_A, "A", "address"},
376 {T_NS, "NS", "name server"},
377 {T_MD, "MD", "mail destination (deprecated)"},
378 {T_MF, "MF", "mail forwarder (deprecated)"},
379 {T_CNAME, "CNAME", "canonical name"},
380 {T_SOA, "SOA", "start of authority"},
381 {T_MB, "MB", "mailbox"},
382 {T_MG, "MG", "mail group member"},
383 {T_MR, "MR", "mail rename"},
384 {T_NULL, "NULL", "null"},
385 {T_WKS, "WKS", "well-known service (deprecated)"},
386 {T_PTR, "PTR", "domain name pointer"},
387 {T_HINFO, "HINFO", "host information"},
388 {T_MINFO, "MINFO", "mailbox information"},
389 {T_MX, "MX", "mail exchanger"},
390 {T_TXT, "TXT", "text"},
391 {T_RP, "RP", "responsible person"},
392 {T_AFSDB, "AFSDB", "DCE or AFS server"},
393 {T_X25, "X25", "X25 address"},
394 {T_ISDN, "ISDN", "ISDN address"},
395 {T_RT, "RT", "router"},
396 {T_NSAP, "NSAP", "nsap address"},
397 {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
398 {T_SIG, "SIG", "signature"},
399 {T_KEY, "KEY", "key"},
400 {T_PX, "PX", "mapping information"},
401 {T_GPOS, "GPOS", "geographical position (withdrawn)"},
402 {T_AAAA, "AAAA", "IPv6 address"},
403 {T_LOC, "LOC", "location"},
404 {T_NXT, "NXT", "next valid name (unimplemented)"},
405 {T_EID, "EID", "endpoint identifier (unimplemented)"},
406 {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
407 {T_SRV, "SRV", "server selection"},
408 {T_ATMA, "ATMA", "ATM address (unimplemented)"},
409 {T_IXFR, "IXFR", "incremental zone transfer"},
410 {T_AXFR, "AXFR", "zone transfer"},
411 {T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
412 {T_MAILA, "MAILA", "mail agent (deprecated)"},
413 {T_NAPTR, "NAPTR", "URN Naming Authority"},
414 {T_ANY, "ANY", "\"any\""},
419 sym_ston(const struct res_sym *syms, const char *name, int *success) {
420 for ((void)NULL; syms->name != 0; syms++) {
421 if (strcasecmp (name, syms->name) == 0) {
424 return (syms->number);
429 return (syms->number); /* The default value. */
433 sym_ntos(const struct res_sym *syms, int number, int *success) {
434 static char unname[20];
436 for ((void)NULL; syms->name != 0; syms++) {
437 if (number == syms->number) {
444 sprintf(unname, "%d", number);
451 sym_ntop(const struct res_sym *syms, int number, int *success) {
452 static char unname[20];
454 for ((void)NULL; syms->name != 0; syms++) {
455 if (number == syms->number) {
458 return (syms->humanname);
461 sprintf(unname, "%d", number);
468 * Return a string for the type.
472 return (sym_ntos(__p_type_syms, type, (int *)0));
476 * Return a string for the type.
479 p_section(int section, int opcode) {
480 const struct res_sym *symbols;
484 symbols = __p_update_section_syms;
487 symbols = __p_default_section_syms;
490 return (sym_ntos(symbols, section, (int *)0));
494 * Return a mnemonic for class.
498 return (sym_ntos(__p_class_syms, class, (int *)0));
502 * Return a mnemonic for an option
505 p_option(u_long option) {
506 static char nbuf[40];
509 case RES_INIT: return "init";
510 case RES_DEBUG: return "debug";
511 case RES_AAONLY: return "aaonly(unimpl)";
512 case RES_USEVC: return "usevc";
513 case RES_PRIMARY: return "primry(unimpl)";
514 case RES_IGNTC: return "igntc";
515 case RES_RECURSE: return "recurs";
516 case RES_DEFNAMES: return "defnam";
517 case RES_STAYOPEN: return "styopn";
518 case RES_DNSRCH: return "dnsrch";
519 case RES_INSECURE1: return "insecure1";
520 case RES_INSECURE2: return "insecure2";
521 case RES_NOALIASES: return "noaliases";
522 case RES_USE_INET6: return "inet6";
523 case RES_NOTLDQUERY: return "no-tld-query";
524 case RES_USE_EDNS0: return "edns0";
525 default: sprintf(nbuf, "?0x%lx?", (u_long)option);
531 * Return a mnemonic for a time to live.
534 p_time(u_int32_t value) {
535 static char nbuf[40];
537 if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
538 sprintf(nbuf, "%u", value);
544 * routines to convert between on-the-wire RR format and zone file format.
545 * Does not contain conversion to/from decimal degrees; divide or multiply
546 * by 60*60*1000 for that.
549 static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
550 1000000,10000000,100000000,1000000000};
552 /* takes an XeY precision/size value, returns a string representation. */
557 static char retbuf[sizeof "90000000.00"];
559 int mantissa, exponent;
561 mantissa = (int)((prec >> 4) & 0x0f) % 10;
562 exponent = (int)((prec >> 0) & 0x0f) % 10;
564 val = mantissa * poweroften[exponent];
566 (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
570 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
572 precsize_aton(strptr)
575 unsigned int mval = 0, cmval = 0;
583 while (isdigit((unsigned char)*cp))
584 mval = mval * 10 + (*cp++ - '0');
586 if (*cp == '.') { /* centimeters */
588 if (isdigit((unsigned char)*cp)) {
589 cmval = (*cp++ - '0') * 10;
590 if (isdigit((unsigned char)*cp)) {
591 cmval += (*cp++ - '0');
595 cmval = (mval * 100) + cmval;
597 for (exponent = 0; exponent < 9; exponent++)
598 if (cmval < poweroften[exponent+1])
601 mantissa = cmval / poweroften[exponent];
605 retval = (mantissa << 4) | exponent;
612 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
614 latlon2ul(latlonstrptr,which)
620 int deg = 0, min = 0, secs = 0, secsfrac = 0;
624 while (isdigit((unsigned char)*cp))
625 deg = deg * 10 + (*cp++ - '0');
627 while (isspace((unsigned char)*cp))
630 if (!(isdigit((unsigned char)*cp)))
633 while (isdigit((unsigned char)*cp))
634 min = min * 10 + (*cp++ - '0');
636 while (isspace((unsigned char)*cp))
639 if (!(isdigit((unsigned char)*cp)))
642 while (isdigit((unsigned char)*cp))
643 secs = secs * 10 + (*cp++ - '0');
645 if (*cp == '.') { /* decimal seconds */
647 if (isdigit((unsigned char)*cp)) {
648 secsfrac = (*cp++ - '0') * 100;
649 if (isdigit((unsigned char)*cp)) {
650 secsfrac += (*cp++ - '0') * 10;
651 if (isdigit((unsigned char)*cp)) {
652 secsfrac += (*cp++ - '0');
658 while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
661 while (isspace((unsigned char)*cp))
668 retval = ((unsigned)1<<31)
669 + (((((deg * 60) + min) * 60) + secs) * 1000)
674 retval = ((unsigned)1<<31)
675 - (((((deg * 60) + min) * 60) + secs) * 1000)
679 retval = 0; /* invalid value -- indicates error */
686 *which = 1; /* latitude */
690 *which = 2; /* longitude */
693 *which = 0; /* error */
697 cp++; /* skip the hemisphere */
699 while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
702 while (isspace((unsigned char)*cp)) /* move to next field */
710 /* converts a zone file representation in a string to an RDATA on-the-wire
713 loc_aton(ascii, binary)
717 const char *cp, *maxcp;
720 u_int32_t latit = 0, longit = 0, alt = 0;
721 u_int32_t lltemp1 = 0, lltemp2 = 0;
722 int altmeters = 0, altfrac = 0, altsign = 1;
723 u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
724 u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
725 u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
726 int which1 = 0, which2 = 0;
729 maxcp = cp + strlen(ascii);
731 lltemp1 = latlon2ul(&cp, &which1);
733 lltemp2 = latlon2ul(&cp, &which2);
735 switch (which1 + which2) {
736 case 3: /* 1 + 2, the only valid combination */
737 if ((which1 == 1) && (which2 == 2)) { /* normal case */
740 } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
743 } else { /* some kind of brokenness */
747 default: /* we didn't get one of each */
760 while (isdigit((unsigned char)*cp))
761 altmeters = altmeters * 10 + (*cp++ - '0');
763 if (*cp == '.') { /* decimal meters */
765 if (isdigit((unsigned char)*cp)) {
766 altfrac = (*cp++ - '0') * 10;
767 if (isdigit((unsigned char)*cp)) {
768 altfrac += (*cp++ - '0');
773 alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
775 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
778 while (isspace((unsigned char)*cp) && (cp < maxcp))
784 siz = precsize_aton(&cp);
786 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
789 while (isspace((unsigned char)*cp) && (cp < maxcp))
795 hp = precsize_aton(&cp);
797 while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
800 while (isspace((unsigned char)*cp) && (cp < maxcp))
806 vp = precsize_aton(&cp);
811 *bcp++ = (u_int8_t) 0; /* version byte */
819 return (16); /* size of RR in octets */
822 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
824 loc_ntoa(binary, ascii)
825 const u_char *binary;
828 static char *error = "?";
829 const u_char *cp = binary;
831 int latdeg, latmin, latsec, latsecfrac;
832 int longdeg, longmin, longsec, longsecfrac;
833 char northsouth, eastwest;
834 int altmeters, altfrac, altsign;
836 const u_int32_t referencealt = 100000 * 100;
838 int32_t latval, longval, altval;
840 u_int8_t sizeval, hpval, vpval, versionval;
842 char *sizestr, *hpstr, *vpstr;
847 (void) sprintf(ascii, "; error: unknown LOC RR version");
857 latval = (templ - ((unsigned)1<<31));
860 longval = (templ - ((unsigned)1<<31));
863 if (templ < referencealt) { /* below WGS 84 spheroid */
864 altval = referencealt - templ;
867 altval = templ - referencealt;
877 latsecfrac = latval % 1000;
878 latval = latval / 1000;
879 latsec = latval % 60;
880 latval = latval / 60;
881 latmin = latval % 60;
882 latval = latval / 60;
891 longsecfrac = longval % 1000;
892 longval = longval / 1000;
893 longsec = longval % 60;
894 longval = longval / 60;
895 longmin = longval % 60;
896 longval = longval / 60;
899 altfrac = altval % 100;
900 altmeters = (altval / 100) * altsign;
902 if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
904 if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
906 if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
910 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
911 latdeg, latmin, latsec, latsecfrac, northsouth,
912 longdeg, longmin, longsec, longsecfrac, eastwest,
913 altmeters, altfrac, sizestr, hpstr, vpstr);
915 if (sizestr != error)
926 /* Return the number of DNS hierarchy levels in the name. */
928 dn_count_labels(const char *name) {
932 for (i = 0, count = 0; i < len; i++) {
933 /* XXX need to check for \. or use named's nlabels(). */
938 /* don't count initial wildcard */
943 /* don't count the null label for root. */
944 /* if terminating '.' not found, must adjust */
945 /* count to include last label */
946 if (len > 0 && name[len-1] != '.')
953 * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
954 * SIG records are required to be printed like this, by the Secure DNS RFC.
957 p_secstodate (u_long secs) {
958 static char output[15]; /* YYYYMMDDHHMMSS and null */
962 time = gmtime(&clock);
963 time->tm_year += 1900;
965 sprintf(output, "%04d%02d%02d%02d%02d%02d",
966 time->tm_year, time->tm_mon, time->tm_mday,
967 time->tm_hour, time->tm_min, time->tm_sec);
972 * Weak aliases for applications that use certain private entry points,
973 * and fail to include <resolv.h>.
976 __weak_reference(__fp_resstat, fp_resstat);
978 __weak_reference(__p_query, p_query);
980 __weak_reference(__p_fqnname, p_fqnname);
982 __weak_reference(__sym_ston, sym_ston);
984 __weak_reference(__sym_ntos, sym_ntos);
986 __weak_reference(__sym_ntop, sym_ntop);
987 #undef dn_count_labels
988 __weak_reference(__dn_count_labels, dn_count_labels);
990 __weak_reference(__p_secstodate, p_secstodate);