2 * Copyright (c) 1985, 1990 Regents of the University of California.
4 * Copyright (C) 2005 - 2007 The AROS Dev Team
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)res_debug.c 5.36 (Berkeley) 3/6/91
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid
[] = "@(#)res_debug.c 5.36 (Berkeley) 3/6/91";
39 #endif /* LIBC_SCCS and not lint */
45 #include <sys/param.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
48 //#include <api/arpa_nameser.h>
49 #include <api/apicalls.h>
50 #include <api/resolv.h>
52 /* #include <string.h> */
55 char *__p_class(), *__p_time(), *__p_type();
56 static char *p_cdname(), *p_rr();
58 char *_res_opcodes
[] = {
77 char *_res_resultcodes
[] = {
96 __p_query(msg
, libPtr
)
98 struct SocketBase
*libPtr
;
100 __fp_query(msg
,libPtr
);
104 * Print the contents of a query.
105 * This is intended to be primarily a debugging routine.
108 __fp_query(msg
,libPtr
)
110 struct SocketBase
*libPtr
;
117 * Print header fields.
120 cp
= msg
+ sizeof(HEADER
);
122 Printf("\topcode = %s", _res_opcodes
[hp
->opcode
]);
123 Printf(", id = %ld", ntohs(hp
->id
));
124 Printf(", rcode = %s\n", _res_resultcodes
[hp
->rcode
]);
125 Printf("\theader flags: ");
138 Printf("\n\tqdcount = %ld", ntohs(hp
->qdcount
));
139 Printf(", ancount = %ld", ntohs(hp
->ancount
));
140 Printf(", nscount = %ld", ntohs(hp
->nscount
));
141 Printf(", arcount = %ld\n\n", ntohs(hp
->arcount
));
143 * Print question records.
145 if (n
= ntohs(hp
->qdcount
)) {
146 Printf("QUESTIONS:\n");
149 cp
= p_cdname(cp
, msg
);
152 Printf(", type = %s", __p_type(_getshort(cp
)));
153 cp
+= sizeof(u_short
);
155 ", class = %s\n\n", __p_class(_getshort(cp
)));
156 cp
+= sizeof(u_short
);
160 * Print authoritative answer records
162 if (n
= ntohs(hp
->ancount
)) {
163 Printf("ANSWERS:\n");
166 cp
= p_rr(cp
, msg
, libPtr
);
172 * print name server records
174 if (n
= ntohs(hp
->nscount
)) {
175 Printf("NAME SERVERS:\n");
178 cp
= p_rr(cp
, msg
, libPtr
);
184 * print additional records
186 if (n
= ntohs(hp
->arcount
)) {
187 Printf("ADDITIONAL RECORDS:\n");
190 cp
= p_rr(cp
, msg
, libPtr
);
204 if ((n
= dn_expand((u_char
*)msg
, (u_char
*)msg
+ 512, (u_char
*)cp
,
205 (u_char
*)name
, sizeof(name
))) < 0)
207 if (name
[0] == '\0') {
216 * Print resource record fields in human readable form.
219 p_rr(cp
, msg
, libPtr
)
221 struct SocketBase
*libPtr
;
223 int type
, class, dlen
, n
, c
;
224 struct in_addr inaddr
;
227 if ((cp
= p_cdname(cp
, msg
)) == NULL
)
228 return (NULL
); /* compression error */
229 Printf("\n\ttype = %s", __p_type(type
= _getshort(cp
)));
230 cp
+= sizeof(u_short
);
231 Printf(", class = %s", __p_class(class = _getshort(cp
)));
232 cp
+= sizeof(u_short
);
233 Printf(", ttl = %s", __p_time(_getlong(cp
)));
234 cp
+= sizeof(u_long
);
235 Printf(", dlen = %d\n", dlen
= _getshort(cp
));
236 cp
+= sizeof(u_short
);
239 * Print type specific data, if appropriate
246 bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
248 Printf("\tinternet address = %s\n",
249 __Inet_NtoA(inaddr
.s_addr
, libPtr
));
251 } else if (dlen
== 7) {
252 Printf("\tinternet address = %s",
253 __Inet_NtoA(inaddr
.s_addr
, libPtr
));
254 Printf(", protocol = %d", cp
[4]);
255 Printf(", port = %d\n",
256 (cp
[5] << 8) + cp
[6]);
270 Printf("\tdomain name = ");
271 cp
= p_cdname(cp
, msg
);
277 Printf("\tCPU=%.*s\n", n
, cp
);
281 Printf("\tOS=%.*s\n", n
, cp
);
287 Printf("\torigin = ");
288 cp
= p_cdname(cp
, msg
);
289 Printf("\n\tmail addr = ");
290 cp
= p_cdname(cp
, msg
);
291 Printf("\n\tserial = %ld", _getlong(cp
));
292 cp
+= sizeof(u_long
);
293 Printf("\n\trefresh = %s", __p_time(_getlong(cp
)));
294 cp
+= sizeof(u_long
);
295 Printf("\n\tretry = %s", __p_time(_getlong(cp
)));
296 cp
+= sizeof(u_long
);
297 Printf("\n\texpire = %s", __p_time(_getlong(cp
)));
298 cp
+= sizeof(u_long
);
299 Printf("\n\tmin = %s\n", __p_time(_getlong(cp
)));
300 cp
+= sizeof(u_long
);
304 Printf("\tpreference = %ld,",_getshort(cp
));
305 cp
+= sizeof(u_short
);
307 cp
= p_cdname(cp
, msg
);
314 if (n
= (unsigned char) *cp
++) {
315 for (c
= n
; c
> 0 && cp
< cp2
; c
--)
327 Printf("\trequests = ");
328 cp
= p_cdname(cp
, msg
);
329 Printf("\n\terrors = ");
330 cp
= p_cdname(cp
, msg
);
334 Printf("\t%s\n", cp
);
341 Printf("\t%ld\n", _getlong(cp
));
347 if (dlen
< sizeof(u_long
) + 1)
349 bcopy(cp
, (char *)&inaddr
, sizeof(inaddr
));
350 cp
+= sizeof(u_long
);
351 Printf("\tinternet address = %s, protocol = %d\n\t",
352 __Inet_NtoA(inaddr
.s_addr
, libPtr
), *cp
++);
354 while (cp
< cp1
+ dlen
) {
365 #ifdef ALLOW_T_UNSPEC
372 if (dlen
< NumBytes
) NumBytes
= dlen
;
373 Printf( "\tFirst %ld bytes of hex data:",
375 for (i
= 0, DataPtr
= cp
; i
< NumBytes
; i
++, DataPtr
++)
376 Printf( " %x", *DataPtr
);
381 #endif /* ALLOW_T_UNSPEC */
387 if (cp
!= cp1
+ dlen
) {
388 Printf("packet size error (%#x != %#x)\n", cp
, cp1
+dlen
);
395 static char nbuf
[40];
398 * Return a string for the type
407 case T_NS
: /* authoritative server */
409 case T_CNAME
: /* canonical name */
411 case T_SOA
: /* start of authority zone */
413 case T_MB
: /* mailbox domain name */
415 case T_MG
: /* mail group member */
417 case T_MR
: /* mail rename name */
419 case T_NULL
: /* null resource record */
421 case T_WKS
: /* well known service */
423 case T_PTR
: /* domain name pointer */
425 case T_HINFO
: /* host information */
427 case T_MINFO
: /* mailbox information */
429 case T_MX
: /* mail routing info */
431 case T_TXT
: /* text */
433 case T_AXFR
: /* zone transfer */
435 case T_MAILB
: /* mail box */
437 case T_MAILA
: /* mail address */
439 case T_ANY
: /* matches any type */
447 #ifdef ALLOW_T_UNSPEC
450 #endif /* ALLOW_T_UNSPEC */
452 (void)sprintf(nbuf
, "%ld", type
);
458 * Return a mnemonic for class
466 case C_IN
: /* internet class */
468 case C_HS
: /* hesiod class */
470 case C_ANY
: /* matches any class */
473 (void)sprintf(nbuf
, "%ld", class);
479 * Return a mnemonic for a time to live
485 int secs
, mins
, hours
;
489 strcpy(nbuf
, "0 secs");
500 #define PLURALIZE(x) x, (x == 1) ? "" : "s"
503 (void)sprintf(p
, "%ld day%s", PLURALIZE(value
));
509 (void)sprintf(p
, "%ld hour%s", PLURALIZE(hours
));
515 (void)sprintf(p
, "%ld min%s", PLURALIZE(mins
));
518 if (secs
|| ! (value
|| hours
|| mins
)) {
519 if (value
|| hours
|| mins
)
521 (void)sprintf(p
, "%ld sec%s", PLURALIZE(secs
));
526 #endif /* RES_DEBUG */