3 * The Regents of the University of California. All rights reserved.
5 * Portions copyright (c) 1999, 2000
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley, Intel Corporation, and its contributors.
26 * 4. Neither the name of University, Intel Corporation, or their respective
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND
31 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
32 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,
34 * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
47 * Permission to use, copy, modify, and distribute this software for any
48 * purpose with or without fee is hereby granted, provided that the above
49 * copyright notice and this permission notice appear in all copies, and that
50 * the name of Digital Equipment Corporation not be used in advertising or
51 * publicity pertaining to distribution of the document or software without
52 * specific, written prior permission.
54 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
55 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
57 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
58 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
59 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
60 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
65 * Portions Copyright (c) 1995 by International Business Machines, Inc.
67 * International Business Machines, Inc. (hereinafter called IBM) grants
68 * permission under its copyrights to use, copy, modify, and distribute this
69 * Software with or without fee, provided that the above copyright notice and
70 * all paragraphs of this notice appear in all copies, and that the name of IBM
71 * not be used in connection with the marketing of any product incorporating
72 * the Software or modifications thereof, without specific, written prior
75 * To the extent it has a right to do so, IBM grants an immunity from suit
76 * under its patents, if any, for the use, sale or manufacture of products to
77 * the extent that such products are used for performing Domain Name System
78 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
79 * granted for any product per se or for any other function of any product.
81 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
82 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
83 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
84 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
85 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
86 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
90 * Portions Copyright (c) 1996 by Internet Software Consortium.
92 * Permission to use, copy, modify, and distribute this software for any
93 * purpose with or without fee is hereby granted, provided that the above
94 * copyright notice and this permission notice appear in all copies.
96 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
97 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
98 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
99 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
100 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
101 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
102 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
106 #if defined(LIBC_SCCS) && !defined(lint)
107 static char sccsid
[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
108 static char rcsid
[] = "$Id: res_debug.c,v 1.1.1.1 2003/11/19 01:51:36 kyu3 Exp $";
109 #endif /* LIBC_SCCS and not lint */
111 #include <sys/types.h>
112 #include <sys/param.h>
113 #include <sys/socket.h>
115 #include <netinet/in.h>
116 #include <arpa/inet.h>
117 #include <arpa/nameser.h>
129 #define SPRINTF(x) sprintf x
131 extern const char *_res_opcodes
[];
132 extern const char *_res_resultcodes
[];
133 extern const char *_res_sectioncodes
[];
136 * Print the current options.
139 fp_resstat(struct __res_state
*statp
, FILE *file
) {
142 fprintf(file
, ";; res options:");
145 for (mask
= 1; mask
!= 0; mask
<<= 1)
146 if (statp
->options
& mask
)
147 fprintf(file
, " %s", p_option(mask
));
152 do_section(ns_msg
*handle
, ns_sect section
, int pflag
, FILE *file
) {
158 * Print answer records.
160 sflag
= (int)(_res
.pfcode
& pflag
);
161 if (_res
.pfcode
&& !sflag
)
164 opcode
= ns_msg_getflag(*handle
, ns_f_opcode
);
167 if (ns_parserr(handle
, section
, rrnum
, &rr
)) {
169 fprintf(file
, ";; ns_parserr: %s\n",
171 else if (rrnum
> 0 && sflag
!= 0 &&
172 (_res
.pfcode
& RES_PRF_HEAD1
))
176 if (rrnum
== 0 && sflag
!= 0 && (_res
.pfcode
& RES_PRF_HEAD1
))
177 fprintf(file
, ";; %s SECTION:\n",
178 p_section(section
, opcode
));
179 if (section
== ns_s_qd
)
180 fprintf(file
, ";;\t%s, type = %s, class = %s\n",
182 p_type(ns_rr_type(rr
)),
183 p_class(ns_rr_class(rr
)));
186 buf
= (char*)malloc(2024);
188 n
= ns_sprintrr(handle
, &rr
, NULL
, NULL
,
191 fprintf(file
, ";; ns_sprintrr: %s\n",
206 p_query(const u_char
*msg
) {
207 fp_query(msg
, stdout
);
211 fp_query(const u_char
*msg
, FILE *file
) {
212 fp_nquery(msg
, PACKETSZ
, file
);
216 * Print the contents of a query.
217 * This is intended to be primarily a debugging routine.
220 fp_nquery(const u_char
*msg
, int len
, FILE *file
) {
222 int qdcount
, ancount
, nscount
, arcount
;
223 u_int opcode
, rcode
, id
;
225 if ((_res
.options
& RES_INIT
) == 0 && res_init() == -1)
228 if (ns_initparse(msg
, len
, &handle
) < 0) {
229 fprintf(file
, ";; ns_initparse: %s\n", strerror(errno
));
232 opcode
= ns_msg_getflag(handle
, ns_f_opcode
);
233 rcode
= ns_msg_getflag(handle
, ns_f_rcode
);
234 id
= ns_msg_id(handle
);
235 qdcount
= ns_msg_count(handle
, ns_s_qd
);
236 ancount
= ns_msg_count(handle
, ns_s_an
);
237 nscount
= ns_msg_count(handle
, ns_s_ns
);
238 arcount
= ns_msg_count(handle
, ns_s_ar
);
241 * Print header fields.
243 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
) || rcode
)
245 ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
246 _res_opcodes
[opcode
], _res_resultcodes
[rcode
], (int)id
);
247 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEADX
))
249 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD2
)) {
250 fprintf(file
, "; flags:");
251 if (ns_msg_getflag(handle
, ns_f_qr
))
252 fprintf(file
, " qr");
253 if (ns_msg_getflag(handle
, ns_f_aa
))
254 fprintf(file
, " aa");
255 if (ns_msg_getflag(handle
, ns_f_tc
))
256 fprintf(file
, " tc");
257 if (ns_msg_getflag(handle
, ns_f_rd
))
258 fprintf(file
, " rd");
259 if (ns_msg_getflag(handle
, ns_f_ra
))
260 fprintf(file
, " ra");
261 if (ns_msg_getflag(handle
, ns_f_z
))
262 fprintf(file
, " ??");
263 if (ns_msg_getflag(handle
, ns_f_ad
))
264 fprintf(file
, " ad");
265 if (ns_msg_getflag(handle
, ns_f_cd
))
266 fprintf(file
, " cd");
268 if ((!_res
.pfcode
) || (_res
.pfcode
& RES_PRF_HEAD1
)) {
269 fprintf(file
, "; %s: %d",
270 p_section(ns_s_qd
, (int)opcode
), qdcount
);
271 fprintf(file
, ", %s: %d",
272 p_section(ns_s_an
, (int)opcode
), ancount
);
273 fprintf(file
, ", %s: %d",
274 p_section(ns_s_ns
, (int)opcode
), nscount
);
275 fprintf(file
, ", %s: %d",
276 p_section(ns_s_ar
, (int)opcode
), arcount
);
278 if ((!_res
.pfcode
) || (_res
.pfcode
&
279 (RES_PRF_HEADX
| RES_PRF_HEAD2
| RES_PRF_HEAD1
))) {
283 * Print the various sections.
285 do_section(&handle
, ns_s_qd
, RES_PRF_QUES
, file
);
286 do_section(&handle
, ns_s_an
, RES_PRF_ANS
, file
);
287 do_section(&handle
, ns_s_ns
, RES_PRF_AUTH
, file
);
288 do_section(&handle
, ns_s_ar
, RES_PRF_ADD
, file
);
289 if (qdcount
== 0 && ancount
== 0 &&
290 nscount
== 0 && arcount
== 0)
295 p_cdnname(const u_char
*cp
, const u_char
*msg
, int len
, FILE *file
) {
299 if ((n
= dn_expand(msg
, msg
+ len
, cp
, name
, sizeof name
)) < 0)
309 p_cdname(const u_char
*cp
, const u_char
*msg
, FILE *file
) {
310 return (p_cdnname(cp
, msg
, PACKETSZ
, file
));
313 /* Return a fully-qualified domain name from a compressed name (with
327 if ((n
= dn_expand(msg
, cp
+ msglen
, cp
, name
, namelen
)) < 0)
329 newlen
= (int)strlen(name
);
330 if (newlen
== 0 || name
[newlen
- 1] != '.') {
331 if (newlen
+ 1 >= namelen
) /* Lack space for final dot */
334 strcpy(name
+ newlen
, ".");
339 /* XXX: the rest of these functions need to become length-limited, too. */
342 p_fqname(const u_char
*cp
, const u_char
*msg
, FILE *file
) {
346 n
= p_fqnname(cp
, msg
, MAXCDNAME
, name
, sizeof name
);
354 * Names of RR classes and qclasses. Classes and qclasses are the same, except
355 * that C_ANY is a qclass but not a class. (You can ask for records of class
356 * C_ANY, but you can't have any records of that class in the database.)
358 const struct res_sym __p_class_syms
[] = {
369 * Names of message sections.
371 const struct res_sym __p_default_section_syms
[] = {
374 {ns_s_ns
, "AUTHORITY"},
375 {ns_s_ar
, "ADDITIONAL"},
379 const struct res_sym __p_update_section_syms
[] = {
381 {S_PREREQ
, "PREREQUISITE"},
382 {S_UPDATE
, "UPDATE"},
383 {S_ADDT
, "ADDITIONAL"},
388 * Names of RR types and qtypes. Types and qtypes are the same, except
389 * that T_ANY is a qtype but not a type. (You can ask for records of type
390 * T_ANY, but you can't have any records of that type in the database.)
392 const struct res_sym __p_type_syms
[] = {
393 {T_A
, "A", "address"},
394 {T_NS
, "NS", "name server"},
395 {T_MD
, "MD", "mail destination (deprecated)"},
396 {T_MF
, "MF", "mail forwarder (deprecated)"},
397 {T_CNAME
, "CNAME", "canonical name"},
398 {T_SOA
, "SOA", "start of authority"},
399 {T_MB
, "MB", "mailbox"},
400 {T_MG
, "MG", "mail group member"},
401 {T_MR
, "MR", "mail rename"},
402 {T_NULL
, "NULL", "null"},
403 {T_WKS
, "WKS", "well-known service (deprecated)"},
404 {T_PTR
, "PTR", "domain name pointer"},
405 {T_HINFO
, "HINFO", "host information"},
406 {T_MINFO
, "MINFO", "mailbox information"},
407 {T_MX
, "MX", "mail exchanger"},
408 {T_TXT
, "TXT", "text"},
409 {T_RP
, "RP", "responsible person"},
410 {T_AFSDB
, "AFSDB", "DCE or AFS server"},
411 {T_X25
, "X25", "X25 address"},
412 {T_ISDN
, "ISDN", "ISDN address"},
413 {T_RT
, "RT", "router"},
414 {T_NSAP
, "NSAP", "nsap address"},
415 {T_NSAP_PTR
, "NSAP_PTR", "domain name pointer"},
416 {T_SIG
, "SIG", "signature"},
417 {T_KEY
, "KEY", "key"},
418 {T_PX
, "PX", "mapping information"},
419 {T_GPOS
, "GPOS", "geographical position (withdrawn)"},
420 {T_AAAA
, "AAAA", "IPv6 address"},
421 {T_LOC
, "LOC", "location"},
422 {T_NXT
, "NXT", "next valid name (unimplemented)"},
423 {T_EID
, "EID", "endpoint identifier (unimplemented)"},
424 {T_NIMLOC
, "NIMLOC", "NIMROD locator (unimplemented)"},
425 {T_SRV
, "SRV", "server selection"},
426 {T_ATMA
, "ATMA", "ATM address (unimplemented)"},
427 {T_IXFR
, "IXFR", "incremental zone transfer"},
428 {T_AXFR
, "AXFR", "zone transfer"},
429 {T_MAILB
, "MAILB", "mailbox-related data (deprecated)"},
430 {T_MAILA
, "MAILA", "mail agent (deprecated)"},
431 {T_NAPTR
, "NAPTR", "URN Naming Authority"},
432 {T_ANY
, "ANY", "\"any\""},
437 sym_ston(const struct res_sym
*syms
, const char *name
, int *success
) {
438 for ((void)NULL
; syms
->name
!= 0; syms
++) {
439 if (strcasecmp (name
, syms
->name
) == 0) {
442 return (syms
->number
);
447 return (syms
->number
); /* The default value. */
451 sym_ntos(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
) {
462 sprintf(unname
, "%d", number
);
469 sym_ntop(const struct res_sym
*syms
, int number
, int *success
) {
470 static char unname
[20];
472 for ((void)NULL
; syms
->name
!= 0; syms
++) {
473 if (number
== syms
->number
) {
476 return (syms
->humanname
);
479 sprintf(unname
, "%d", number
);
486 * Return a string for the type.
490 return (sym_ntos(__p_type_syms
, type
, (int *)0));
494 * Return a string for the type.
497 p_section(int section
, int opcode
) {
498 const struct res_sym
*symbols
;
502 symbols
= __p_update_section_syms
;
505 symbols
= __p_default_section_syms
;
508 return (sym_ntos(symbols
, section
, (int *)0));
512 * Return a mnemonic for class.
516 return (sym_ntos(__p_class_syms
, class, (int *)0));
520 * Return a mnemonic for an option
523 p_option(u_long option
) {
524 static char nbuf
[40];
527 case RES_INIT
: return "init";
528 case RES_DEBUG
: return "debug";
529 case RES_AAONLY
: return "aaonly(unimpl)";
530 case RES_USEVC
: return "usevc";
531 case RES_PRIMARY
: return "primry(unimpl)";
532 case RES_IGNTC
: return "igntc";
533 case RES_RECURSE
: return "recurs";
534 case RES_DEFNAMES
: return "defnam";
535 case RES_STAYOPEN
: return "styopn";
536 case RES_DNSRCH
: return "dnsrch";
537 case RES_INSECURE1
: return "insecure1";
538 case RES_INSECURE2
: return "insecure2";
539 default: sprintf(nbuf
, "?0x%lx?", (unsigned long)option
);
545 * Return a mnemonic for a time to live.
548 p_time(u_int32_t value
) {
549 static char nbuf
[40];
551 if (ns_format_ttl(value
, nbuf
, sizeof nbuf
) < 0)
552 sprintf(nbuf
, "%u", value
);
558 * routines to convert between on-the-wire RR format and zone file format.
559 * Does not contain conversion to/from decimal degrees; divide or multiply
560 * by 60*60*1000 for that.
563 static unsigned int poweroften
[10] = {1, 10, 100, 1000, 10000, 100000,
564 1000000,10000000,100000000,1000000000};
566 /* takes an XeY precision/size value, returns a string representation. */
572 static char retbuf
[sizeof "90000000.00"];
574 int mantissa
, exponent
;
576 mantissa
= (int)((prec
>> 4) & 0x0f) % 10;
577 exponent
= (int)((prec
>> 0) & 0x0f) % 10;
579 val
= mantissa
* poweroften
[exponent
];
581 (void) sprintf(retbuf
, "%ld.%.2ld", val
/100, val
%100);
585 /* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
591 unsigned int mval
= 0, cmval
= 0;
600 mval
= mval
* 10 + (*cp
++ - '0');
602 if (*cp
== '.') { /* centimeters */
605 cmval
= (*cp
++ - '0') * 10;
607 cmval
+= (*cp
++ - '0');
611 cmval
= (mval
* 100) + cmval
;
613 for (exponent
= 0; exponent
< 9; exponent
++)
614 if (cmval
< poweroften
[exponent
+1])
617 mantissa
= cmval
/ poweroften
[exponent
];
621 retval
= (u_int8_t
)((mantissa
<< 4) | exponent
);
628 /* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
637 int deg
= 0, min
= 0, secs
= 0, secsfrac
= 0;
642 deg
= deg
* 10 + (*cp
++ - '0');
651 min
= min
* 10 + (*cp
++ - '0');
660 secs
= secs
* 10 + (*cp
++ - '0');
662 if (*cp
== '.') { /* decimal seconds */
665 secsfrac
= (*cp
++ - '0') * 100;
667 secsfrac
+= (*cp
++ - '0') * 10;
669 secsfrac
+= (*cp
++ - '0');
675 while (!isspace(*cp
)) /* if any trailing garbage */
685 retval
= ((unsigned)1<<31)
686 + (((((deg
* 60) + min
) * 60) + secs
) * 1000)
691 retval
= ((unsigned)1<<31)
692 - (((((deg
* 60) + min
) * 60) + secs
) * 1000)
696 retval
= 0; /* invalid value -- indicates error */
703 *which
= 1; /* latitude */
707 *which
= 2; /* longitude */
710 *which
= 0; /* error */
714 cp
++; /* skip the hemisphere */
716 while (!isspace(*cp
)) /* if any trailing garbage */
719 while (isspace(*cp
)) /* move to next field */
727 /* converts a zone file representation in a string to an RDATA on-the-wire
735 const char *cp
, *maxcp
;
738 u_int32_t latit
= 0, longit
= 0, alt
= 0;
739 u_int32_t lltemp1
= 0, lltemp2
= 0;
740 int altmeters
= 0, altfrac
= 0, altsign
= 1;
741 u_int8_t hp
= 0x16; /* default = 1e6 cm = 10000.00m = 10km */
742 u_int8_t vp
= 0x13; /* default = 1e3 cm = 10.00m */
743 u_int8_t siz
= 0x12; /* default = 1e2 cm = 1.00m */
744 int which1
= 0, which2
= 0;
747 maxcp
= cp
+ strlen(ascii
);
749 lltemp1
= latlon2ul((char **)&cp
, &which1
);
751 lltemp2
= latlon2ul((char **)&cp
, &which2
);
753 switch (which1
+ which2
) {
754 case 3: /* 1 + 2, the only valid combination */
755 if ((which1
== 1) && (which2
== 2)) { /* normal case */
758 } else if ((which1
== 2) && (which2
== 1)) { /* reversed */
761 } else { /* some kind of brokenness */
765 default: /* we didn't get one of each */
779 altmeters
= altmeters
* 10 + (*cp
++ - '0');
781 if (*cp
== '.') { /* decimal meters */
784 altfrac
= (*cp
++ - '0') * 10;
786 altfrac
+= (*cp
++ - '0');
791 alt
= (10000000 + (altsign
* (altmeters
* 100 + altfrac
)));
793 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
796 while (isspace(*cp
) && (cp
< maxcp
))
802 siz
= precsize_aton((char **)&cp
);
804 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
807 while (isspace(*cp
) && (cp
< maxcp
))
813 hp
= precsize_aton((char **)&cp
);
815 while (!isspace(*cp
) && (cp
< maxcp
)) /* if trailing garbage or m */
818 while (isspace(*cp
) && (cp
< maxcp
))
824 vp
= precsize_aton((char **)&cp
);
829 *bcp
++ = (u_int8_t
) 0; /* version byte */
837 return (16); /* size of RR in octets */
840 /* takes an on-the-wire LOC RR and formats it in a human readable format. */
843 const u_char
*binary
,
847 static char *error
= "?";
848 const u_char
*cp
= binary
;
850 int latdeg
, latmin
, latsec
, latsecfrac
;
851 int longdeg
, longmin
, longsec
, longsecfrac
;
852 char northsouth
, eastwest
;
853 int altmeters
, altfrac
, altsign
;
855 const u_int32_t referencealt
= 100000 * 100;
857 int32_t latval
, longval
, altval
;
859 u_int8_t sizeval
, hpval
, vpval
, versionval
;
861 char *sizestr
, *hpstr
, *vpstr
;
866 (void) sprintf(ascii
, "; error: unknown LOC RR version");
876 latval
= (templ
- ((unsigned)1<<31));
879 longval
= (templ
- ((unsigned)1<<31));
882 if (templ
< referencealt
) { /* below WGS 84 spheroid */
883 altval
= referencealt
- templ
;
886 altval
= templ
- referencealt
;
896 latsecfrac
= latval
% 1000;
897 latval
= latval
/ 1000;
898 latsec
= latval
% 60;
899 latval
= latval
/ 60;
900 latmin
= latval
% 60;
901 latval
= latval
/ 60;
910 longsecfrac
= longval
% 1000;
911 longval
= longval
/ 1000;
912 longsec
= longval
% 60;
913 longval
= longval
/ 60;
914 longmin
= longval
% 60;
915 longval
= longval
/ 60;
918 altfrac
= altval
% 100;
919 altmeters
= (altval
/ 100) * altsign
;
921 if ((sizestr
= strdup(precsize_ntoa(sizeval
))) == NULL
)
923 if ((hpstr
= strdup(precsize_ntoa(hpval
))) == NULL
)
925 if ((vpstr
= strdup(precsize_ntoa(vpval
))) == NULL
)
929 "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
930 latdeg
, latmin
, latsec
, latsecfrac
, northsouth
,
931 longdeg
, longmin
, longsec
, longsecfrac
, eastwest
,
932 altmeters
, altfrac
, sizestr
, hpstr
, vpstr
);
934 if (sizestr
!= error
)
945 /* Return the number of DNS hierarchy levels in the name. */
947 dn_count_labels(const char *name
) {
950 len
= (int)strlen(name
);
951 for (i
= 0, count
= 0; i
< len
; i
++) {
952 /* XXX need to check for \. or use named's nlabels(). */
957 /* don't count initial wildcard */
962 /* don't count the null label for root. */
963 /* if terminating '.' not found, must adjust */
964 /* count to include last label */
965 if (len
> 0 && name
[len
-1] != '.')
972 * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
973 * SIG records are required to be printed like this, by the Secure DNS RFC.
976 p_secstodate (u_long secs
) {
977 static char output
[15]; /* YYYYMMDDHHMMSS and null */
978 time_t clock
= (time_t)secs
;
981 time
= gmtime(&clock
);
982 time
->tm_year
+= 1900;
984 sprintf(output
, "%04d%02d%02d%02d%02d%02d",
985 time
->tm_year
, time
->tm_mon
, time
->tm_mday
,
986 time
->tm_hour
, time
->tm_min
, time
->tm_sec
);