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 * 4. 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
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
51 * Portions Copyright (c) 1995 by International Business Machines, Inc.
53 * International Business Machines, Inc. (hereinafter called IBM) grants
54 * permission under its copyrights to use, copy, modify, and distribute this
55 * Software with or without fee, provided that the above copyright notice and
56 * all paragraphs of this notice appear in all copies, and that the name of IBM
57 * not be used in connection with the marketing of any product incorporating
58 * the Software or modifications thereof, without specific, written prior
61 * To the extent it has a right to do so, IBM grants an immunity from suit
62 * under its patents, if any, for the use, sale or manufacture of products to
63 * the extent that such products are used for performing Domain Name System
64 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
65 * granted for any product per se or for any other function of any product.
67 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
68 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
69 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
70 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
71 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
72 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
76 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
78 * Permission to use, copy, modify, and distribute this software for any
79 * purpose with or without fee is hereby granted, provided that the above
80 * copyright notice and this permission notice appear in all copies.
82 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
83 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
84 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
85 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
86 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
87 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
88 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
92 #if defined(LIBC_SCCS) && !defined(lint)
93 static const char sccsid
[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
94 static const char rcsid
[] = "$Id$";
95 #endif /* LIBC_SCCS and not lint */
97 #include <sys/types.h>
98 #include <sys/param.h>
99 #include <sys/socket.h>
101 #include <netinet/in.h>
102 #include <arpa/inet.h>
103 #include <arpa/nameser.h>
116 # define SPRINTF(x) strlen(sprintf/**/x)
118 # define SPRINTF(x) sprintf x
121 extern const char *_res_opcodes
[];
122 extern const char *_res_sectioncodes
[];
125 * Print the current options.
128 fp_resstat(const res_state statp
, FILE *file
) {
131 fprintf(file
, ";; res options:");
132 for (mask
= 1; mask
!= 0; mask
<<= 1)
133 if (statp
->options
& mask
)
134 fprintf(file
, " %s", p_option(mask
));
139 do_section(const res_state statp
,
140 ns_msg
*handle
, ns_sect section
,
141 int pflag
, FILE *file
)
144 char buf
[2048]; /* XXX need to malloc */
149 * Print answer records.
151 sflag
= (statp
->pfcode
& pflag
);
152 if (statp
->pfcode
&& !sflag
)
155 opcode
= (ns_opcode
) ns_msg_getflag(*handle
, ns_f_opcode
);
158 if (ns_parserr(handle
, section
, rrnum
, &rr
)) {
160 fprintf(file
, ";; ns_parserr: %s\n",
162 else if (rrnum
> 0 && sflag
!= 0 &&
163 (statp
->pfcode
& RES_PRF_HEAD1
))
167 if (rrnum
== 0 && sflag
!= 0 && (statp
->pfcode
& RES_PRF_HEAD1
))
168 fprintf(file
, ";; %s SECTION:\n",
169 p_section(section
, opcode
));
170 if (section
== ns_s_qd
)
171 fprintf(file
, ";;\t%s, type = %s, class = %s\n",
173 p_type(ns_rr_type(rr
)),
174 p_class(ns_rr_class(rr
)));
176 n
= ns_sprintrr(handle
, &rr
, NULL
, NULL
,
179 fprintf(file
, ";; ns_sprintrr: %s\n",
191 * Print the contents of a query.
192 * This is intended to be primarily a debugging routine.
195 res_pquery(const res_state statp
, const u_char
*msg
, int len
, FILE *file
) {
197 int qdcount
, ancount
, nscount
, arcount
;
198 u_int opcode
, rcode
, id
;
200 if (ns_initparse(msg
, len
, &handle
) < 0) {
201 fprintf(file
, ";; ns_initparse: %s\n", strerror(errno
));
204 opcode
= ns_msg_getflag(handle
, ns_f_opcode
);
205 rcode
= ns_msg_getflag(handle
, ns_f_rcode
);
206 id
= ns_msg_id(handle
);
207 qdcount
= ns_msg_count(handle
, ns_s_qd
);
208 ancount
= ns_msg_count(handle
, ns_s_an
);
209 nscount
= ns_msg_count(handle
, ns_s_ns
);
210 arcount
= ns_msg_count(handle
, ns_s_ar
);
213 * Print header fields.
215 if ((!statp
->pfcode
) || (statp
->pfcode
& RES_PRF_HEADX
) || rcode
)
217 ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
218 _res_opcodes
[opcode
], p_rcode(rcode
), id
);
219 if ((!statp
->pfcode
) || (statp
->pfcode
& RES_PRF_HEADX
))
221 if ((!statp
->pfcode
) || (statp
->pfcode
& RES_PRF_HEAD2
)) {
222 fprintf(file
, "; flags:");
223 if (ns_msg_getflag(handle
, ns_f_qr
))
224 fprintf(file
, " qr");
225 if (ns_msg_getflag(handle
, ns_f_aa
))
226 fprintf(file
, " aa");
227 if (ns_msg_getflag(handle
, ns_f_tc
))
228 fprintf(file
, " tc");
229 if (ns_msg_getflag(handle
, ns_f_rd
))
230 fprintf(file
, " rd");
231 if (ns_msg_getflag(handle
, ns_f_ra
))
232 fprintf(file
, " ra");
233 if (ns_msg_getflag(handle
, ns_f_z
))
234 fprintf(file
, " ??");
235 if (ns_msg_getflag(handle
, ns_f_ad
))
236 fprintf(file
, " ad");
237 if (ns_msg_getflag(handle
, ns_f_cd
))
238 fprintf(file
, " cd");
240 if ((!statp
->pfcode
) || (statp
->pfcode
& RES_PRF_HEAD1
)) {
241 fprintf(file
, "; %s: %d",
242 p_section(ns_s_qd
, opcode
), qdcount
);
243 fprintf(file
, ", %s: %d",
244 p_section(ns_s_an
, opcode
), ancount
);
245 fprintf(file
, ", %s: %d",
246 p_section(ns_s_ns
, opcode
), nscount
);
247 fprintf(file
, ", %s: %d",
248 p_section(ns_s_ar
, opcode
), arcount
);
250 if ((!statp
->pfcode
) || (statp
->pfcode
&
251 (RES_PRF_HEADX
| RES_PRF_HEAD2
| RES_PRF_HEAD1
))) {
255 * Print the various sections.
257 do_section(statp
, &handle
, ns_s_qd
, RES_PRF_QUES
, file
);
258 do_section(statp
, &handle
, ns_s_an
, RES_PRF_ANS
, file
);
259 do_section(statp
, &handle
, ns_s_ns
, RES_PRF_AUTH
, file
);
260 do_section(statp
, &handle
, ns_s_ar
, RES_PRF_ADD
, file
);
261 if (qdcount
== 0 && ancount
== 0 &&
262 nscount
== 0 && arcount
== 0)
267 p_cdnname(const u_char
*cp
, const u_char
*msg
, int len
, FILE *file
) {
271 if ((n
= dn_expand(msg
, msg
+ len
, cp
, name
, sizeof name
)) < 0)
281 p_cdname(const u_char
*cp
, const u_char
*msg
, FILE *file
) {
282 return (p_cdnname(cp
, msg
, PACKETSZ
, file
));
285 /* Return a fully-qualified domain name from a compressed name (with
289 p_fqnname(cp
, msg
, msglen
, name
, namelen
)
290 const u_char
*cp
, *msg
;
297 if ((n
= dn_expand(msg
, cp
+ msglen
, cp
, name
, namelen
)) < 0)
299 newlen
= strlen(name
);
300 if (newlen
== 0 || name
[newlen
- 1] != '.') {
301 if (newlen
+ 1 >= namelen
) /* Lack space for final dot */
304 strcpy(name
+ newlen
, ".");
309 /* XXX: the rest of these functions need to become length-limited, too. */
312 p_fqname(const u_char
*cp
, const u_char
*msg
, FILE *file
) {
316 n
= p_fqnname(cp
, msg
, MAXCDNAME
, name
, sizeof name
);
324 * Names of RR classes and qclasses. Classes and qclasses are the same, except
325 * that C_ANY is a qclass but not a class. (You can ask for records of class
326 * C_ANY, but you can't have any records of that class in the database.)
328 const struct res_sym __p_class_syms
[] = {
339 * Names of message sections.
341 const struct res_sym __p_default_section_syms
[] = {
344 {ns_s_ns
, "AUTHORITY"},
345 {ns_s_ar
, "ADDITIONAL"},
349 const struct res_sym __p_update_section_syms
[] = {
351 {S_PREREQ
, "PREREQUISITE"},
352 {S_UPDATE
, "UPDATE"},
353 {S_ADDT
, "ADDITIONAL"},
357 const struct res_sym __p_key_syms
[] = {
358 {NS_ALG_MD5RSA
, "RSA", "RSA KEY with MD5 hash"},
359 {NS_ALG_DH
, "DH", "Diffie Hellman"},
360 {NS_ALG_DSA
, "DSA", "Digital Signature Algorithm"},
361 {NS_ALG_EXPIRE_ONLY
, "EXPIREONLY", "No algorithm"},
362 {NS_ALG_PRIVATE_OID
, "PRIVATE", "Algorithm obtained from OID"},
366 const struct res_sym __p_cert_syms
[] = {
367 {cert_t_pkix
, "PKIX", "PKIX (X.509v3) Certificate"},
368 {cert_t_spki
, "SPKI", "SPKI certificate"},
369 {cert_t_pgp
, "PGP", "PGP certificate"},
370 {cert_t_url
, "URL", "URL Private"},
371 {cert_t_oid
, "OID", "OID Private"},
376 * Names of RR types and qtypes. Types and qtypes are the same, except
377 * that T_ANY is a qtype but not a type. (You can ask for records of type
378 * T_ANY, but you can't have any records of that type in the database.)
380 const struct res_sym __p_type_syms
[] = {
381 {ns_t_a
, "A", "address"},
382 {ns_t_ns
, "NS", "name server"},
383 {ns_t_md
, "MD", "mail destination (deprecated)"},
384 {ns_t_mf
, "MF", "mail forwarder (deprecated)"},
385 {ns_t_cname
, "CNAME", "canonical name"},
386 {ns_t_soa
, "SOA", "start of authority"},
387 {ns_t_mb
, "MB", "mailbox"},
388 {ns_t_mg
, "MG", "mail group member"},
389 {ns_t_mr
, "MR", "mail rename"},
390 {ns_t_null
, "NULL", "null"},
391 {ns_t_wks
, "WKS", "well-known service (deprecated)"},
392 {ns_t_ptr
, "PTR", "domain name pointer"},
393 {ns_t_hinfo
, "HINFO", "host information"},
394 {ns_t_minfo
, "MINFO", "mailbox information"},
395 {ns_t_mx
, "MX", "mail exchanger"},
396 {ns_t_txt
, "TXT", "text"},
397 {ns_t_rp
, "RP", "responsible person"},
398 {ns_t_afsdb
, "AFSDB", "DCE or AFS server"},
399 {ns_t_x25
, "X25", "X25 address"},
400 {ns_t_isdn
, "ISDN", "ISDN address"},
401 {ns_t_rt
, "RT", "router"},
402 {ns_t_nsap
, "NSAP", "nsap address"},
403 {ns_t_nsap_ptr
, "NSAP_PTR", "domain name pointer"},
404 {ns_t_sig
, "SIG", "signature"},
405 {ns_t_key
, "KEY", "key"},
406 {ns_t_px
, "PX", "mapping information"},
407 {ns_t_gpos
, "GPOS", "geographical position (withdrawn)"},
408 {ns_t_aaaa
, "AAAA", "IPv6 address"},
409 {ns_t_loc
, "LOC", "location"},
410 {ns_t_nxt
, "NXT", "next valid name (unimplemented)"},
411 {ns_t_eid
, "EID", "endpoint identifier (unimplemented)"},
412 {ns_t_nimloc
, "NIMLOC", "NIMROD locator (unimplemented)"},
413 {ns_t_srv
, "SRV", "server selection"},
414 {ns_t_atma
, "ATMA", "ATM address (unimplemented)"},
415 {ns_t_tsig
, "TSIG", "transaction signature"},
416 {ns_t_ixfr
, "IXFR", "incremental zone transfer"},
417 {ns_t_axfr
, "AXFR", "zone transfer"},
418 {ns_t_zxfr
, "ZXFR", "compressed zone transfer"},
419 {ns_t_mailb
, "MAILB", "mailbox-related data (deprecated)"},
420 {ns_t_maila
, "MAILA", "mail agent (deprecated)"},
421 {ns_t_naptr
, "NAPTR", "URN Naming Authority"},
422 {ns_t_kx
, "KX", "Key Exchange"},
423 {ns_t_cert
, "CERT", "Certificate"},
424 {ns_t_any
, "ANY", "\"any\""},
429 * Names of DNS rcodes.
431 const struct res_sym __p_rcode_syms
[] = {
432 {ns_r_noerror
, "NOERROR", "no error"},
433 {ns_r_formerr
, "FORMERR", "format error"},
434 {ns_r_servfail
, "SERVFAIL", "server failed"},
435 {ns_r_nxdomain
, "NXDOMAIN", "no such domain name"},
436 {ns_r_notimpl
, "NOTIMP", "not implemented"},
437 {ns_r_refused
, "REFUSED", "refused"},
438 {ns_r_yxdomain
, "YXDOMAIN", "domain name exists"},
439 {ns_r_yxrrset
, "YXRRSET", "rrset exists"},
440 {ns_r_nxrrset
, "NXRRSET", "rrset doesn't exist"},
441 {ns_r_notauth
, "NOTAUTH", "not authoritative"},
442 {ns_r_notzone
, "NOTZONE", "Not in zone"},
444 {ns_r_badsig
, "BADSIG", "bad signature"},
445 {ns_r_badkey
, "BADKEY", "bad key"},
446 {ns_r_badtime
, "BADTIME", "bad time"},
451 sym_ston(const struct res_sym
*syms
, const char *name
, int *success
) {
452 for ((void)NULL
; syms
->name
!= 0; syms
++) {
453 if (strcasecmp (name
, syms
->name
) == 0) {
456 return (syms
->number
);
461 return (syms
->number
); /* The default value. */
465 sym_ntos(const struct res_sym
*syms
, int number
, int *success
) {
466 static char unname
[20];
469 /* Changed to prevent warning. --drepper@gnu */
470 for (; syms
->name
!= 0; syms
++) {
472 for ((void)NULL
; syms
->name
!= 0; syms
++) {
474 if (number
== syms
->number
) {
481 sprintf(unname
, "%d", number
); /* XXX nonreentrant */
488 sym_ntop(const struct res_sym
*syms
, int number
, int *success
) {
489 static char unname
[20];
492 /* Changed to prevent warning. --drepper@gnu */
493 for (; syms
->name
!= 0; syms
++) {
495 for ((void)NULL
; syms
->name
!= 0; syms
++) {
497 if (number
== syms
->number
) {
500 return (syms
->humanname
);
503 sprintf(unname
, "%d", number
); /* XXX nonreentrant */
510 * Return a string for the type.
514 return (sym_ntos(__p_type_syms
, type
, (int *)0));
518 * Return a string for the type.
521 p_section(int section
, int opcode
) {
522 const struct res_sym
*symbols
;
526 symbols
= __p_update_section_syms
;
529 symbols
= __p_default_section_syms
;
532 return (sym_ntos(symbols
, section
, (int *)0));
536 * Return a mnemonic for class.
540 return (sym_ntos(__p_class_syms
, class, (int *)0));
544 * Return a mnemonic for an option
547 p_option(u_long option
) {
548 static char nbuf
[40];
551 case RES_INIT
: return "init";
552 case RES_DEBUG
: return "debug";
553 case RES_AAONLY
: return "aaonly(unimpl)";
554 case RES_USEVC
: return "usevc";
555 case RES_PRIMARY
: return "primry(unimpl)";
556 case RES_IGNTC
: return "igntc";
557 case RES_RECURSE
: return "recurs";
558 case RES_DEFNAMES
: return "defnam";
559 case RES_STAYOPEN
: return "styopn";
560 case RES_DNSRCH
: return "dnsrch";
561 case RES_INSECURE1
: return "insecure1";
562 case RES_INSECURE2
: return "insecure2";
563 /* XXX nonreentrant */
564 default: sprintf(nbuf
, "?0x%lx?", (u_long
)option
);
570 * Return a mnemonic for a time to live.
573 p_time(u_int32_t value
) {
574 static char nbuf
[40]; /* XXX nonreentrant */
576 if (ns_format_ttl(value
, nbuf
, sizeof nbuf
) < 0)
577 sprintf(nbuf
, "%u", value
);
582 * Return a string for the rcode.
586 return (sym_ntos(__p_rcode_syms
, rcode
, (int *)0));
590 * routines to convert between on-the-wire RR format and zone file format.
591 * Does not contain conversion to/from decimal degrees; divide or multiply
592 * by 60*60*1000 for that.
595 static unsigned int poweroften
[10] = {1, 10, 100, 1000, 10000, 100000,
596 1000000,10000000,100000000,1000000000};
598 /* takes an XeY precision/size value, returns a string representation. */
603 static char retbuf
[sizeof "90000000.00"]; /* XXX nonreentrant */
605 int mantissa
, exponent
;
607 mantissa
= (int)((prec
>> 4) & 0x0f) % 10;
608 exponent
= (int)((prec
>> 0) & 0x0f) % 10;
610 val
= mantissa
* poweroften
[exponent
];
612 (void) sprintf(retbuf
, "%ld.%.2ld", val
/100, val
%100);
616 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
618 precsize_aton(strptr
)
621 unsigned int mval
= 0, cmval
= 0;
630 mval
= mval
* 10 + (*cp
++ - '0');
632 if (*cp
== '.') { /* centimeters */
635 cmval
= (*cp
++ - '0') * 10;
637 cmval
+= (*cp
++ - '0');
641 cmval
= (mval
* 100) + cmval
;
643 for (exponent
= 0; exponent
< 9; exponent
++)
644 if (cmval
< poweroften
[exponent
+1])
647 mantissa
= cmval
/ poweroften
[exponent
];
651 retval
= (mantissa
<< 4) | exponent
;
658 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
660 latlon2ul(latlonstrptr
,which
)
666 int deg
= 0, min
= 0, secs
= 0, secsfrac
= 0;
671 deg
= deg
* 10 + (*cp
++ - '0');
680 min
= min
* 10 + (*cp
++ - '0');
689 secs
= secs
* 10 + (*cp
++ - '0');
691 if (*cp
== '.') { /* decimal seconds */
694 secsfrac
= (*cp
++ - '0') * 100;
696 secsfrac
+= (*cp
++ - '0') * 10;
698 secsfrac
+= (*cp
++ - '0');
704 while (!isspace(*cp
)) /* if any trailing garbage */
714 retval
= ((unsigned)1<<31)
715 + (((((deg
* 60) + min
) * 60) + secs
) * 1000)
720 retval
= ((unsigned)1<<31)
721 - (((((deg
* 60) + min
) * 60) + secs
) * 1000)
725 retval
= 0; /* invalid value -- indicates error */
732 *which
= 1; /* latitude */
736 *which
= 2; /* longitude */
739 *which
= 0; /* error */
743 cp
++; /* skip the hemisphere */
745 while (!isspace(*cp
)) /* if any trailing garbage */
748 while (isspace(*cp
)) /* move to next field */
756 /* converts a zone file representation in a string to an RDATA on-the-wire
759 loc_aton(ascii
, binary
)
763 const char *cp
, *maxcp
;
766 u_int32_t latit
= 0, longit
= 0, alt
= 0;
767 u_int32_t lltemp1
= 0, lltemp2
= 0;
768 int altmeters
= 0, altfrac
= 0, altsign
= 1;
769 u_int8_t hp
= 0x16; /* default = 1e6 cm = 10000.00m = 10km */
770 u_int8_t vp
= 0x13; /* default = 1e3 cm = 10.00m */
771 u_int8_t siz
= 0x12; /* default = 1e2 cm = 1.00m */
772 int which1
= 0, which2
= 0;
775 maxcp
= cp
+ strlen(ascii
);
777 lltemp1
= latlon2ul(&cp
, &which1
);
779 lltemp2
= latlon2ul(&cp
, &which2
);
781 switch (which1
+ which2
) {
782 case 3: /* 1 + 2, the only valid combination */
783 if ((which1
== 1) && (which2
== 2)) { /* normal case */
786 } else if ((which1
== 2) && (which2
== 1)) { /* reversed */
789 } else { /* some kind of brokenness */
793 default: /* we didn't get one of each */
807 altmeters
= altmeters
* 10 + (*cp
++ - '0');
809 if (*cp
== '.') { /* decimal meters */
812 altfrac
= (*cp
++ - '0') * 10;
814 altfrac
+= (*cp
++ - '0');
819 alt
= (10000000 + (altsign
* (altmeters
* 100 + altfrac
)));
821 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
824 while (isspace(*cp
) && (cp
< maxcp
))
830 siz
= precsize_aton(&cp
);
832 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
835 while (isspace(*cp
) && (cp
< maxcp
))
841 hp
= precsize_aton(&cp
);
843 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
846 while (isspace(*cp
) && (cp
< maxcp
))
852 vp
= precsize_aton(&cp
);
857 *bcp
++ = (u_int8_t
) 0; /* version byte */
865 return (16); /* size of RR in octets */
868 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
870 loc_ntoa(binary
, ascii
)
871 const u_char
*binary
;
874 static char *error
= "?";
875 static char tmpbuf
[sizeof
876 "1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
877 const u_char
*cp
= binary
;
879 int latdeg
, latmin
, latsec
, latsecfrac
;
880 int longdeg
, longmin
, longsec
, longsecfrac
;
881 char northsouth
, eastwest
;
882 int altmeters
, altfrac
, altsign
;
884 const u_int32_t referencealt
= 100000 * 100;
886 int32_t latval
, longval
, altval
;
888 u_int8_t sizeval
, hpval
, vpval
, versionval
;
890 char *sizestr
, *hpstr
, *vpstr
;
898 (void) sprintf(ascii
, "; error: unknown LOC RR version");
908 latval
= (templ
- ((unsigned)1<<31));
911 longval
= (templ
- ((unsigned)1<<31));
914 if (templ
< referencealt
) { /* below WGS 84 spheroid */
915 altval
= referencealt
- templ
;
918 altval
= templ
- referencealt
;
928 latsecfrac
= latval
% 1000;
929 latval
= latval
/ 1000;
930 latsec
= latval
% 60;
931 latval
= latval
/ 60;
932 latmin
= latval
% 60;
933 latval
= latval
/ 60;
942 longsecfrac
= longval
% 1000;
943 longval
= longval
/ 1000;
944 longsec
= longval
% 60;
945 longval
= longval
/ 60;
946 longmin
= longval
% 60;
947 longval
= longval
/ 60;
950 altfrac
= altval
% 100;
951 altmeters
= (altval
/ 100) * altsign
;
953 if ((sizestr
= strdup(precsize_ntoa(sizeval
))) == NULL
)
955 if ((hpstr
= strdup(precsize_ntoa(hpval
))) == NULL
)
957 if ((vpstr
= strdup(precsize_ntoa(vpval
))) == NULL
)
961 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
962 latdeg
, latmin
, latsec
, latsecfrac
, northsouth
,
963 longdeg
, longmin
, longsec
, longsecfrac
, eastwest
,
964 altmeters
, altfrac
, sizestr
, hpstr
, vpstr
);
966 if (sizestr
!= error
)
977 /* Return the number of DNS hierarchy levels in the name. */
979 dn_count_labels(const char *name
) {
983 for (i
= 0, count
= 0; i
< len
; i
++) {
984 /* XXX need to check for \. or use named's nlabels(). */
989 /* don't count initial wildcard */
994 /* don't count the null label for root. */
995 /* if terminating '.' not found, must adjust */
996 /* count to include last label */
997 if (len
> 0 && name
[len
-1] != '.')
1004 * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
1005 * SIG records are required to be printed like this, by the Secure DNS RFC.
1008 p_secstodate (u_long secs
) {
1009 /* XXX nonreentrant */
1010 static char output
[15]; /* YYYYMMDDHHMMSS and null */
1011 time_t clock
= secs
;
1015 struct time timebuf
;
1017 time
= gmtime_r(&clock
, &timebuf
);
1019 time
= gmtime(&clock
);
1021 time
->tm_year
+= 1900;
1023 sprintf(output
, "%04d%02d%02d%02d%02d%02d",
1024 time
->tm_year
, time
->tm_mon
, time
->tm_mday
,
1025 time
->tm_hour
, time
->tm_min
, time
->tm_sec
);