4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <sys/types.h>
43 #include <netinet/in.h>
45 #include <arpa/nameser.h>
47 extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
48 extern char *inet_ntoa();
49 void fp_query(char *msg
, FILE *file
);
51 char *_res_opcodes
[] = {
70 char *_res_resultcodes
[] = {
93 fp_query(msg
, stdout
);
97 * Print the contents of a query.
98 * This is intended to be primarily a debugging routine.
110 * Print header fields.
113 cp
= msg
+ sizeof (HEADER
);
114 fprintf(file
, "HEADER:\n");
115 fprintf(file
, "\topcode = %s", _res_opcodes
[hp
->opcode
]);
116 fprintf(file
, ", id = %d", ntohs(hp
->id
));
117 fprintf(file
, ", rcode = %s\n", _res_resultcodes
[hp
->rcode
]);
118 fprintf(file
, "\theader flags: ");
120 fprintf(file
, " qr");
122 fprintf(file
, " aa");
124 fprintf(file
, " tc");
126 fprintf(file
, " rd");
128 fprintf(file
, " ra");
130 fprintf(file
, " pr");
131 fprintf(file
, "\n\tqdcount = %d", ntohs(hp
->qdcount
));
132 fprintf(file
, ", ancount = %d", ntohs(hp
->ancount
));
133 fprintf(file
, ", nscount = %d", ntohs(hp
->nscount
));
134 fprintf(file
, ", arcount = %d\n\n", ntohs(hp
->arcount
));
136 * Print question records.
138 if (n
= ntohs(hp
->qdcount
)) {
139 fprintf(file
, "QUESTIONS:\n");
142 cp
= p_cdname(cp
, msg
, file
);
145 fprintf(file
, ", type = %s", p_type(_getshort(cp
)));
146 cp
+= sizeof (u_short
);
147 fprintf(file
, ", class = %s\n\n",
148 p_class(_getshort(cp
)));
149 cp
+= sizeof (u_short
);
153 * Print authoritative answer records
155 if (n
= ntohs(hp
->ancount
)) {
156 fprintf(file
, "ANSWERS:\n");
159 cp
= p_rr(cp
, msg
, file
);
165 * print name server records
167 if (n
= ntohs(hp
->nscount
)) {
168 fprintf(file
, "NAME SERVERS:\n");
171 cp
= p_rr(cp
, msg
, file
);
177 * print additional records
179 if (n
= ntohs(hp
->arcount
)) {
180 fprintf(file
, "ADDITIONAL RECORDS:\n");
183 cp
= p_rr(cp
, msg
, file
);
191 p_cdname(cp
, msg
, file
)
198 if ((n
= dn_expand(msg
, msg
+ 512, cp
, name
, sizeof (name
))) < 0)
200 if (name
[0] == '\0') {
209 * Print resource record fields in human readable form.
216 int type
, class, dlen
, n
, c
;
217 struct in_addr inaddr
;
220 if ((cp
= p_cdname(cp
, msg
, file
)) == NULL
)
221 return (NULL
); /* compression error */
222 fprintf(file
, "\n\ttype = %s", p_type(type
= _getshort(cp
)));
223 cp
+= sizeof (u_short
);
224 fprintf(file
, ", class = %s", p_class(class = _getshort(cp
)));
225 cp
+= sizeof (u_short
);
226 fprintf(file
, ", ttl = %s", p_time(_getlong(cp
)));
227 cp
+= sizeof (u_long
);
228 fprintf(file
, ", dlen = %d\n", dlen
= _getshort(cp
));
229 cp
+= sizeof (u_short
);
232 * Print type specific data, if appropriate
240 memcpy((void *)&inaddr
, (void *)cp
, sizeof (inaddr
));
242 bcopy(cp
, (char *)&inaddr
, sizeof (inaddr
));
245 fprintf(file
, "\tinternet address = %s\n",
248 } else if (dlen
== 7) {
249 fprintf(file
, "\tinternet address = %s",
251 fprintf(file
, ", protocol = %d", cp
[4]);
252 fprintf(file
, ", port = %d\n",
253 (cp
[5] << 8) + cp
[6]);
267 fprintf(file
, "\tdomain name = ");
268 cp
= p_cdname(cp
, msg
, file
);
274 fprintf(file
, "\tCPU=%.*s\n", n
, cp
);
278 fprintf(file
, "\tOS=%.*s\n", n
, cp
);
284 fprintf(file
, "\torigin = ");
285 cp
= p_cdname(cp
, msg
, file
);
286 fprintf(file
, "\n\tmail addr = ");
287 cp
= p_cdname(cp
, msg
, file
);
288 fprintf(file
, "\n\tserial = %ld", _getlong(cp
));
289 cp
+= sizeof (u_long
);
290 fprintf(file
, "\n\trefresh = %s", p_time(_getlong(cp
)));
291 cp
+= sizeof (u_long
);
292 fprintf(file
, "\n\tretry = %s", p_time(_getlong(cp
)));
293 cp
+= sizeof (u_long
);
294 fprintf(file
, "\n\texpire = %s", p_time(_getlong(cp
)));
295 cp
+= sizeof (u_long
);
296 fprintf(file
, "\n\tmin = %s\n", p_time(_getlong(cp
)));
297 cp
+= sizeof (u_long
);
301 fprintf(file
, "\tpreference = %ld,", _getshort(cp
));
302 cp
+= sizeof (u_short
);
303 fprintf(file
, " name = ");
304 cp
= p_cdname(cp
, msg
, file
);
308 (void) fputs("\t\"", file
);
311 if (n
= (unsigned char) *cp
++) {
312 for (c
= n
; c
> 0 && cp
< cp2
; c
--)
314 (void) putc('\\', file
);
315 (void) putc(*cp
++, file
);
317 (void) putc(*cp
++, file
);
320 (void) fputs("\"\n", file
);
324 fprintf(file
, "\trequests = ");
325 cp
= p_cdname(cp
, msg
, file
);
326 fprintf(file
, "\n\terrors = ");
327 cp
= p_cdname(cp
, msg
, file
);
331 fprintf(file
, "\t%s\n", cp
);
338 fprintf(file
, "\t%ld\n", _getlong(cp
));
344 if (dlen
< sizeof (u_long
) + 1)
347 memcpy((void *)&inaddr
, (void *)cp
, sizeof (inaddr
));
349 bcopy(cp
, (char *)&inaddr
, sizeof (inaddr
));
351 cp
+= sizeof (u_long
);
352 fprintf(file
, "\tinternet address = %s, protocol = %d\n\t",
353 inet_ntoa(inaddr
), *cp
++);
355 while (cp
< cp1
+ dlen
) {
359 fprintf(file
, " %d", n
);
366 #ifdef ALLOW_T_UNSPEC
373 if (dlen
< NumBytes
) NumBytes
= dlen
;
374 fprintf(file
, "\tFirst %d bytes of hex data:",
376 for (i
= 0, DataPtr
= cp
; i
< NumBytes
; i
++, DataPtr
++)
377 fprintf(file
, " %x", *DataPtr
);
382 #endif /* ALLOW_T_UNSPEC */
385 fprintf(file
, "\t???\n");
388 if (cp
!= cp1
+ dlen
) {
389 fprintf(file
, "packet size error (%#x != %#x)\n", cp
, cp1
+dlen
);
396 static char nbuf
[40];
399 * Return a string for the type
408 case T_NS
: /* authoritative server */
410 case T_CNAME
: /* canonical name */
412 case T_SOA
: /* start of authority zone */
414 case T_MB
: /* mailbox domain name */
416 case T_MG
: /* mail group member */
418 case T_MR
: /* mail rename name */
420 case T_NULL
: /* null resource record */
422 case T_WKS
: /* well known service */
424 case T_PTR
: /* domain name pointer */
426 case T_HINFO
: /* host information */
428 case T_MINFO
: /* mailbox information */
430 case T_MX
: /* mail routing info */
432 case T_TXT
: /* text */
434 case T_AXFR
: /* zone transfer */
436 case T_MAILB
: /* mail box */
438 case T_MAILA
: /* mail address */
440 case T_ANY
: /* matches any type */
448 #ifdef ALLOW_T_UNSPEC
451 #endif /* ALLOW_T_UNSPEC */
453 (void) sprintf(nbuf
, "%d", type
);
459 * Return a mnemonic for class
467 case C_IN
: /* internet class */
469 case C_HS
: /* hesiod class */
471 case C_ANY
: /* matches any class */
474 (void) sprintf(nbuf
, "%d", class);
480 * Return a mnemonic for a time to live
486 int secs
, mins
, hours
;
490 strcpy(nbuf
, "0 secs");
501 #define PLURALIZE(x) x, (x == 1) ? "" : "s"
504 (void) sprintf(p
, "%d day%s", PLURALIZE(value
));
510 (void) sprintf(p
, "%d hour%s", PLURALIZE(hours
));
516 (void) sprintf(p
, "%d min%s", PLURALIZE(mins
));
519 if (secs
|| ! (value
|| hours
|| mins
)) {
520 if (value
|| hours
|| mins
)
522 (void) sprintf(p
, "%d sec%s", PLURALIZE(secs
));