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.4 2005/11/13 02:04:47 swildner 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
)
128 fprintf(file
, ";; res options:");
131 for (mask
= 1; mask
!= 0; mask
<<= 1)
132 if (statp
->options
& mask
)
133 fprintf(file
, " %s", p_option(mask
));
138 do_section(ns_msg
*handle
, ns_sect section
, int pflag
, FILE *file
)
141 char buf
[2048]; /* XXX need to malloc */
146 * Print answer records.
148 sflag
= (_res
.pfcode
& pflag
);
149 if (_res
.pfcode
&& !sflag
)
152 opcode
= ns_msg_getflag(*handle
, ns_f_opcode
);
155 if (ns_parserr(handle
, section
, rrnum
, &rr
)) {
157 fprintf(file
, ";; ns_parserr: %s\n",
159 else if (rrnum
> 0 && sflag
!= 0 &&
160 (_res
.pfcode
& RES_PRF_HEAD1
))
164 if (rrnum
== 0 && sflag
!= 0 && (_res
.pfcode
& RES_PRF_HEAD1
))
165 fprintf(file
, ";; %s SECTION:\n",
166 p_section(section
, opcode
));
167 if (section
== ns_s_qd
)
168 fprintf(file
, ";;\t%s, type = %s, class = %s\n",
170 p_type(ns_rr_type(rr
)),
171 p_class(ns_rr_class(rr
)));
173 n
= ns_sprintrr(handle
, &rr
, NULL
, NULL
,
176 fprintf(file
, ";; ns_sprintrr: %s\n",
188 p_query(const u_char
*msg
)
190 fp_query(msg
, stdout
);
194 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
)
207 int qdcount
, ancount
, nscount
, arcount
;
208 u_int opcode
, rcode
, id
;
210 if ((_res
.options
& RES_INIT
) == 0 && res_init() == -1)
213 if (ns_initparse(msg
, len
, &handle
) < 0) {
214 fprintf(file
, ";; ns_initparse: %s\n", strerror(errno
));
217 opcode
= ns_msg_getflag(handle
, ns_f_opcode
);
218 rcode
= ns_msg_getflag(handle
, ns_f_rcode
);
219 id
= ns_msg_id(handle
);
220 qdcount
= ns_msg_count(handle
, ns_s_qd
);
221 ancount
= ns_msg_count(handle
, ns_s_an
);
222 nscount
= ns_msg_count(handle
, ns_s_ns
);
223 arcount
= ns_msg_count(handle
, ns_s_ar
);
226 * Print header fields.
228 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
) || rcode
)
230 ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
231 _res_opcodes
[opcode
], _res_resultcodes
[rcode
], id
);
232 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
))
234 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD2
)) {
235 fprintf(file
, "; flags:");
236 if (ns_msg_getflag(handle
, ns_f_qr
))
237 fprintf(file
, " qr");
238 if (ns_msg_getflag(handle
, ns_f_aa
))
239 fprintf(file
, " aa");
240 if (ns_msg_getflag(handle
, ns_f_tc
))
241 fprintf(file
, " tc");
242 if (ns_msg_getflag(handle
, ns_f_rd
))
243 fprintf(file
, " rd");
244 if (ns_msg_getflag(handle
, ns_f_ra
))
245 fprintf(file
, " ra");
246 if (ns_msg_getflag(handle
, ns_f_z
))
247 fprintf(file
, " ??");
248 if (ns_msg_getflag(handle
, ns_f_ad
))
249 fprintf(file
, " ad");
250 if (ns_msg_getflag(handle
, ns_f_cd
))
251 fprintf(file
, " cd");
253 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD1
)) {
254 fprintf(file
, "; %s: %d",
255 p_section(ns_s_qd
, opcode
), qdcount
);
256 fprintf(file
, ", %s: %d",
257 p_section(ns_s_an
, opcode
), ancount
);
258 fprintf(file
, ", %s: %d",
259 p_section(ns_s_ns
, opcode
), nscount
);
260 fprintf(file
, ", %s: %d",
261 p_section(ns_s_ar
, opcode
), arcount
);
263 if ((!_res
.pfcode
) || (_res
.pfcode
&
264 (RES_PRF_HEADX
| RES_PRF_HEAD2
| RES_PRF_HEAD1
))) {
268 * Print the various sections.
270 do_section(&handle
, ns_s_qd
, RES_PRF_QUES
, file
);
271 do_section(&handle
, ns_s_an
, RES_PRF_ANS
, file
);
272 do_section(&handle
, ns_s_ns
, RES_PRF_AUTH
, file
);
273 do_section(&handle
, ns_s_ar
, RES_PRF_ADD
, file
);
274 if (qdcount
== 0 && ancount
== 0 &&
275 nscount
== 0 && arcount
== 0)
280 p_cdnname(const u_char
*cp
, const u_char
*msg
, int len
, FILE *file
)
285 if ((n
= dn_expand(msg
, msg
+ len
, cp
, name
, sizeof name
)) < 0)
295 p_cdname(const u_char
*cp
, const u_char
*msg
, FILE *file
)
297 return (p_cdnname(cp
, msg
, PACKETSZ
, file
));
300 /* Return a fully-qualified domain name from a compressed name (with
304 p_fqnname(const u_char
*cp
, const u_char
*msg
, int msglen
, char *name
,
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
)
329 n
= p_fqnname(cp
, msg
, MAXCDNAME
, name
, sizeof name
);
337 * Names of RR classes and qclasses. Classes and qclasses are the same, except
338 * that C_ANY is a qclass but not a class. (You can ask for records of class
339 * C_ANY, but you can't have any records of that class in the database.)
341 const struct res_sym __p_class_syms
[] = {
352 * Names of message sections.
354 const struct res_sym __p_default_section_syms
[] = {
357 {ns_s_ns
, "AUTHORITY"},
358 {ns_s_ar
, "ADDITIONAL"},
362 const struct res_sym __p_update_section_syms
[] = {
364 {S_PREREQ
, "PREREQUISITE"},
365 {S_UPDATE
, "UPDATE"},
366 {S_ADDT
, "ADDITIONAL"},
371 * Names of RR types and qtypes. Types and qtypes are the same, except
372 * that T_ANY is a qtype but not a type. (You can ask for records of type
373 * T_ANY, but you can't have any records of that type in the database.)
375 const struct res_sym __p_type_syms
[] = {
376 {T_A
, "A", "address"},
377 {T_NS
, "NS", "name server"},
378 {T_MD
, "MD", "mail destination (deprecated)"},
379 {T_MF
, "MF", "mail forwarder (deprecated)"},
380 {T_CNAME
, "CNAME", "canonical name"},
381 {T_SOA
, "SOA", "start of authority"},
382 {T_MB
, "MB", "mailbox"},
383 {T_MG
, "MG", "mail group member"},
384 {T_MR
, "MR", "mail rename"},
385 {T_NULL
, "NULL", "null"},
386 {T_WKS
, "WKS", "well-known service (deprecated)"},
387 {T_PTR
, "PTR", "domain name pointer"},
388 {T_HINFO
, "HINFO", "host information"},
389 {T_MINFO
, "MINFO", "mailbox information"},
390 {T_MX
, "MX", "mail exchanger"},
391 {T_TXT
, "TXT", "text"},
392 {T_RP
, "RP", "responsible person"},
393 {T_AFSDB
, "AFSDB", "DCE or AFS server"},
394 {T_X25
, "X25", "X25 address"},
395 {T_ISDN
, "ISDN", "ISDN address"},
396 {T_RT
, "RT", "router"},
397 {T_NSAP
, "NSAP", "nsap address"},
398 {T_NSAP_PTR
, "NSAP_PTR", "domain name pointer"},
399 {T_SIG
, "SIG", "signature"},
400 {T_KEY
, "KEY", "key"},
401 {T_PX
, "PX", "mapping information"},
402 {T_GPOS
, "GPOS", "geographical position (withdrawn)"},
403 {T_AAAA
, "AAAA", "IPv6 address"},
404 {T_LOC
, "LOC", "location"},
405 {T_NXT
, "NXT", "next valid name (unimplemented)"},
406 {T_EID
, "EID", "endpoint identifier (unimplemented)"},
407 {T_NIMLOC
, "NIMLOC", "NIMROD locator (unimplemented)"},
408 {T_SRV
, "SRV", "server selection"},
409 {T_ATMA
, "ATMA", "ATM address (unimplemented)"},
410 {T_IXFR
, "IXFR", "incremental zone transfer"},
411 {T_AXFR
, "AXFR", "zone transfer"},
412 {T_MAILB
, "MAILB", "mailbox-related data (deprecated)"},
413 {T_MAILA
, "MAILA", "mail agent (deprecated)"},
414 {T_NAPTR
, "NAPTR", "URN Naming Authority"},
415 {T_ANY
, "ANY", "\"any\""},
420 sym_ston(const struct res_sym
*syms
, const char *name
, int *success
)
422 for (; syms
->name
!= 0; syms
++) {
423 if (strcasecmp (name
, syms
->name
) == 0) {
426 return (syms
->number
);
431 return (syms
->number
); /* The default value. */
435 sym_ntos(const struct res_sym
*syms
, int number
, int *success
)
437 static char unname
[20];
439 for (; syms
->name
!= 0; syms
++) {
440 if (number
== syms
->number
) {
447 sprintf(unname
, "%d", number
);
454 sym_ntop(const struct res_sym
*syms
, int number
, int *success
)
456 static char unname
[20];
458 for (; syms
->name
!= 0; syms
++) {
459 if (number
== syms
->number
) {
462 return (syms
->humanname
);
465 sprintf(unname
, "%d", number
);
472 * Return a string for the type.
477 return (sym_ntos(__p_type_syms
, type
, (int *)0));
481 * Return a string for the type.
484 p_section(int section
, int opcode
)
486 const struct res_sym
*symbols
;
490 symbols
= __p_update_section_syms
;
493 symbols
= __p_default_section_syms
;
496 return (sym_ntos(symbols
, section
, (int *)0));
500 * Return a mnemonic for class.
505 return (sym_ntos(__p_class_syms
, class, (int *)0));
509 * Return a mnemonic for an option
512 p_option(u_long option
) {
513 static char nbuf
[40];
516 case RES_INIT
: return "init";
517 case RES_DEBUG
: return "debug";
518 case RES_AAONLY
: return "aaonly(unimpl)";
519 case RES_USEVC
: return "usevc";
520 case RES_PRIMARY
: return "primry(unimpl)";
521 case RES_IGNTC
: return "igntc";
522 case RES_RECURSE
: return "recurs";
523 case RES_DEFNAMES
: return "defnam";
524 case RES_STAYOPEN
: return "styopn";
525 case RES_DNSRCH
: return "dnsrch";
526 case RES_INSECURE1
: return "insecure1";
527 case RES_INSECURE2
: return "insecure2";
528 case RES_NOALIASES
: return "noaliases";
529 case RES_USE_INET6
: return "inet6";
530 case RES_NOTLDQUERY
: return "no-tld-query";
531 case RES_USE_EDNS0
: return "edns0";
532 default: sprintf(nbuf
, "?0x%lx?", (u_long
)option
);
538 * Return a mnemonic for a time to live.
541 p_time(u_int32_t value
) {
542 static char nbuf
[40];
544 if (ns_format_ttl(value
, nbuf
, sizeof nbuf
) < 0)
545 sprintf(nbuf
, "%u", value
);
551 * routines to convert between on-the-wire RR format and zone file format.
552 * Does not contain conversion to/from decimal degrees; divide or multiply
553 * by 60*60*1000 for that.
556 static unsigned int poweroften
[10] = {1, 10, 100, 1000, 10000, 100000,
557 1000000,10000000,100000000,1000000000};
559 /* takes an XeY precision/size value, returns a string representation. */
561 precsize_ntoa(u_int8_t prec
)
563 static char retbuf
[sizeof "90000000.00"];
565 int mantissa
, exponent
;
567 mantissa
= (int)((prec
>> 4) & 0x0f) % 10;
568 exponent
= (int)((prec
>> 0) & 0x0f) % 10;
570 val
= mantissa
* poweroften
[exponent
];
572 sprintf(retbuf
, "%ld.%.2ld", val
/100, val
%100);
576 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
578 precsize_aton(char **strptr
)
580 unsigned int mval
= 0, cmval
= 0;
588 while (isdigit((unsigned char)*cp
))
589 mval
= mval
* 10 + (*cp
++ - '0');
591 if (*cp
== '.') { /* centimeters */
593 if (isdigit((unsigned char)*cp
)) {
594 cmval
= (*cp
++ - '0') * 10;
595 if (isdigit((unsigned char)*cp
)) {
596 cmval
+= (*cp
++ - '0');
600 cmval
= (mval
* 100) + cmval
;
602 for (exponent
= 0; exponent
< 9; exponent
++)
603 if (cmval
< poweroften
[exponent
+1])
606 mantissa
= cmval
/ poweroften
[exponent
];
610 retval
= (mantissa
<< 4) | exponent
;
617 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
619 latlon2ul(char **latlonstrptr
, int *which
)
623 int deg
= 0, min
= 0, secs
= 0, secsfrac
= 0;
627 while (isdigit((unsigned char)*cp
))
628 deg
= deg
* 10 + (*cp
++ - '0');
630 while (isspace((unsigned char)*cp
))
633 if (!(isdigit((unsigned char)*cp
)))
636 while (isdigit((unsigned char)*cp
))
637 min
= min
* 10 + (*cp
++ - '0');
639 while (isspace((unsigned char)*cp
))
642 if (!(isdigit((unsigned char)*cp
)))
645 while (isdigit((unsigned char)*cp
))
646 secs
= secs
* 10 + (*cp
++ - '0');
648 if (*cp
== '.') { /* decimal seconds */
650 if (isdigit((unsigned char)*cp
)) {
651 secsfrac
= (*cp
++ - '0') * 100;
652 if (isdigit((unsigned char)*cp
)) {
653 secsfrac
+= (*cp
++ - '0') * 10;
654 if (isdigit((unsigned char)*cp
)) {
655 secsfrac
+= (*cp
++ - '0');
661 while (!isspace((unsigned char)*cp
)) /* if any trailing garbage */
664 while (isspace((unsigned char)*cp
))
671 retval
= ((unsigned)1<<31)
672 + (((((deg
* 60) + min
) * 60) + secs
) * 1000)
677 retval
= ((unsigned)1<<31)
678 - (((((deg
* 60) + min
) * 60) + secs
) * 1000)
682 retval
= 0; /* invalid value -- indicates error */
689 *which
= 1; /* latitude */
693 *which
= 2; /* longitude */
696 *which
= 0; /* error */
700 cp
++; /* skip the hemisphere */
702 while (!isspace((unsigned char)*cp
)) /* if any trailing garbage */
705 while (isspace((unsigned char)*cp
)) /* move to next field */
713 /* converts a zone file representation in a string to an RDATA on-the-wire
716 loc_aton(const char *ascii
, u_char
*binary
)
718 const char *cp
, *maxcp
;
721 u_int32_t latit
= 0, longit
= 0, alt
= 0;
722 u_int32_t lltemp1
= 0, lltemp2
= 0;
723 int altmeters
= 0, altfrac
= 0, altsign
= 1;
724 u_int8_t hp
= 0x16; /* default = 1e6 cm = 10000.00m = 10km */
725 u_int8_t vp
= 0x13; /* default = 1e3 cm = 10.00m */
726 u_int8_t siz
= 0x12; /* default = 1e2 cm = 1.00m */
727 int which1
= 0, which2
= 0;
730 maxcp
= cp
+ strlen(ascii
);
732 lltemp1
= latlon2ul(&cp
, &which1
);
734 lltemp2
= latlon2ul(&cp
, &which2
);
736 switch (which1
+ which2
) {
737 case 3: /* 1 + 2, the only valid combination */
738 if ((which1
== 1) && (which2
== 2)) { /* normal case */
741 } else if ((which1
== 2) && (which2
== 1)) { /* reversed */
744 } else { /* some kind of brokenness */
748 default: /* we didn't get one of each */
761 while (isdigit((unsigned char)*cp
))
762 altmeters
= altmeters
* 10 + (*cp
++ - '0');
764 if (*cp
== '.') { /* decimal meters */
766 if (isdigit((unsigned char)*cp
)) {
767 altfrac
= (*cp
++ - '0') * 10;
768 if (isdigit((unsigned char)*cp
)) {
769 altfrac
+= (*cp
++ - '0');
774 alt
= (10000000 + (altsign
* (altmeters
* 100 + altfrac
)));
776 while (!isspace((unsigned char)*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
779 while (isspace((unsigned char)*cp
) && (cp
< maxcp
))
785 siz
= precsize_aton(&cp
);
787 while (!isspace((unsigned char)*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
790 while (isspace((unsigned char)*cp
) && (cp
< maxcp
))
796 hp
= precsize_aton(&cp
);
798 while (!isspace((unsigned char)*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
801 while (isspace((unsigned char)*cp
) && (cp
< maxcp
))
807 vp
= precsize_aton(&cp
);
812 *bcp
++ = (u_int8_t
) 0; /* version byte */
820 return (16); /* size of RR in octets */
823 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
825 loc_ntoa(const u_char
*binary
, char *ascii
)
827 static char *error
= "?";
828 const u_char
*cp
= binary
;
830 int latdeg
, latmin
, latsec
, latsecfrac
;
831 int longdeg
, longmin
, longsec
, longsecfrac
;
832 char northsouth
, eastwest
;
833 int altmeters
, altfrac
, altsign
;
835 const u_int32_t referencealt
= 100000 * 100;
837 int32_t latval
, longval
, altval
;
839 u_int8_t sizeval
, hpval
, vpval
, versionval
;
841 char *sizestr
, *hpstr
, *vpstr
;
846 sprintf(ascii
, "; error: unknown LOC RR version");
856 latval
= (templ
- ((unsigned)1<<31));
859 longval
= (templ
- ((unsigned)1<<31));
862 if (templ
< referencealt
) { /* below WGS 84 spheroid */
863 altval
= referencealt
- templ
;
866 altval
= templ
- referencealt
;
876 latsecfrac
= latval
% 1000;
877 latval
= latval
/ 1000;
878 latsec
= latval
% 60;
879 latval
= latval
/ 60;
880 latmin
= latval
% 60;
881 latval
= latval
/ 60;
890 longsecfrac
= longval
% 1000;
891 longval
= longval
/ 1000;
892 longsec
= longval
% 60;
893 longval
= longval
/ 60;
894 longmin
= longval
% 60;
895 longval
= longval
/ 60;
898 altfrac
= altval
% 100;
899 altmeters
= (altval
/ 100) * altsign
;
901 if ((sizestr
= strdup(precsize_ntoa(sizeval
))) == NULL
)
903 if ((hpstr
= strdup(precsize_ntoa(hpval
))) == NULL
)
905 if ((vpstr
= strdup(precsize_ntoa(vpval
))) == NULL
)
909 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
910 latdeg
, latmin
, latsec
, latsecfrac
, northsouth
,
911 longdeg
, longmin
, longsec
, longsecfrac
, eastwest
,
912 altmeters
, altfrac
, sizestr
, hpstr
, vpstr
);
914 if (sizestr
!= error
)
925 /* Return the number of DNS hierarchy levels in the name. */
927 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
)
959 static char output
[15]; /* YYYYMMDDHHMMSS and null */
963 time
= gmtime(&clock
);
964 time
->tm_year
+= 1900;
966 sprintf(output
, "%04d%02d%02d%02d%02d%02d",
967 time
->tm_year
, time
->tm_mon
, time
->tm_mday
,
968 time
->tm_hour
, time
->tm_min
, time
->tm_sec
);
973 * Weak aliases for applications that use certain private entry points,
974 * and fail to include <resolv.h>.
977 __weak_reference(__fp_resstat
, fp_resstat
);
979 __weak_reference(__p_query
, p_query
);
981 __weak_reference(__p_fqnname
, p_fqnname
);
983 __weak_reference(__sym_ston
, sym_ston
);
985 __weak_reference(__sym_ntos
, sym_ntos
);
987 __weak_reference(__sym_ntop
, sym_ntop
);
988 #undef dn_count_labels
989 __weak_reference(__dn_count_labels
, dn_count_labels
);
991 __weak_reference(__p_secstodate
, p_secstodate
);