2 * ++Copyright++ 1985, 1990, 1993
4 * Copyright (c) 1985, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
33 * Permission to use, copy, modify, and distribute this software for any
34 * purpose with or without fee is hereby granted, provided that the above
35 * copyright notice and this permission notice appear in all copies, and that
36 * the name of Digital Equipment Corporation not be used in advertising or
37 * publicity pertaining to distribution of the document or software without
38 * specific, written prior permission.
40 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
41 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
43 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
44 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
45 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
46 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 * Portions Copyright (c) 1995 by International Business Machines, Inc.
51 * International Business Machines, Inc. (hereinafter called IBM) grants
52 * permission under its copyrights to use, copy, modify, and distribute this
53 * Software with or without fee, provided that the above copyright notice and
54 * all paragraphs of this notice appear in all copies, and that the name of IBM
55 * not be used in connection with the marketing of any product incorporating
56 * the Software or modifications thereof, without specific, written prior
59 * To the extent it has a right to do so, IBM grants an immunity from suit
60 * under its patents, if any, for the use, sale or manufacture of products to
61 * the extent that such products are used for performing Domain Name System
62 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
63 * granted for any product per se or for any other function of any product.
65 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
66 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
67 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
68 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
69 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
70 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
74 #if defined(LIBC_SCCS) && !defined(lint)
75 static char sccsid
[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
76 static char rcsid
[] = "$Id$";
77 #endif /* LIBC_SCCS and not lint */
79 #include <sys/param.h>
80 #include <sys/types.h>
81 #include <sys/socket.h>
82 #include <netinet/in.h>
83 #include <arpa/inet.h>
84 #include <arpa/nameser.h>
92 #if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
96 # include "../conf/portability.h"
99 #if defined(USE_OPTIONS_H)
100 # include "../conf/options.h"
103 extern const char *_res_opcodes
[];
104 extern const char *_res_resultcodes
[];
106 /* XXX: we should use getservbyport() instead. */
111 static char nbuf
[20];
114 case 5: return "rje";
115 case 7: return "echo";
116 case 9: return "discard";
117 case 11: return "systat";
118 case 13: return "daytime";
119 case 15: return "netstat";
120 case 17: return "qotd";
121 case 19: return "chargen";
122 case 20: return "ftp-data";
123 case 21: return "ftp";
124 case 23: return "telnet";
125 case 25: return "smtp";
126 case 37: return "time";
127 case 39: return "rlp";
128 case 42: return "name";
129 case 43: return "whois";
130 case 53: return "domain";
131 case 57: return "apts";
132 case 59: return "apfs";
133 case 67: return "bootps";
134 case 68: return "bootpc";
135 case 69: return "tftp";
136 case 77: return "rje";
137 case 79: return "finger";
138 case 87: return "link";
139 case 95: return "supdup";
140 case 100: return "newacct";
141 case 101: return "hostnames";
142 case 102: return "iso-tsap";
143 case 103: return "x400";
144 case 104: return "x400-snd";
145 case 105: return "csnet-ns";
146 case 109: return "pop-2";
147 case 111: return "sunrpc";
148 case 113: return "auth";
149 case 115: return "sftp";
150 case 117: return "uucp-path";
151 case 119: return "nntp";
152 case 121: return "erpc";
153 case 123: return "ntp";
154 case 133: return "statsrv";
155 case 136: return "profile";
156 case 144: return "NeWS";
157 case 161: return "snmp";
158 case 162: return "snmp-trap";
159 case 170: return "print-srv";
160 default: (void) sprintf(nbuf
, "%d", wks
); return (nbuf
);
164 /* XXX: we should use getprotobynumber() instead. */
169 static char nbuf
[20];
172 case 1: return "icmp";
173 case 2: return "igmp";
174 case 3: return "ggp";
176 case 6: return "tcp";
177 case 7: return "ucl";
178 case 8: return "egp";
179 case 9: return "igp";
180 case 11: return "nvp-II";
181 case 12: return "pup";
182 case 16: return "chaos";
183 case 17: return "udp";
184 default: (void) sprintf(nbuf
, "%d", protonum
); return (nbuf
);
188 static const u_char
*
189 do_rrset(msg
, len
, cp
, cnt
, pflag
, file
, hs
)
191 const u_char
*cp
, *msg
;
199 * Print answer records.
201 sflag
= (_res
.pfcode
& pflag
);
202 if ((n
= ntohs(cnt
))) {
203 if ((!_res
.pfcode
) ||
204 ((sflag
) && (_res
.pfcode
& RES_PRF_HEAD1
)))
207 if ((!_res
.pfcode
) || sflag
) {
208 cp
= p_rr(cp
, msg
, file
);
211 cp
+= __dn_skipname(cp
, cp
+ MAXCDNAME
);
215 dlen
= _getshort((u_char
*)cp
);
219 if ((cp
- msg
) > len
)
222 if ((!_res
.pfcode
) ||
223 ((sflag
) && (_res
.pfcode
& RES_PRF_HEAD1
)))
233 __fp_query(msg
, stdout
);
238 /* ultrix 4.0's packaging has some icky packaging. alias for it here.
239 * there is more junk of this kind over in res_comp.c.
250 * Print the current options.
251 * This is intended to be primarily a debugging routine.
254 __fp_resstat(statp
, file
)
255 struct __res_state
*statp
;
258 register u_long mask
;
260 fprintf(file
, ";; res options:");
263 for (mask
= 1; mask
!= 0; mask
<<= 1)
264 if (statp
->options
& mask
)
265 fprintf(file
, " %s", p_option(mask
));
270 * Print the contents of a query.
271 * This is intended to be primarily a debugging routine.
274 __fp_nquery(msg
, len
, file
)
279 register const u_char
*cp
, *endMark
;
280 register const HEADER
*hp
;
283 if ((_res
.options
& RES_INIT
) == 0 && res_init() == -1)
286 #define TruncTest(x) if (x > endMark) goto trunc
287 #define ErrorTest(x) if (x == NULL) goto error
290 * Print header fields.
295 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
) || hp
->rcode
) {
296 fprintf(file
, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
297 _res_opcodes
[hp
->opcode
],
298 _res_resultcodes
[hp
->rcode
],
302 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
))
304 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD2
)) {
305 fprintf(file
, "; flags:");
307 fprintf(file
, " qr");
309 fprintf(file
, " aa");
311 fprintf(file
, " tc");
313 fprintf(file
, " rd");
315 fprintf(file
, " ra");
317 fprintf(file
, " UNUSED-BIT-ON");
319 fprintf(file
, " ad");
321 fprintf(file
, " cd");
323 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD1
)) {
324 fprintf(file
, "; Ques: %d", ntohs(hp
->qdcount
));
325 fprintf(file
, ", Ans: %d", ntohs(hp
->ancount
));
326 fprintf(file
, ", Auth: %d", ntohs(hp
->nscount
));
327 fprintf(file
, ", Addit: %d", ntohs(hp
->arcount
));
329 if ((!_res
.pfcode
) || (_res
.pfcode
&
330 (RES_PRF_HEADX
| RES_PRF_HEAD2
| RES_PRF_HEAD1
))) {
334 * Print question records.
336 if ((n
= ntohs(hp
->qdcount
))) {
337 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
338 fprintf(file
, ";; QUESTIONS:\n");
340 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
341 fprintf(file
, ";;\t");
343 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
344 cp
= p_cdnname(cp
, msg
, len
, file
);
349 if ((n
= dn_expand(msg
, msg
+len
, cp
, name
,
357 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
358 fprintf(file
, ", type = %s",
359 __p_type(_getshort((u_char
*)cp
)));
362 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
363 fprintf(file
, ", class = %s\n",
364 __p_class(_getshort((u_char
*)cp
)));
366 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_QUES
))
371 * Print authoritative answer records
374 cp
= do_rrset(msg
, len
, cp
, hp
->ancount
, RES_PRF_ANS
, file
,
379 * print name server records
382 cp
= do_rrset(msg
, len
, cp
, hp
->nscount
, RES_PRF_AUTH
, file
,
383 ";; AUTHORITY RECORDS:\n");
388 * print additional records
390 cp
= do_rrset(msg
, len
, cp
, hp
->arcount
, RES_PRF_ADD
, file
,
391 ";; ADDITIONAL RECORDS:\n");
395 fprintf(file
, "\n;; ...truncated\n");
398 fprintf(file
, "\n;; ...malformed\n");
402 __fp_query(msg
, file
)
406 fp_nquery(msg
, PACKETSZ
, file
);
410 __p_cdnname(cp
, msg
, len
, file
)
411 const u_char
*cp
, *msg
;
418 if ((n
= dn_expand(msg
, msg
+ len
, cp
, name
, sizeof name
)) < 0)
428 __p_cdname(cp
, msg
, file
)
429 const u_char
*cp
, *msg
;
432 return (p_cdnname(cp
, msg
, PACKETSZ
, file
));
436 /* Return a fully-qualified domain name from a compressed name (with
440 __p_fqnname(cp
, msg
, msglen
, name
, namelen
)
441 const u_char
*cp
, *msg
;
448 if ((n
= dn_expand(msg
, cp
+ msglen
, cp
, name
, namelen
)) < 0)
450 newlen
= strlen (name
);
451 if (newlen
== 0 || name
[newlen
- 1] != '.') {
452 if (newlen
+1 >= namelen
) /* Lack space for final dot */
455 strcpy(name
+ newlen
, ".");
460 /* XXX: the rest of these functions need to become length-limited, too. (vix)
464 __p_fqname(cp
, msg
, file
)
465 const u_char
*cp
, *msg
;
471 n
= __p_fqnname(cp
, msg
, MAXCDNAME
, name
, sizeof name
);
479 * Print resource record fields in human readable form.
482 __p_rr(cp
, msg
, file
)
483 const u_char
*cp
, *msg
;
486 int type
, class, dlen
, n
, c
;
487 struct in_addr inaddr
;
488 const u_char
*cp1
, *cp2
;
492 char rrname
[MAXDNAME
]; /* The fqdn of this RR */
493 char base64_key
[MAX_KEY_BASE64
];
495 if ((_res
.options
& RES_INIT
) == 0 && res_init() == -1) {
496 __set_h_errno (NETDB_INTERNAL
);
499 cp
= __p_fqnname(cp
, msg
, MAXCDNAME
, rrname
, sizeof rrname
);
501 return (NULL
); /* compression error */
504 type
= _getshort((u_char
*)cp
);
506 class = _getshort((u_char
*)cp
);
508 tmpttl
= _getlong((u_char
*)cp
);
510 dlen
= _getshort((u_char
*)cp
);
513 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_TTLID
))
514 fprintf(file
, "\t%lu", (u_long
)tmpttl
);
515 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_CLASS
))
516 fprintf(file
, "\t%s", __p_class(class));
517 fprintf(file
, "\t%s", __p_type(type
));
519 * Print type specific data, if appropriate
526 bcopy(cp
, (char *)&inaddr
, INADDRSZ
);
528 fprintf(file
, "\t%s", inet_ntoa(inaddr
));
530 } else if (dlen
== 7) {
535 address
= inet_ntoa(inaddr
);
537 protocol
= *(u_char
*)cp
;
538 cp
+= sizeof (u_char
);
539 port
= _getshort((u_char
*)cp
);
541 fprintf(file
, "\t%s\t; proto %d, port %d",
542 address
, protocol
, port
);
556 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
563 (void) fputs("\t\"", file
);
564 if ((n
= (unsigned char) *cp
++) != 0) {
565 for (c
= n
; c
> 0 && cp
< cp2
; c
--) {
566 if (strchr("\n\"\\", *cp
))
567 (void) putc('\\', file
);
568 (void) putc(*cp
++, file
);
572 if (cp
< cp2
&& (n
= (unsigned char) *cp
++) != 0) {
573 (void) fputs ("\t\"", file
);
574 for (c
= n
; c
> 0 && cp
< cp2
; c
--) {
575 if (strchr("\n\"\\", *cp
))
576 (void) putc('\\', file
);
577 (void) putc(*cp
++, file
);
580 } else if (type
== T_HINFO
) {
581 (void) fputs("\"?\"", file
);
582 fprintf(file
, "\n;; *** Warning *** OS-type missing");
588 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
591 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
594 t
= _getlong((u_char
*)cp
); cp
+= INT32SZ
;
595 fprintf(file
, "\t\t\t%lu\t; serial\n", (u_long
)t
);
596 t
= _getlong((u_char
*)cp
); cp
+= INT32SZ
;
597 fprintf(file
, "\t\t\t%lu\t; refresh (%s)\n",
598 (u_long
)t
, __p_time(t
));
599 t
= _getlong((u_char
*)cp
); cp
+= INT32SZ
;
600 fprintf(file
, "\t\t\t%lu\t; retry (%s)\n",
601 (u_long
)t
, __p_time(t
));
602 t
= _getlong((u_char
*)cp
); cp
+= INT32SZ
;
603 fprintf(file
, "\t\t\t%lu\t; expire (%s)\n",
604 (u_long
)t
, __p_time(t
));
605 t
= _getlong((u_char
*)cp
); cp
+= INT32SZ
;
606 fprintf(file
, "\t\t\t%lu )\t; minimum (%s)",
607 (u_long
)t
, __p_time(t
));
613 fprintf(file
, "\t%d ", _getshort((u_char
*)cp
));
615 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
620 fprintf(file
, "\t%d ", _getshort((u_char
*)cp
));
622 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
625 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
631 (void) fputs("\t\"", file
);
632 if ((n
= (unsigned char) *cp
++) != 0) {
633 for (c
= n
; c
> 0 && cp
< cp2
; c
--) {
634 if (strchr("\n\"\\", *cp
))
635 (void) putc('\\', file
);
636 (void) putc(*cp
++, file
);
643 (void) putc('\t', file
);
647 if ((n
= (unsigned char) *cp
++)) {
648 for (c
= n
; c
> 0 && cp
< cp2
; c
--) {
649 if (strchr("\n\"\\", *cp
))
650 (void) putc('\\', file
);
651 (void) putc(*cp
++, file
);
661 (void) fprintf(file
, "\t%s", inet_nsap_ntoa(dlen
, cp
, NULL
));
666 char t
[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
668 fprintf(file
, "\t%s", inet_ntop(AF_INET6
, cp
, t
, sizeof t
));
676 (void) fprintf(file
, "\t%s", loc_ntoa(cp
, t
));
682 u_int order
, preference
;
684 order
= _getshort(cp
); cp
+= INT16SZ
;
685 preference
= _getshort(cp
); cp
+= INT16SZ
;
686 fprintf(file
, "\t%u %u ",order
, preference
);
689 fprintf(file
,"\"%.*s\" ", (int)n
, cp
);
693 fprintf(file
,"\"%.*s\" ", (int)n
, cp
);
697 fprintf(file
,"\"%.*s\" ", (int)n
, cp
);
699 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
705 u_int priority
, weight
, port
;
707 priority
= _getshort(cp
); cp
+= INT16SZ
;
708 weight
= _getshort(cp
); cp
+= INT16SZ
;
709 port
= _getshort(cp
); cp
+= INT16SZ
;
710 fprintf(file
, "\t%u %u %u ", priority
, weight
, port
);
711 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
719 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
722 if ((cp
= p_fqname(cp
, msg
, file
)) == NULL
)
728 fputs((char *)cp
, file
);
735 fprintf(file
, "\t%u", _getlong((u_char
*)cp
));
741 if (dlen
< INT32SZ
+ 1)
743 bcopy(cp
, (char *)&inaddr
, INADDRSZ
);
745 fprintf(file
, "\t%s %s ( ",
748 cp
+= sizeof (u_char
);
751 while (cp
< cp1
+ dlen
) {
756 fputs("\n\t\t\t", file
);
759 fputs(dewks(n
), file
);
771 keyflags
= _getshort(cp
);
773 fprintf(file
,"0x%04x", keyflags
); /* flags */
774 fprintf(file
," %u", *cp
++); /* protocol */
775 fprintf(file
," %u (", *cp
++); /* algorithm */
777 n
= b64_ntop(cp
, (cp1
+ dlen
) - cp
,
778 base64_key
, sizeof base64_key
);
779 for (c
= 0; c
< n
; ++c
) {
781 fprintf(file
, "\n\t");
782 putc(base64_key
[c
], file
); /* public key data */
787 fprintf(file
, "\t; BAD BASE64");
793 type
= _getshort((u_char
*)cp
);
795 fprintf(file
, " %s", p_type(type
));
796 fprintf(file
, "\t%d", *cp
++); /* algorithm */
797 /* Check label value and print error if wrong. */
799 c
= dn_count_labels (rrname
);
801 fprintf(file
, "\t; LABELS WRONG (%d should be %d)\n\t",
804 n
= _getlong((u_char
*)cp
);
805 if ((u_int32_t
) n
!= tmpttl
)
806 fprintf(file
, " %u", n
);
809 fprintf(file
, " (\n\t%s",
810 __p_secstodate(_getlong((u_char
*)cp
)));
813 fprintf(file
, " %s", __p_secstodate(_getlong((u_char
*)cp
)));
816 fprintf(file
," %u ", _getshort((u_char
*)cp
));
819 cp
= p_fqname(cp
, msg
, file
);
820 n
= b64_ntop(cp
, (cp1
+ dlen
) - cp
,
821 base64_key
, sizeof base64_key
);
822 for (c
= 0; c
< n
; c
++) {
824 fprintf (file
, "\n\t");
825 putc(base64_key
[c
], file
); /* signature */
830 fprintf(file
, "\t; BAD BASE64");
835 #ifdef ALLOW_T_UNSPEC
842 if (dlen
< NumBytes
) NumBytes
= dlen
;
843 fprintf(file
, "\tFirst %d bytes of hex data:",
845 for (i
= 0, DataPtr
= cp
; i
< NumBytes
; i
++, DataPtr
++)
846 fprintf(file
, " %x", *DataPtr
);
850 #endif /* ALLOW_T_UNSPEC */
853 fprintf(file
, "\t?%d?", type
);
857 fprintf(file
, "\t; dlen=%d, ttl %s\n", dlen
, __p_time(tmpttl
));
861 if (cp
- cp1
!= dlen
) {
863 ";; packet size error (found %lu, dlen was %d)\n",
864 (unsigned long) (cp
- cp1
), dlen
);
871 * Names of RR classes and qclasses. Classes and qclasses are the same, except
872 * that C_ANY is a qclass but not a class. (You can ask for records of class
873 * C_ANY, but you can't have any records of that class in the database.)
875 const struct res_sym __p_class_syms
[] = {
885 * Names of RR types and qtypes. Types and qtypes are the same, except
886 * that T_ANY is a qtype but not a type. (You can ask for records of type
887 * T_ANY, but you can't have any records of that type in the database.)
889 const struct res_sym __p_type_syms
[] = {
890 {T_A
, "A", "address"},
891 {T_NS
, "NS", "name server"},
892 {T_MD
, "MD", "mail destination (deprecated)"},
893 {T_MF
, "MF", "mail forwarder (deprecated)"},
894 {T_CNAME
, "CNAME", "canonical name"},
895 {T_SOA
, "SOA", "start of authority"},
896 {T_MB
, "MB", "mailbox"},
897 {T_MG
, "MG", "mail group member"},
898 {T_MR
, "MR", "mail rename"},
899 {T_NULL
, "NULL", "null"},
900 {T_WKS
, "WKS", "well-known service (deprecated)"},
901 {T_PTR
, "PTR", "domain name pointer"},
902 {T_HINFO
, "HINFO", "host information"},
903 {T_MINFO
, "MINFO", "mailbox information"},
904 {T_MX
, "MX", "mail exchanger"},
905 {T_TXT
, "TXT", "text"},
906 {T_RP
, "RP", "responsible person"},
907 {T_AFSDB
, "AFSDB", "DCE or AFS server"},
908 {T_X25
, "X25", "X25 address"},
909 {T_ISDN
, "ISDN", "ISDN address"},
910 {T_RT
, "RT", "router"},
911 {T_NSAP
, "NSAP", "nsap address"},
912 {T_NSAP_PTR
, "NSAP_PTR", "domain name pointer"},
913 {T_SIG
, "SIG", "signature"},
914 {T_KEY
, "KEY", "key"},
915 {T_PX
, "PX", "mapping information"},
916 {T_GPOS
, "GPOS", "geographical position (withdrawn)"},
917 {T_AAAA
, "AAAA", "IPv6 address"},
918 {T_LOC
, "LOC", "location"},
919 {T_NXT
, "NXT", "next valid name (unimplemented)"},
920 {T_EID
, "EID", "endpoint identifier (unimplemented)"},
921 {T_NIMLOC
, "NIMLOC", "NIMROD locator (unimplemented)"},
922 {T_SRV
, "SRV", "server selection"},
923 {T_ATMA
, "ATMA", "ATM address (unimplemented)"},
924 {T_IXFR
, "IXFR", "incremental zone transfer"},
925 {T_AXFR
, "AXFR", "zone transfer"},
926 {T_MAILB
, "MAILB", "mailbox-related data (deprecated)"},
927 {T_MAILA
, "MAILA", "mail agent (deprecated)"},
928 {T_UINFO
, "UINFO", "user information (nonstandard)"},
929 {T_UID
, "UID", "user ID (nonstandard)"},
930 {T_GID
, "GID", "group ID (nonstandard)"},
931 {T_NAPTR
, "NAPTR", "URN Naming Authority"},
932 #ifdef ALLOW_T_UNSPEC
933 {T_UNSPEC
, "UNSPEC", "unspecified data (nonstandard)"},
934 #endif /* ALLOW_T_UNSPEC */
935 {T_ANY
, "ANY", "\"any\""},
940 __sym_ston(syms
, name
, success
)
941 const struct res_sym
*syms
;
946 /* Changed to prevent warning. --drepper@gnu */
947 for (; syms
->name
!= 0; syms
++) {
949 for (NULL
; syms
->name
!= 0; syms
++) {
951 if (strcasecmp (name
, syms
->name
) == 0) {
954 return (syms
->number
);
959 return (syms
->number
); /* The default value. */
963 __sym_ntos(syms
, number
, success
)
964 const struct res_sym
*syms
;
968 static char unname
[20];
971 /* Changed to prevent warning. --drepper@gnu */
972 for (; syms
->name
!= 0; syms
++) {
974 for (NULL
; syms
->name
!= 0; syms
++) {
976 if (number
== syms
->number
) {
983 sprintf (unname
, "%d", number
);
991 __sym_ntop(syms
, number
, success
)
992 const struct res_sym
*syms
;
996 static char unname
[20];
999 /* Changed to prevent warning. --drepper@gnu */
1000 for (; syms
->name
!= 0; syms
++) {
1002 for (NULL
; syms
->name
!= 0; syms
++) {
1004 if (number
== syms
->number
) {
1007 return (syms
->humanname
);
1010 sprintf(unname
, "%d", number
);
1017 * Return a string for the type
1023 return (__sym_ntos (__p_type_syms
, type
, (int *)0));
1027 * Return a mnemonic for class
1033 return (__sym_ntos (__p_class_syms
, class, (int *)0));
1037 * Return a mnemonic for an option
1043 static char nbuf
[40];
1046 case RES_INIT
: return "init";
1047 case RES_DEBUG
: return "debug";
1048 case RES_AAONLY
: return "aaonly(unimpl)";
1049 case RES_USEVC
: return "usevc";
1050 case RES_PRIMARY
: return "primry(unimpl)";
1051 case RES_IGNTC
: return "igntc";
1052 case RES_RECURSE
: return "recurs";
1053 case RES_DEFNAMES
: return "defnam";
1054 case RES_STAYOPEN
: return "styopn";
1055 case RES_DNSRCH
: return "dnsrch";
1056 case RES_INSECURE1
: return "insecure1";
1057 case RES_INSECURE2
: return "insecure2";
1058 default: sprintf(nbuf
, "?0x%lx?", (u_long
)option
);
1064 * Return a mnemonic for a time to live
1070 static char nbuf
[60];
1071 int secs
, mins
, hours
, days
;
1075 strcpy(nbuf
, "0 secs");
1088 #define PLURALIZE(x) x, (x == 1) ? "" : "s"
1091 (void)sprintf(p
, "%d day%s", PLURALIZE(days
));
1097 (void)sprintf(p
, "%d hour%s", PLURALIZE(hours
));
1103 (void)sprintf(p
, "%d min%s", PLURALIZE(mins
));
1106 if (secs
|| ! (days
|| hours
|| mins
)) {
1107 if (days
|| hours
|| mins
)
1109 (void)sprintf(p
, "%d sec%s", PLURALIZE(secs
));
1115 * routines to convert between on-the-wire RR format and zone file format.
1116 * Does not contain conversion to/from decimal degrees; divide or multiply
1117 * by 60*60*1000 for that.
1120 static unsigned int poweroften
[10] = {1, 10, 100, 1000, 10000, 100000,
1121 1000000,10000000,100000000,1000000000};
1123 /* takes an XeY precision/size value, returns a string representation. */
1128 static char retbuf
[sizeof "90000000.00"];
1130 int mantissa
, exponent
;
1132 mantissa
= (int)((prec
>> 4) & 0x0f) % 10;
1133 exponent
= (int)((prec
>> 0) & 0x0f) % 10;
1135 val
= mantissa
* poweroften
[exponent
];
1137 (void) sprintf(retbuf
, "%ld.%.2ld", val
/100, val
%100);
1141 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
1143 precsize_aton(strptr
)
1146 u_int8_t retval
= 0;
1152 while (isdigit(*cp
)) {
1154 mantissa
= *cp
- '0';
1164 mantissa
= *cp
- '0';
1171 mantissa
= *cp
- '0';
1185 retval
= (mantissa
<< 4) | exponent
;
1190 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
1192 latlon2ul(latlonstrptr
,which
)
1193 char **latlonstrptr
;
1198 int deg
= 0, min
= 0, secs
= 0, secsfrac
= 0;
1202 while (isdigit(*cp
))
1203 deg
= deg
* 10 + (*cp
++ - '0');
1205 while (isspace(*cp
))
1208 if (!(isdigit(*cp
)))
1211 while (isdigit(*cp
))
1212 min
= min
* 10 + (*cp
++ - '0');
1214 while (isspace(*cp
))
1217 if (!(isdigit(*cp
)))
1220 while (isdigit(*cp
))
1221 secs
= secs
* 10 + (*cp
++ - '0');
1223 if (*cp
== '.') { /* decimal seconds */
1226 secsfrac
= (*cp
++ - '0') * 100;
1228 secsfrac
+= (*cp
++ - '0') * 10;
1230 secsfrac
+= (*cp
++ - '0');
1236 while (!isspace(*cp
)) /* if any trailing garbage */
1239 while (isspace(*cp
))
1246 retval
= ((unsigned)1<<31)
1247 + (((((deg
* 60) + min
) * 60) + secs
) * 1000)
1252 retval
= ((unsigned)1<<31)
1253 - (((((deg
* 60) + min
) * 60) + secs
) * 1000)
1257 retval
= 0; /* invalid value -- indicates error */
1264 *which
= 1; /* latitude */
1268 *which
= 2; /* longitude */
1271 *which
= 0; /* error */
1275 cp
++; /* skip the hemisphere */
1277 while (!isspace(*cp
)) /* if any trailing garbage */
1280 while (isspace(*cp
)) /* move to next field */
1288 /* converts a zone file representation in a string to an RDATA on-the-wire
1289 * representation. */
1291 loc_aton(ascii
, binary
)
1295 const char *cp
, *maxcp
;
1298 u_int32_t latit
= 0, longit
= 0, alt
= 0;
1299 u_int32_t lltemp1
= 0, lltemp2
= 0;
1300 int altmeters
= 0, altfrac
= 0, altsign
= 1;
1301 u_int8_t hp
= 0x16; /* default = 1e6 cm = 10000.00m = 10km */
1302 u_int8_t vp
= 0x13; /* default = 1e3 cm = 10.00m */
1303 u_int8_t siz
= 0x12; /* default = 1e2 cm = 1.00m */
1304 int which1
= 0, which2
= 0;
1307 maxcp
= cp
+ strlen(ascii
);
1309 lltemp1
= latlon2ul(&cp
, &which1
);
1311 lltemp2
= latlon2ul(&cp
, &which2
);
1313 switch (which1
+ which2
) {
1314 case 3: /* 1 + 2, the only valid combination */
1315 if ((which1
== 1) && (which2
== 2)) { /* normal case */
1318 } else if ((which1
== 2) && (which2
== 1)) { /* reversed */
1321 } else { /* some kind of brokenness */
1325 default: /* we didn't get one of each */
1338 while (isdigit(*cp
))
1339 altmeters
= altmeters
* 10 + (*cp
++ - '0');
1341 if (*cp
== '.') { /* decimal meters */
1344 altfrac
= (*cp
++ - '0') * 10;
1346 altfrac
+= (*cp
++ - '0');
1351 alt
= (10000000 + (altsign
* (altmeters
* 100 + altfrac
)));
1353 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
1356 while (isspace(*cp
) && (cp
< maxcp
))
1362 siz
= precsize_aton(&cp
);
1364 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
1367 while (isspace(*cp
) && (cp
< maxcp
))
1373 hp
= precsize_aton(&cp
);
1375 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
1378 while (isspace(*cp
) && (cp
< maxcp
))
1384 vp
= precsize_aton(&cp
);
1389 *bcp
++ = (u_int8_t
) 0; /* version byte */
1394 PUTLONG(longit
,bcp
);
1397 return (16); /* size of RR in octets */
1400 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
1402 loc_ntoa(binary
, ascii
)
1403 const u_char
*binary
;
1406 static char *error
= "?";
1407 register const u_char
*cp
= binary
;
1409 int latdeg
, latmin
, latsec
, latsecfrac
;
1410 int longdeg
, longmin
, longsec
, longsecfrac
;
1411 char northsouth
, eastwest
;
1412 int altmeters
, altfrac
, altsign
;
1414 const int referencealt
= 100000 * 100;
1416 int32_t latval
, longval
, altval
;
1418 u_int8_t sizeval
, hpval
, vpval
, versionval
;
1420 char *sizestr
, *hpstr
, *vpstr
;
1425 sprintf(ascii
, "; error: unknown LOC RR version");
1435 latval
= (templ
- ((unsigned)1<<31));
1438 longval
= (templ
- ((unsigned)1<<31));
1441 if (templ
< (u_int32_t
) referencealt
) { /* below WGS 84 spheroid */
1442 altval
= referencealt
- templ
;
1445 altval
= templ
- referencealt
;
1455 latsecfrac
= latval
% 1000;
1456 latval
= latval
/ 1000;
1457 latsec
= latval
% 60;
1458 latval
= latval
/ 60;
1459 latmin
= latval
% 60;
1460 latval
= latval
/ 60;
1469 longsecfrac
= longval
% 1000;
1470 longval
= longval
/ 1000;
1471 longsec
= longval
% 60;
1472 longval
= longval
/ 60;
1473 longmin
= longval
% 60;
1474 longval
= longval
/ 60;
1477 altfrac
= altval
% 100;
1478 altmeters
= (altval
/ 100) * altsign
;
1480 if ((sizestr
= strdup(precsize_ntoa(sizeval
))) == NULL
)
1482 if ((hpstr
= strdup(precsize_ntoa(hpval
))) == NULL
)
1484 if ((vpstr
= strdup(precsize_ntoa(vpval
))) == NULL
)
1488 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
1489 latdeg
, latmin
, latsec
, latsecfrac
, northsouth
,
1490 longdeg
, longmin
, longsec
, longsecfrac
, eastwest
,
1491 altmeters
, altfrac
, sizestr
, hpstr
, vpstr
);
1493 if (sizestr
!= error
)
1504 /* Return the number of DNS hierarchy levels in the name. */
1506 __dn_count_labels(name
)
1513 for(i
= 0, count
= 0; i
< len
; i
++) {
1518 /* don't count initial wildcard */
1523 /* don't count the null label for root. */
1524 /* if terminating '.' not found, must adjust */
1525 /* count to include last label */
1526 if (len
> 0 && name
[len
-1] != '.')
1533 * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
1534 * SIG records are required to be printed like this, by the Secure DNS RFC.
1537 __p_secstodate (secs
)
1540 static char output
[15]; /* YYYYMMDDHHMMSS and null */
1541 time_t clock
= secs
;
1544 __gmtime_r(&clock
, &time
);
1545 time
.tm_year
+= 1900;
1547 sprintf(output
, "%04d%02d%02d%02d%02d%02d",
1548 time
.tm_year
, time
.tm_mon
, time
.tm_mday
,
1549 time
.tm_hour
, time
.tm_min
, time
.tm_sec
);