xref: /titanic_41/usr/src/lib/libresolv/res_debug.c (revision 7257d1b4d25bfac0c802847390e98a464fd787ac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7257d1b4Sraf  * Common Development and Distribution License (the "License").
6*7257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21e8031f0aSraf 
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <netinet/in.h>
447c478bd9Sstevel@tonic-gate #include <stdio.h>
457c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
487c478bd9Sstevel@tonic-gate extern char *inet_ntoa();
496a1c6faaSanay void fp_query(char *msg, FILE *file);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate char *_res_opcodes[] = {
527c478bd9Sstevel@tonic-gate 	"QUERY",
537c478bd9Sstevel@tonic-gate 	"IQUERY",
547c478bd9Sstevel@tonic-gate 	"CQUERYM",
557c478bd9Sstevel@tonic-gate 	"CQUERYU",
567c478bd9Sstevel@tonic-gate 	"4",
577c478bd9Sstevel@tonic-gate 	"5",
587c478bd9Sstevel@tonic-gate 	"6",
597c478bd9Sstevel@tonic-gate 	"7",
607c478bd9Sstevel@tonic-gate 	"8",
617c478bd9Sstevel@tonic-gate 	"UPDATEA",
627c478bd9Sstevel@tonic-gate 	"UPDATED",
637c478bd9Sstevel@tonic-gate 	"UPDATEDA",
647c478bd9Sstevel@tonic-gate 	"UPDATEM",
657c478bd9Sstevel@tonic-gate 	"UPDATEMA",
667c478bd9Sstevel@tonic-gate 	"ZONEINIT",
677c478bd9Sstevel@tonic-gate 	"ZONEREF",
687c478bd9Sstevel@tonic-gate };
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate char *_res_resultcodes[] = {
717c478bd9Sstevel@tonic-gate 	"NOERROR",
727c478bd9Sstevel@tonic-gate 	"FORMERR",
737c478bd9Sstevel@tonic-gate 	"SERVFAIL",
747c478bd9Sstevel@tonic-gate 	"NXDOMAIN",
757c478bd9Sstevel@tonic-gate 	"NOTIMP",
767c478bd9Sstevel@tonic-gate 	"REFUSED",
777c478bd9Sstevel@tonic-gate 	"6",
787c478bd9Sstevel@tonic-gate 	"7",
797c478bd9Sstevel@tonic-gate 	"8",
807c478bd9Sstevel@tonic-gate 	"9",
817c478bd9Sstevel@tonic-gate 	"10",
827c478bd9Sstevel@tonic-gate 	"11",
837c478bd9Sstevel@tonic-gate 	"12",
847c478bd9Sstevel@tonic-gate 	"13",
857c478bd9Sstevel@tonic-gate 	"14",
867c478bd9Sstevel@tonic-gate 	"NOCHANGE",
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
896a1c6faaSanay void
p_query(msg)907c478bd9Sstevel@tonic-gate p_query(msg)
917c478bd9Sstevel@tonic-gate 	char *msg;
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	fp_query(msg, stdout);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Print the contents of a query.
987c478bd9Sstevel@tonic-gate  * This is intended to be primarily a debugging routine.
997c478bd9Sstevel@tonic-gate  */
1006a1c6faaSanay void
fp_query(msg,file)1017c478bd9Sstevel@tonic-gate fp_query(msg, file)
1027c478bd9Sstevel@tonic-gate 	char *msg;
1037c478bd9Sstevel@tonic-gate 	FILE *file;
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	register char *cp;
1067c478bd9Sstevel@tonic-gate 	register HEADER *hp;
1077c478bd9Sstevel@tonic-gate 	register int n;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/*
1107c478bd9Sstevel@tonic-gate 	 * Print header fields.
1117c478bd9Sstevel@tonic-gate 	 */
1127c478bd9Sstevel@tonic-gate 	hp = (HEADER *)msg;
1137c478bd9Sstevel@tonic-gate 	cp = msg + sizeof (HEADER);
1147c478bd9Sstevel@tonic-gate 	fprintf(file, "HEADER:\n");
1157c478bd9Sstevel@tonic-gate 	fprintf(file, "\topcode = %s", _res_opcodes[hp->opcode]);
1167c478bd9Sstevel@tonic-gate 	fprintf(file, ", id = %d", ntohs(hp->id));
1177c478bd9Sstevel@tonic-gate 	fprintf(file, ", rcode = %s\n", _res_resultcodes[hp->rcode]);
1187c478bd9Sstevel@tonic-gate 	fprintf(file, "\theader flags: ");
1197c478bd9Sstevel@tonic-gate 	if (hp->qr)
1207c478bd9Sstevel@tonic-gate 		fprintf(file, " qr");
1217c478bd9Sstevel@tonic-gate 	if (hp->aa)
1227c478bd9Sstevel@tonic-gate 		fprintf(file, " aa");
1237c478bd9Sstevel@tonic-gate 	if (hp->tc)
1247c478bd9Sstevel@tonic-gate 		fprintf(file, " tc");
1257c478bd9Sstevel@tonic-gate 	if (hp->rd)
1267c478bd9Sstevel@tonic-gate 		fprintf(file, " rd");
1277c478bd9Sstevel@tonic-gate 	if (hp->ra)
1287c478bd9Sstevel@tonic-gate 		fprintf(file, " ra");
1297c478bd9Sstevel@tonic-gate 	if (hp->pr)
1307c478bd9Sstevel@tonic-gate 		fprintf(file, " pr");
1317c478bd9Sstevel@tonic-gate 	fprintf(file, "\n\tqdcount = %d", ntohs(hp->qdcount));
1327c478bd9Sstevel@tonic-gate 	fprintf(file, ", ancount = %d", ntohs(hp->ancount));
1337c478bd9Sstevel@tonic-gate 	fprintf(file, ", nscount = %d", ntohs(hp->nscount));
1347c478bd9Sstevel@tonic-gate 	fprintf(file, ", arcount = %d\n\n", ntohs(hp->arcount));
1357c478bd9Sstevel@tonic-gate 	/*
1367c478bd9Sstevel@tonic-gate 	 * Print question records.
1377c478bd9Sstevel@tonic-gate 	 */
1387c478bd9Sstevel@tonic-gate 	if (n = ntohs(hp->qdcount)) {
1397c478bd9Sstevel@tonic-gate 		fprintf(file, "QUESTIONS:\n");
1407c478bd9Sstevel@tonic-gate 		while (--n >= 0) {
1417c478bd9Sstevel@tonic-gate 			fprintf(file, "\t");
1427c478bd9Sstevel@tonic-gate 			cp = p_cdname(cp, msg, file);
1437c478bd9Sstevel@tonic-gate 			if (cp == NULL)
1447c478bd9Sstevel@tonic-gate 				return;
1457c478bd9Sstevel@tonic-gate 			fprintf(file, ", type = %s", p_type(_getshort(cp)));
1467c478bd9Sstevel@tonic-gate 			cp += sizeof (u_short);
1477c478bd9Sstevel@tonic-gate 			fprintf(file, ", class = %s\n\n",
1487c478bd9Sstevel@tonic-gate 						p_class(_getshort(cp)));
1497c478bd9Sstevel@tonic-gate 			cp += sizeof (u_short);
1507c478bd9Sstevel@tonic-gate 		}
1517c478bd9Sstevel@tonic-gate 	}
1527c478bd9Sstevel@tonic-gate 	/*
1537c478bd9Sstevel@tonic-gate 	 * Print authoritative answer records
1547c478bd9Sstevel@tonic-gate 	 */
1557c478bd9Sstevel@tonic-gate 	if (n = ntohs(hp->ancount)) {
1567c478bd9Sstevel@tonic-gate 		fprintf(file, "ANSWERS:\n");
1577c478bd9Sstevel@tonic-gate 		while (--n >= 0) {
1587c478bd9Sstevel@tonic-gate 			fprintf(file, "\t");
1597c478bd9Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1607c478bd9Sstevel@tonic-gate 			if (cp == NULL)
1617c478bd9Sstevel@tonic-gate 				return;
1627c478bd9Sstevel@tonic-gate 		}
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 	/*
1657c478bd9Sstevel@tonic-gate 	 * print name server records
1667c478bd9Sstevel@tonic-gate 	 */
1677c478bd9Sstevel@tonic-gate 	if (n = ntohs(hp->nscount)) {
1687c478bd9Sstevel@tonic-gate 		fprintf(file, "NAME SERVERS:\n");
1697c478bd9Sstevel@tonic-gate 		while (--n >= 0) {
1707c478bd9Sstevel@tonic-gate 			fprintf(file, "\t");
1717c478bd9Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1727c478bd9Sstevel@tonic-gate 			if (cp == NULL)
1737c478bd9Sstevel@tonic-gate 				return;
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 	/*
1777c478bd9Sstevel@tonic-gate 	 * print additional records
1787c478bd9Sstevel@tonic-gate 	 */
1797c478bd9Sstevel@tonic-gate 	if (n = ntohs(hp->arcount)) {
1807c478bd9Sstevel@tonic-gate 		fprintf(file, "ADDITIONAL RECORDS:\n");
1817c478bd9Sstevel@tonic-gate 		while (--n >= 0) {
1827c478bd9Sstevel@tonic-gate 			fprintf(file, "\t");
1837c478bd9Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1847c478bd9Sstevel@tonic-gate 			if (cp == NULL)
1857c478bd9Sstevel@tonic-gate 				return;
1867c478bd9Sstevel@tonic-gate 		}
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate char *
p_cdname(cp,msg,file)1917c478bd9Sstevel@tonic-gate p_cdname(cp, msg, file)
1927c478bd9Sstevel@tonic-gate 	char *cp, *msg;
1937c478bd9Sstevel@tonic-gate 	FILE *file;
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate 	char name[MAXDNAME];
1967c478bd9Sstevel@tonic-gate 	int n;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if ((n = dn_expand(msg, msg + 512, cp, name, sizeof (name))) < 0)
1997c478bd9Sstevel@tonic-gate 		return (NULL);
2007c478bd9Sstevel@tonic-gate 	if (name[0] == '\0') {
2017c478bd9Sstevel@tonic-gate 		name[0] = '.';
2027c478bd9Sstevel@tonic-gate 		name[1] = '\0';
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 	fputs(name, file);
2057c478bd9Sstevel@tonic-gate 	return (cp + n);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Print resource record fields in human readable form.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate char *
p_rr(cp,msg,file)2127c478bd9Sstevel@tonic-gate p_rr(cp, msg, file)
2137c478bd9Sstevel@tonic-gate 	char *cp, *msg;
2147c478bd9Sstevel@tonic-gate 	FILE *file;
2157c478bd9Sstevel@tonic-gate {
2167c478bd9Sstevel@tonic-gate 	int type, class, dlen, n, c;
2177c478bd9Sstevel@tonic-gate 	struct in_addr inaddr;
2187c478bd9Sstevel@tonic-gate 	char *cp1, *cp2;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	if ((cp = p_cdname(cp, msg, file)) == NULL)
2217c478bd9Sstevel@tonic-gate 		return (NULL);			/* compression error */
2227c478bd9Sstevel@tonic-gate 	fprintf(file, "\n\ttype = %s", p_type(type = _getshort(cp)));
2237c478bd9Sstevel@tonic-gate 	cp += sizeof (u_short);
2247c478bd9Sstevel@tonic-gate 	fprintf(file, ", class = %s", p_class(class = _getshort(cp)));
2257c478bd9Sstevel@tonic-gate 	cp += sizeof (u_short);
2267c478bd9Sstevel@tonic-gate 	fprintf(file, ", ttl = %s", p_time(_getlong(cp)));
2277c478bd9Sstevel@tonic-gate 	cp += sizeof (u_long);
2287c478bd9Sstevel@tonic-gate 	fprintf(file, ", dlen = %d\n", dlen = _getshort(cp));
2297c478bd9Sstevel@tonic-gate 	cp += sizeof (u_short);
2307c478bd9Sstevel@tonic-gate 	cp1 = cp;
2317c478bd9Sstevel@tonic-gate 	/*
2327c478bd9Sstevel@tonic-gate 	 * Print type specific data, if appropriate
2337c478bd9Sstevel@tonic-gate 	 */
2347c478bd9Sstevel@tonic-gate 	switch (type) {
2357c478bd9Sstevel@tonic-gate 	case T_A:
2367c478bd9Sstevel@tonic-gate 		switch (class) {
2377c478bd9Sstevel@tonic-gate 		case C_IN:
2387c478bd9Sstevel@tonic-gate 		case C_HS:
2397c478bd9Sstevel@tonic-gate #ifdef SYSV
2407c478bd9Sstevel@tonic-gate 			memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
2417c478bd9Sstevel@tonic-gate #else
2427c478bd9Sstevel@tonic-gate 			bcopy(cp, (char *)&inaddr, sizeof (inaddr));
2437c478bd9Sstevel@tonic-gate #endif
2447c478bd9Sstevel@tonic-gate 			if (dlen == 4) {
2457c478bd9Sstevel@tonic-gate 				fprintf(file, "\tinternet address = %s\n",
2467c478bd9Sstevel@tonic-gate 					inet_ntoa(inaddr));
2477c478bd9Sstevel@tonic-gate 				cp += dlen;
2487c478bd9Sstevel@tonic-gate 			} else if (dlen == 7) {
2497c478bd9Sstevel@tonic-gate 				fprintf(file, "\tinternet address = %s",
2507c478bd9Sstevel@tonic-gate 					inet_ntoa(inaddr));
2517c478bd9Sstevel@tonic-gate 				fprintf(file, ", protocol = %d", cp[4]);
2527c478bd9Sstevel@tonic-gate 				fprintf(file, ", port = %d\n",
2537c478bd9Sstevel@tonic-gate 					(cp[5] << 8) + cp[6]);
2547c478bd9Sstevel@tonic-gate 				cp += dlen;
2557c478bd9Sstevel@tonic-gate 			}
2567c478bd9Sstevel@tonic-gate 			break;
2577c478bd9Sstevel@tonic-gate 		default:
2587c478bd9Sstevel@tonic-gate 			cp += dlen;
2597c478bd9Sstevel@tonic-gate 		}
2607c478bd9Sstevel@tonic-gate 		break;
2617c478bd9Sstevel@tonic-gate 	case T_CNAME:
2627c478bd9Sstevel@tonic-gate 	case T_MB:
2637c478bd9Sstevel@tonic-gate 	case T_MG:
2647c478bd9Sstevel@tonic-gate 	case T_MR:
2657c478bd9Sstevel@tonic-gate 	case T_NS:
2667c478bd9Sstevel@tonic-gate 	case T_PTR:
2677c478bd9Sstevel@tonic-gate 		fprintf(file, "\tdomain name = ");
2687c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2697c478bd9Sstevel@tonic-gate 		fprintf(file, "\n");
2707c478bd9Sstevel@tonic-gate 		break;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	case T_HINFO:
2737c478bd9Sstevel@tonic-gate 		if (n = *cp++) {
2747c478bd9Sstevel@tonic-gate 			fprintf(file, "\tCPU=%.*s\n", n, cp);
2757c478bd9Sstevel@tonic-gate 			cp += n;
2767c478bd9Sstevel@tonic-gate 		}
2777c478bd9Sstevel@tonic-gate 		if (n = *cp++) {
2787c478bd9Sstevel@tonic-gate 			fprintf(file, "\tOS=%.*s\n", n, cp);
2797c478bd9Sstevel@tonic-gate 			cp += n;
2807c478bd9Sstevel@tonic-gate 		}
2817c478bd9Sstevel@tonic-gate 		break;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	case T_SOA:
2847c478bd9Sstevel@tonic-gate 		fprintf(file, "\torigin = ");
2857c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2867c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\tmail addr = ");
2877c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2887c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\tserial = %ld", _getlong(cp));
2897c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
2907c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\trefresh = %s", p_time(_getlong(cp)));
2917c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
2927c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\tretry = %s", p_time(_getlong(cp)));
2937c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
2947c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\texpire = %s", p_time(_getlong(cp)));
2957c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
2967c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\tmin = %s\n", p_time(_getlong(cp)));
2977c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
2987c478bd9Sstevel@tonic-gate 		break;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	case T_MX:
3017c478bd9Sstevel@tonic-gate 		fprintf(file, "\tpreference = %ld,", _getshort(cp));
3027c478bd9Sstevel@tonic-gate 		cp += sizeof (u_short);
3037c478bd9Sstevel@tonic-gate 		fprintf(file, " name = ");
3047c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3057c478bd9Sstevel@tonic-gate 		break;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	case T_TXT:
3087c478bd9Sstevel@tonic-gate 		(void) fputs("\t\"", file);
3097c478bd9Sstevel@tonic-gate 		cp2 = cp1 + dlen;
3107c478bd9Sstevel@tonic-gate 		while (cp < cp2) {
3117c478bd9Sstevel@tonic-gate 			if (n = (unsigned char) *cp++) {
3127c478bd9Sstevel@tonic-gate 				for (c = n; c > 0 && cp < cp2; c--)
3137c478bd9Sstevel@tonic-gate 					if (*cp == '\n') {
3147c478bd9Sstevel@tonic-gate 					    (void) putc('\\', file);
3157c478bd9Sstevel@tonic-gate 					    (void) putc(*cp++, file);
3167c478bd9Sstevel@tonic-gate 					} else
3177c478bd9Sstevel@tonic-gate 					    (void) putc(*cp++, file);
3187c478bd9Sstevel@tonic-gate 			}
3197c478bd9Sstevel@tonic-gate 		}
3207c478bd9Sstevel@tonic-gate 		(void) fputs("\"\n", file);
3217c478bd9Sstevel@tonic-gate 		break;
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	case T_MINFO:
3247c478bd9Sstevel@tonic-gate 		fprintf(file, "\trequests = ");
3257c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3267c478bd9Sstevel@tonic-gate 		fprintf(file, "\n\terrors = ");
3277c478bd9Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3287c478bd9Sstevel@tonic-gate 		break;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	case T_UINFO:
3317c478bd9Sstevel@tonic-gate 		fprintf(file, "\t%s\n", cp);
3327c478bd9Sstevel@tonic-gate 		cp += dlen;
3337c478bd9Sstevel@tonic-gate 		break;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	case T_UID:
3367c478bd9Sstevel@tonic-gate 	case T_GID:
3377c478bd9Sstevel@tonic-gate 		if (dlen == 4) {
3387c478bd9Sstevel@tonic-gate 			fprintf(file, "\t%ld\n", _getlong(cp));
3397c478bd9Sstevel@tonic-gate 			cp += sizeof (int);
3407c478bd9Sstevel@tonic-gate 		}
3417c478bd9Sstevel@tonic-gate 		break;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	case T_WKS:
3447c478bd9Sstevel@tonic-gate 		if (dlen < sizeof (u_long) + 1)
3457c478bd9Sstevel@tonic-gate 			break;
3467c478bd9Sstevel@tonic-gate #ifdef SYSV
3477c478bd9Sstevel@tonic-gate 		memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
3487c478bd9Sstevel@tonic-gate #else
3497c478bd9Sstevel@tonic-gate 		bcopy(cp, (char *)&inaddr, sizeof (inaddr));
3507c478bd9Sstevel@tonic-gate #endif
3517c478bd9Sstevel@tonic-gate 		cp += sizeof (u_long);
3527c478bd9Sstevel@tonic-gate 		fprintf(file, "\tinternet address = %s, protocol = %d\n\t",
3537c478bd9Sstevel@tonic-gate 			inet_ntoa(inaddr), *cp++);
3547c478bd9Sstevel@tonic-gate 		n = 0;
3557c478bd9Sstevel@tonic-gate 		while (cp < cp1 + dlen) {
3567c478bd9Sstevel@tonic-gate 			c = *cp++;
3577c478bd9Sstevel@tonic-gate 			do {
3587c478bd9Sstevel@tonic-gate 				if (c & 0200)
3597c478bd9Sstevel@tonic-gate 					fprintf(file, " %d", n);
3607c478bd9Sstevel@tonic-gate 				c <<= 1;
3617c478bd9Sstevel@tonic-gate 			} while (++n & 07);
3627c478bd9Sstevel@tonic-gate 		}
3637c478bd9Sstevel@tonic-gate 		putc('\n', file);
3647c478bd9Sstevel@tonic-gate 		break;
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC
3677c478bd9Sstevel@tonic-gate 	case T_UNSPEC:
3687c478bd9Sstevel@tonic-gate 		{
3697c478bd9Sstevel@tonic-gate 			int NumBytes = 8;
3707c478bd9Sstevel@tonic-gate 			char *DataPtr;
3717c478bd9Sstevel@tonic-gate 			int i;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 			if (dlen < NumBytes) NumBytes = dlen;
3747c478bd9Sstevel@tonic-gate 			fprintf(file, "\tFirst %d bytes of hex data:",
3757c478bd9Sstevel@tonic-gate 				NumBytes);
3767c478bd9Sstevel@tonic-gate 			for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
3777c478bd9Sstevel@tonic-gate 				fprintf(file, " %x", *DataPtr);
3787c478bd9Sstevel@tonic-gate 			fputs("\n", file);
3797c478bd9Sstevel@tonic-gate 			cp += dlen;
3807c478bd9Sstevel@tonic-gate 		}
3817c478bd9Sstevel@tonic-gate 		break;
3827c478bd9Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	default:
3857c478bd9Sstevel@tonic-gate 		fprintf(file, "\t???\n");
3867c478bd9Sstevel@tonic-gate 		cp += dlen;
3877c478bd9Sstevel@tonic-gate 	}
3887c478bd9Sstevel@tonic-gate 	if (cp != cp1 + dlen) {
3897c478bd9Sstevel@tonic-gate 		fprintf(file, "packet size error (%#x != %#x)\n", cp, cp1+dlen);
3907c478bd9Sstevel@tonic-gate 		cp = NULL;
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 	fprintf(file, "\n");
3937c478bd9Sstevel@tonic-gate 	return (cp);
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate static	char nbuf[40];
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * Return a string for the type
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate char *
p_type(type)4027c478bd9Sstevel@tonic-gate p_type(type)
4037c478bd9Sstevel@tonic-gate 	int type;
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	switch (type) {
4067c478bd9Sstevel@tonic-gate 	case T_A:
4077c478bd9Sstevel@tonic-gate 		return ("A");
4087c478bd9Sstevel@tonic-gate 	case T_NS:		/* authoritative server */
4097c478bd9Sstevel@tonic-gate 		return ("NS");
4107c478bd9Sstevel@tonic-gate 	case T_CNAME:		/* canonical name */
4117c478bd9Sstevel@tonic-gate 		return ("CNAME");
4127c478bd9Sstevel@tonic-gate 	case T_SOA:		/* start of authority zone */
4137c478bd9Sstevel@tonic-gate 		return ("SOA");
4147c478bd9Sstevel@tonic-gate 	case T_MB:		/* mailbox domain name */
4157c478bd9Sstevel@tonic-gate 		return ("MB");
4167c478bd9Sstevel@tonic-gate 	case T_MG:		/* mail group member */
4177c478bd9Sstevel@tonic-gate 		return ("MG");
4187c478bd9Sstevel@tonic-gate 	case T_MR:		/* mail rename name */
4197c478bd9Sstevel@tonic-gate 		return ("MR");
4207c478bd9Sstevel@tonic-gate 	case T_NULL:		/* null resource record */
4217c478bd9Sstevel@tonic-gate 		return ("NULL");
4227c478bd9Sstevel@tonic-gate 	case T_WKS:		/* well known service */
4237c478bd9Sstevel@tonic-gate 		return ("WKS");
4247c478bd9Sstevel@tonic-gate 	case T_PTR:		/* domain name pointer */
4257c478bd9Sstevel@tonic-gate 		return ("PTR");
4267c478bd9Sstevel@tonic-gate 	case T_HINFO:		/* host information */
4277c478bd9Sstevel@tonic-gate 		return ("HINFO");
4287c478bd9Sstevel@tonic-gate 	case T_MINFO:		/* mailbox information */
4297c478bd9Sstevel@tonic-gate 		return ("MINFO");
4307c478bd9Sstevel@tonic-gate 	case T_MX:		/* mail routing info */
4317c478bd9Sstevel@tonic-gate 		return ("MX");
4327c478bd9Sstevel@tonic-gate 	case T_TXT:		/* text */
4337c478bd9Sstevel@tonic-gate 		return ("TXT");
4347c478bd9Sstevel@tonic-gate 	case T_AXFR:		/* zone transfer */
4357c478bd9Sstevel@tonic-gate 		return ("AXFR");
4367c478bd9Sstevel@tonic-gate 	case T_MAILB:		/* mail box */
4377c478bd9Sstevel@tonic-gate 		return ("MAILB");
4387c478bd9Sstevel@tonic-gate 	case T_MAILA:		/* mail address */
4397c478bd9Sstevel@tonic-gate 		return ("MAILA");
4407c478bd9Sstevel@tonic-gate 	case T_ANY:		/* matches any type */
4417c478bd9Sstevel@tonic-gate 		return ("ANY");
4427c478bd9Sstevel@tonic-gate 	case T_UINFO:
4437c478bd9Sstevel@tonic-gate 		return ("UINFO");
4447c478bd9Sstevel@tonic-gate 	case T_UID:
4457c478bd9Sstevel@tonic-gate 		return ("UID");
4467c478bd9Sstevel@tonic-gate 	case T_GID:
4477c478bd9Sstevel@tonic-gate 		return ("GID");
4487c478bd9Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC
4497c478bd9Sstevel@tonic-gate 	case T_UNSPEC:
4507c478bd9Sstevel@tonic-gate 		return ("UNSPEC");
4517c478bd9Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */
4527c478bd9Sstevel@tonic-gate 	default:
4537c478bd9Sstevel@tonic-gate 		(void) sprintf(nbuf, "%d", type);
4547c478bd9Sstevel@tonic-gate 		return (nbuf);
4557c478bd9Sstevel@tonic-gate 	}
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate  * Return a mnemonic for class
4607c478bd9Sstevel@tonic-gate  */
4617c478bd9Sstevel@tonic-gate char *
p_class(class)4627c478bd9Sstevel@tonic-gate p_class(class)
4637c478bd9Sstevel@tonic-gate 	int class;
4647c478bd9Sstevel@tonic-gate {
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	switch (class) {
4677c478bd9Sstevel@tonic-gate 	case C_IN:		/* internet class */
4687c478bd9Sstevel@tonic-gate 		return ("IN");
4697c478bd9Sstevel@tonic-gate 	case C_HS:		/* hesiod class */
4707c478bd9Sstevel@tonic-gate 		return ("HS");
4717c478bd9Sstevel@tonic-gate 	case C_ANY:		/* matches any class */
4727c478bd9Sstevel@tonic-gate 		return ("ANY");
4737c478bd9Sstevel@tonic-gate 	default:
4747c478bd9Sstevel@tonic-gate 		(void) sprintf(nbuf, "%d", class);
4757c478bd9Sstevel@tonic-gate 		return (nbuf);
4767c478bd9Sstevel@tonic-gate 	}
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate /*
4807c478bd9Sstevel@tonic-gate  * Return a mnemonic for a time to live
4817c478bd9Sstevel@tonic-gate  */
4827c478bd9Sstevel@tonic-gate char *
p_time(value)4837c478bd9Sstevel@tonic-gate p_time(value)
4847c478bd9Sstevel@tonic-gate 	u_long value;
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate 	int secs, mins, hours;
4877c478bd9Sstevel@tonic-gate 	register char *p;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	if (value == 0) {
4907c478bd9Sstevel@tonic-gate 		strcpy(nbuf, "0 secs");
4917c478bd9Sstevel@tonic-gate 		return (nbuf);
4927c478bd9Sstevel@tonic-gate 	}
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	secs = value % 60;
4957c478bd9Sstevel@tonic-gate 	value /= 60;
4967c478bd9Sstevel@tonic-gate 	mins = value % 60;
4977c478bd9Sstevel@tonic-gate 	value /= 60;
4987c478bd9Sstevel@tonic-gate 	hours = value % 24;
4997c478bd9Sstevel@tonic-gate 	value /= 24;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate #define	PLURALIZE(x)	x, (x == 1) ? "" : "s"
5027c478bd9Sstevel@tonic-gate 	p = nbuf;
5037c478bd9Sstevel@tonic-gate 	if (value) {
5047c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d day%s", PLURALIZE(value));
5057c478bd9Sstevel@tonic-gate 		while (*++p);
5067c478bd9Sstevel@tonic-gate 	}
5077c478bd9Sstevel@tonic-gate 	if (hours) {
5087c478bd9Sstevel@tonic-gate 		if (value)
5097c478bd9Sstevel@tonic-gate 			*p++ = ' ';
5107c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d hour%s", PLURALIZE(hours));
5117c478bd9Sstevel@tonic-gate 		while (*++p);
5127c478bd9Sstevel@tonic-gate 	}
5137c478bd9Sstevel@tonic-gate 	if (mins) {
5147c478bd9Sstevel@tonic-gate 		if (value || hours)
5157c478bd9Sstevel@tonic-gate 			*p++ = ' ';
5167c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d min%s", PLURALIZE(mins));
5177c478bd9Sstevel@tonic-gate 		while (*++p);
5187c478bd9Sstevel@tonic-gate 	}
5197c478bd9Sstevel@tonic-gate 	if (secs || ! (value || hours || mins)) {
5207c478bd9Sstevel@tonic-gate 		if (value || hours || mins)
5217c478bd9Sstevel@tonic-gate 			*p++ = ' ';
5227c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d sec%s", PLURALIZE(secs));
5237c478bd9Sstevel@tonic-gate 	}
5247c478bd9Sstevel@tonic-gate 	return (nbuf);
5257c478bd9Sstevel@tonic-gate }
526