xref: /onnv-gate/usr/src/lib/libresolv/res_debug.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate  * The Regents of the University of California
330Sstevel@tonic-gate  * All Rights Reserved
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate  * contributors.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <netinet/in.h>
440Sstevel@tonic-gate #include <stdio.h>
450Sstevel@tonic-gate #include <arpa/nameser.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time();
480Sstevel@tonic-gate extern char *inet_ntoa();
49237Sanay void fp_query(char *msg, FILE *file);
500Sstevel@tonic-gate 
510Sstevel@tonic-gate char *_res_opcodes[] = {
520Sstevel@tonic-gate 	"QUERY",
530Sstevel@tonic-gate 	"IQUERY",
540Sstevel@tonic-gate 	"CQUERYM",
550Sstevel@tonic-gate 	"CQUERYU",
560Sstevel@tonic-gate 	"4",
570Sstevel@tonic-gate 	"5",
580Sstevel@tonic-gate 	"6",
590Sstevel@tonic-gate 	"7",
600Sstevel@tonic-gate 	"8",
610Sstevel@tonic-gate 	"UPDATEA",
620Sstevel@tonic-gate 	"UPDATED",
630Sstevel@tonic-gate 	"UPDATEDA",
640Sstevel@tonic-gate 	"UPDATEM",
650Sstevel@tonic-gate 	"UPDATEMA",
660Sstevel@tonic-gate 	"ZONEINIT",
670Sstevel@tonic-gate 	"ZONEREF",
680Sstevel@tonic-gate };
690Sstevel@tonic-gate 
700Sstevel@tonic-gate char *_res_resultcodes[] = {
710Sstevel@tonic-gate 	"NOERROR",
720Sstevel@tonic-gate 	"FORMERR",
730Sstevel@tonic-gate 	"SERVFAIL",
740Sstevel@tonic-gate 	"NXDOMAIN",
750Sstevel@tonic-gate 	"NOTIMP",
760Sstevel@tonic-gate 	"REFUSED",
770Sstevel@tonic-gate 	"6",
780Sstevel@tonic-gate 	"7",
790Sstevel@tonic-gate 	"8",
800Sstevel@tonic-gate 	"9",
810Sstevel@tonic-gate 	"10",
820Sstevel@tonic-gate 	"11",
830Sstevel@tonic-gate 	"12",
840Sstevel@tonic-gate 	"13",
850Sstevel@tonic-gate 	"14",
860Sstevel@tonic-gate 	"NOCHANGE",
870Sstevel@tonic-gate };
880Sstevel@tonic-gate 
89237Sanay void
p_query(msg)900Sstevel@tonic-gate p_query(msg)
910Sstevel@tonic-gate 	char *msg;
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	fp_query(msg, stdout);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate  * Print the contents of a query.
980Sstevel@tonic-gate  * This is intended to be primarily a debugging routine.
990Sstevel@tonic-gate  */
100237Sanay void
fp_query(msg,file)1010Sstevel@tonic-gate fp_query(msg, file)
1020Sstevel@tonic-gate 	char *msg;
1030Sstevel@tonic-gate 	FILE *file;
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	register char *cp;
1060Sstevel@tonic-gate 	register HEADER *hp;
1070Sstevel@tonic-gate 	register int n;
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	/*
1100Sstevel@tonic-gate 	 * Print header fields.
1110Sstevel@tonic-gate 	 */
1120Sstevel@tonic-gate 	hp = (HEADER *)msg;
1130Sstevel@tonic-gate 	cp = msg + sizeof (HEADER);
1140Sstevel@tonic-gate 	fprintf(file, "HEADER:\n");
1150Sstevel@tonic-gate 	fprintf(file, "\topcode = %s", _res_opcodes[hp->opcode]);
1160Sstevel@tonic-gate 	fprintf(file, ", id = %d", ntohs(hp->id));
1170Sstevel@tonic-gate 	fprintf(file, ", rcode = %s\n", _res_resultcodes[hp->rcode]);
1180Sstevel@tonic-gate 	fprintf(file, "\theader flags: ");
1190Sstevel@tonic-gate 	if (hp->qr)
1200Sstevel@tonic-gate 		fprintf(file, " qr");
1210Sstevel@tonic-gate 	if (hp->aa)
1220Sstevel@tonic-gate 		fprintf(file, " aa");
1230Sstevel@tonic-gate 	if (hp->tc)
1240Sstevel@tonic-gate 		fprintf(file, " tc");
1250Sstevel@tonic-gate 	if (hp->rd)
1260Sstevel@tonic-gate 		fprintf(file, " rd");
1270Sstevel@tonic-gate 	if (hp->ra)
1280Sstevel@tonic-gate 		fprintf(file, " ra");
1290Sstevel@tonic-gate 	if (hp->pr)
1300Sstevel@tonic-gate 		fprintf(file, " pr");
1310Sstevel@tonic-gate 	fprintf(file, "\n\tqdcount = %d", ntohs(hp->qdcount));
1320Sstevel@tonic-gate 	fprintf(file, ", ancount = %d", ntohs(hp->ancount));
1330Sstevel@tonic-gate 	fprintf(file, ", nscount = %d", ntohs(hp->nscount));
1340Sstevel@tonic-gate 	fprintf(file, ", arcount = %d\n\n", ntohs(hp->arcount));
1350Sstevel@tonic-gate 	/*
1360Sstevel@tonic-gate 	 * Print question records.
1370Sstevel@tonic-gate 	 */
1380Sstevel@tonic-gate 	if (n = ntohs(hp->qdcount)) {
1390Sstevel@tonic-gate 		fprintf(file, "QUESTIONS:\n");
1400Sstevel@tonic-gate 		while (--n >= 0) {
1410Sstevel@tonic-gate 			fprintf(file, "\t");
1420Sstevel@tonic-gate 			cp = p_cdname(cp, msg, file);
1430Sstevel@tonic-gate 			if (cp == NULL)
1440Sstevel@tonic-gate 				return;
1450Sstevel@tonic-gate 			fprintf(file, ", type = %s", p_type(_getshort(cp)));
1460Sstevel@tonic-gate 			cp += sizeof (u_short);
1470Sstevel@tonic-gate 			fprintf(file, ", class = %s\n\n",
1480Sstevel@tonic-gate 						p_class(_getshort(cp)));
1490Sstevel@tonic-gate 			cp += sizeof (u_short);
1500Sstevel@tonic-gate 		}
1510Sstevel@tonic-gate 	}
1520Sstevel@tonic-gate 	/*
1530Sstevel@tonic-gate 	 * Print authoritative answer records
1540Sstevel@tonic-gate 	 */
1550Sstevel@tonic-gate 	if (n = ntohs(hp->ancount)) {
1560Sstevel@tonic-gate 		fprintf(file, "ANSWERS:\n");
1570Sstevel@tonic-gate 		while (--n >= 0) {
1580Sstevel@tonic-gate 			fprintf(file, "\t");
1590Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1600Sstevel@tonic-gate 			if (cp == NULL)
1610Sstevel@tonic-gate 				return;
1620Sstevel@tonic-gate 		}
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 	/*
1650Sstevel@tonic-gate 	 * print name server records
1660Sstevel@tonic-gate 	 */
1670Sstevel@tonic-gate 	if (n = ntohs(hp->nscount)) {
1680Sstevel@tonic-gate 		fprintf(file, "NAME SERVERS:\n");
1690Sstevel@tonic-gate 		while (--n >= 0) {
1700Sstevel@tonic-gate 			fprintf(file, "\t");
1710Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1720Sstevel@tonic-gate 			if (cp == NULL)
1730Sstevel@tonic-gate 				return;
1740Sstevel@tonic-gate 		}
1750Sstevel@tonic-gate 	}
1760Sstevel@tonic-gate 	/*
1770Sstevel@tonic-gate 	 * print additional records
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate 	if (n = ntohs(hp->arcount)) {
1800Sstevel@tonic-gate 		fprintf(file, "ADDITIONAL RECORDS:\n");
1810Sstevel@tonic-gate 		while (--n >= 0) {
1820Sstevel@tonic-gate 			fprintf(file, "\t");
1830Sstevel@tonic-gate 			cp = p_rr(cp, msg, file);
1840Sstevel@tonic-gate 			if (cp == NULL)
1850Sstevel@tonic-gate 				return;
1860Sstevel@tonic-gate 		}
1870Sstevel@tonic-gate 	}
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate char *
p_cdname(cp,msg,file)1910Sstevel@tonic-gate p_cdname(cp, msg, file)
1920Sstevel@tonic-gate 	char *cp, *msg;
1930Sstevel@tonic-gate 	FILE *file;
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate 	char name[MAXDNAME];
1960Sstevel@tonic-gate 	int n;
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate 	if ((n = dn_expand(msg, msg + 512, cp, name, sizeof (name))) < 0)
1990Sstevel@tonic-gate 		return (NULL);
2000Sstevel@tonic-gate 	if (name[0] == '\0') {
2010Sstevel@tonic-gate 		name[0] = '.';
2020Sstevel@tonic-gate 		name[1] = '\0';
2030Sstevel@tonic-gate 	}
2040Sstevel@tonic-gate 	fputs(name, file);
2050Sstevel@tonic-gate 	return (cp + n);
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /*
2090Sstevel@tonic-gate  * Print resource record fields in human readable form.
2100Sstevel@tonic-gate  */
2110Sstevel@tonic-gate char *
p_rr(cp,msg,file)2120Sstevel@tonic-gate p_rr(cp, msg, file)
2130Sstevel@tonic-gate 	char *cp, *msg;
2140Sstevel@tonic-gate 	FILE *file;
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate 	int type, class, dlen, n, c;
2170Sstevel@tonic-gate 	struct in_addr inaddr;
2180Sstevel@tonic-gate 	char *cp1, *cp2;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	if ((cp = p_cdname(cp, msg, file)) == NULL)
2210Sstevel@tonic-gate 		return (NULL);			/* compression error */
2220Sstevel@tonic-gate 	fprintf(file, "\n\ttype = %s", p_type(type = _getshort(cp)));
2230Sstevel@tonic-gate 	cp += sizeof (u_short);
2240Sstevel@tonic-gate 	fprintf(file, ", class = %s", p_class(class = _getshort(cp)));
2250Sstevel@tonic-gate 	cp += sizeof (u_short);
2260Sstevel@tonic-gate 	fprintf(file, ", ttl = %s", p_time(_getlong(cp)));
2270Sstevel@tonic-gate 	cp += sizeof (u_long);
2280Sstevel@tonic-gate 	fprintf(file, ", dlen = %d\n", dlen = _getshort(cp));
2290Sstevel@tonic-gate 	cp += sizeof (u_short);
2300Sstevel@tonic-gate 	cp1 = cp;
2310Sstevel@tonic-gate 	/*
2320Sstevel@tonic-gate 	 * Print type specific data, if appropriate
2330Sstevel@tonic-gate 	 */
2340Sstevel@tonic-gate 	switch (type) {
2350Sstevel@tonic-gate 	case T_A:
2360Sstevel@tonic-gate 		switch (class) {
2370Sstevel@tonic-gate 		case C_IN:
2380Sstevel@tonic-gate 		case C_HS:
2390Sstevel@tonic-gate #ifdef SYSV
2400Sstevel@tonic-gate 			memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
2410Sstevel@tonic-gate #else
2420Sstevel@tonic-gate 			bcopy(cp, (char *)&inaddr, sizeof (inaddr));
2430Sstevel@tonic-gate #endif
2440Sstevel@tonic-gate 			if (dlen == 4) {
2450Sstevel@tonic-gate 				fprintf(file, "\tinternet address = %s\n",
2460Sstevel@tonic-gate 					inet_ntoa(inaddr));
2470Sstevel@tonic-gate 				cp += dlen;
2480Sstevel@tonic-gate 			} else if (dlen == 7) {
2490Sstevel@tonic-gate 				fprintf(file, "\tinternet address = %s",
2500Sstevel@tonic-gate 					inet_ntoa(inaddr));
2510Sstevel@tonic-gate 				fprintf(file, ", protocol = %d", cp[4]);
2520Sstevel@tonic-gate 				fprintf(file, ", port = %d\n",
2530Sstevel@tonic-gate 					(cp[5] << 8) + cp[6]);
2540Sstevel@tonic-gate 				cp += dlen;
2550Sstevel@tonic-gate 			}
2560Sstevel@tonic-gate 			break;
2570Sstevel@tonic-gate 		default:
2580Sstevel@tonic-gate 			cp += dlen;
2590Sstevel@tonic-gate 		}
2600Sstevel@tonic-gate 		break;
2610Sstevel@tonic-gate 	case T_CNAME:
2620Sstevel@tonic-gate 	case T_MB:
2630Sstevel@tonic-gate 	case T_MG:
2640Sstevel@tonic-gate 	case T_MR:
2650Sstevel@tonic-gate 	case T_NS:
2660Sstevel@tonic-gate 	case T_PTR:
2670Sstevel@tonic-gate 		fprintf(file, "\tdomain name = ");
2680Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2690Sstevel@tonic-gate 		fprintf(file, "\n");
2700Sstevel@tonic-gate 		break;
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	case T_HINFO:
2730Sstevel@tonic-gate 		if (n = *cp++) {
2740Sstevel@tonic-gate 			fprintf(file, "\tCPU=%.*s\n", n, cp);
2750Sstevel@tonic-gate 			cp += n;
2760Sstevel@tonic-gate 		}
2770Sstevel@tonic-gate 		if (n = *cp++) {
2780Sstevel@tonic-gate 			fprintf(file, "\tOS=%.*s\n", n, cp);
2790Sstevel@tonic-gate 			cp += n;
2800Sstevel@tonic-gate 		}
2810Sstevel@tonic-gate 		break;
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	case T_SOA:
2840Sstevel@tonic-gate 		fprintf(file, "\torigin = ");
2850Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2860Sstevel@tonic-gate 		fprintf(file, "\n\tmail addr = ");
2870Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
2880Sstevel@tonic-gate 		fprintf(file, "\n\tserial = %ld", _getlong(cp));
2890Sstevel@tonic-gate 		cp += sizeof (u_long);
2900Sstevel@tonic-gate 		fprintf(file, "\n\trefresh = %s", p_time(_getlong(cp)));
2910Sstevel@tonic-gate 		cp += sizeof (u_long);
2920Sstevel@tonic-gate 		fprintf(file, "\n\tretry = %s", p_time(_getlong(cp)));
2930Sstevel@tonic-gate 		cp += sizeof (u_long);
2940Sstevel@tonic-gate 		fprintf(file, "\n\texpire = %s", p_time(_getlong(cp)));
2950Sstevel@tonic-gate 		cp += sizeof (u_long);
2960Sstevel@tonic-gate 		fprintf(file, "\n\tmin = %s\n", p_time(_getlong(cp)));
2970Sstevel@tonic-gate 		cp += sizeof (u_long);
2980Sstevel@tonic-gate 		break;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	case T_MX:
3010Sstevel@tonic-gate 		fprintf(file, "\tpreference = %ld,", _getshort(cp));
3020Sstevel@tonic-gate 		cp += sizeof (u_short);
3030Sstevel@tonic-gate 		fprintf(file, " name = ");
3040Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3050Sstevel@tonic-gate 		break;
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	case T_TXT:
3080Sstevel@tonic-gate 		(void) fputs("\t\"", file);
3090Sstevel@tonic-gate 		cp2 = cp1 + dlen;
3100Sstevel@tonic-gate 		while (cp < cp2) {
3110Sstevel@tonic-gate 			if (n = (unsigned char) *cp++) {
3120Sstevel@tonic-gate 				for (c = n; c > 0 && cp < cp2; c--)
3130Sstevel@tonic-gate 					if (*cp == '\n') {
3140Sstevel@tonic-gate 					    (void) putc('\\', file);
3150Sstevel@tonic-gate 					    (void) putc(*cp++, file);
3160Sstevel@tonic-gate 					} else
3170Sstevel@tonic-gate 					    (void) putc(*cp++, file);
3180Sstevel@tonic-gate 			}
3190Sstevel@tonic-gate 		}
3200Sstevel@tonic-gate 		(void) fputs("\"\n", file);
3210Sstevel@tonic-gate 		break;
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 	case T_MINFO:
3240Sstevel@tonic-gate 		fprintf(file, "\trequests = ");
3250Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3260Sstevel@tonic-gate 		fprintf(file, "\n\terrors = ");
3270Sstevel@tonic-gate 		cp = p_cdname(cp, msg, file);
3280Sstevel@tonic-gate 		break;
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	case T_UINFO:
3310Sstevel@tonic-gate 		fprintf(file, "\t%s\n", cp);
3320Sstevel@tonic-gate 		cp += dlen;
3330Sstevel@tonic-gate 		break;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	case T_UID:
3360Sstevel@tonic-gate 	case T_GID:
3370Sstevel@tonic-gate 		if (dlen == 4) {
3380Sstevel@tonic-gate 			fprintf(file, "\t%ld\n", _getlong(cp));
3390Sstevel@tonic-gate 			cp += sizeof (int);
3400Sstevel@tonic-gate 		}
3410Sstevel@tonic-gate 		break;
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	case T_WKS:
3440Sstevel@tonic-gate 		if (dlen < sizeof (u_long) + 1)
3450Sstevel@tonic-gate 			break;
3460Sstevel@tonic-gate #ifdef SYSV
3470Sstevel@tonic-gate 		memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr));
3480Sstevel@tonic-gate #else
3490Sstevel@tonic-gate 		bcopy(cp, (char *)&inaddr, sizeof (inaddr));
3500Sstevel@tonic-gate #endif
3510Sstevel@tonic-gate 		cp += sizeof (u_long);
3520Sstevel@tonic-gate 		fprintf(file, "\tinternet address = %s, protocol = %d\n\t",
3530Sstevel@tonic-gate 			inet_ntoa(inaddr), *cp++);
3540Sstevel@tonic-gate 		n = 0;
3550Sstevel@tonic-gate 		while (cp < cp1 + dlen) {
3560Sstevel@tonic-gate 			c = *cp++;
3570Sstevel@tonic-gate 			do {
3580Sstevel@tonic-gate 				if (c & 0200)
3590Sstevel@tonic-gate 					fprintf(file, " %d", n);
3600Sstevel@tonic-gate 				c <<= 1;
3610Sstevel@tonic-gate 			} while (++n & 07);
3620Sstevel@tonic-gate 		}
3630Sstevel@tonic-gate 		putc('\n', file);
3640Sstevel@tonic-gate 		break;
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC
3670Sstevel@tonic-gate 	case T_UNSPEC:
3680Sstevel@tonic-gate 		{
3690Sstevel@tonic-gate 			int NumBytes = 8;
3700Sstevel@tonic-gate 			char *DataPtr;
3710Sstevel@tonic-gate 			int i;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 			if (dlen < NumBytes) NumBytes = dlen;
3740Sstevel@tonic-gate 			fprintf(file, "\tFirst %d bytes of hex data:",
3750Sstevel@tonic-gate 				NumBytes);
3760Sstevel@tonic-gate 			for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
3770Sstevel@tonic-gate 				fprintf(file, " %x", *DataPtr);
3780Sstevel@tonic-gate 			fputs("\n", file);
3790Sstevel@tonic-gate 			cp += dlen;
3800Sstevel@tonic-gate 		}
3810Sstevel@tonic-gate 		break;
3820Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	default:
3850Sstevel@tonic-gate 		fprintf(file, "\t???\n");
3860Sstevel@tonic-gate 		cp += dlen;
3870Sstevel@tonic-gate 	}
3880Sstevel@tonic-gate 	if (cp != cp1 + dlen) {
3890Sstevel@tonic-gate 		fprintf(file, "packet size error (%#x != %#x)\n", cp, cp1+dlen);
3900Sstevel@tonic-gate 		cp = NULL;
3910Sstevel@tonic-gate 	}
3920Sstevel@tonic-gate 	fprintf(file, "\n");
3930Sstevel@tonic-gate 	return (cp);
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate static	char nbuf[40];
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * Return a string for the type
4000Sstevel@tonic-gate  */
4010Sstevel@tonic-gate char *
p_type(type)4020Sstevel@tonic-gate p_type(type)
4030Sstevel@tonic-gate 	int type;
4040Sstevel@tonic-gate {
4050Sstevel@tonic-gate 	switch (type) {
4060Sstevel@tonic-gate 	case T_A:
4070Sstevel@tonic-gate 		return ("A");
4080Sstevel@tonic-gate 	case T_NS:		/* authoritative server */
4090Sstevel@tonic-gate 		return ("NS");
4100Sstevel@tonic-gate 	case T_CNAME:		/* canonical name */
4110Sstevel@tonic-gate 		return ("CNAME");
4120Sstevel@tonic-gate 	case T_SOA:		/* start of authority zone */
4130Sstevel@tonic-gate 		return ("SOA");
4140Sstevel@tonic-gate 	case T_MB:		/* mailbox domain name */
4150Sstevel@tonic-gate 		return ("MB");
4160Sstevel@tonic-gate 	case T_MG:		/* mail group member */
4170Sstevel@tonic-gate 		return ("MG");
4180Sstevel@tonic-gate 	case T_MR:		/* mail rename name */
4190Sstevel@tonic-gate 		return ("MR");
4200Sstevel@tonic-gate 	case T_NULL:		/* null resource record */
4210Sstevel@tonic-gate 		return ("NULL");
4220Sstevel@tonic-gate 	case T_WKS:		/* well known service */
4230Sstevel@tonic-gate 		return ("WKS");
4240Sstevel@tonic-gate 	case T_PTR:		/* domain name pointer */
4250Sstevel@tonic-gate 		return ("PTR");
4260Sstevel@tonic-gate 	case T_HINFO:		/* host information */
4270Sstevel@tonic-gate 		return ("HINFO");
4280Sstevel@tonic-gate 	case T_MINFO:		/* mailbox information */
4290Sstevel@tonic-gate 		return ("MINFO");
4300Sstevel@tonic-gate 	case T_MX:		/* mail routing info */
4310Sstevel@tonic-gate 		return ("MX");
4320Sstevel@tonic-gate 	case T_TXT:		/* text */
4330Sstevel@tonic-gate 		return ("TXT");
4340Sstevel@tonic-gate 	case T_AXFR:		/* zone transfer */
4350Sstevel@tonic-gate 		return ("AXFR");
4360Sstevel@tonic-gate 	case T_MAILB:		/* mail box */
4370Sstevel@tonic-gate 		return ("MAILB");
4380Sstevel@tonic-gate 	case T_MAILA:		/* mail address */
4390Sstevel@tonic-gate 		return ("MAILA");
4400Sstevel@tonic-gate 	case T_ANY:		/* matches any type */
4410Sstevel@tonic-gate 		return ("ANY");
4420Sstevel@tonic-gate 	case T_UINFO:
4430Sstevel@tonic-gate 		return ("UINFO");
4440Sstevel@tonic-gate 	case T_UID:
4450Sstevel@tonic-gate 		return ("UID");
4460Sstevel@tonic-gate 	case T_GID:
4470Sstevel@tonic-gate 		return ("GID");
4480Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC
4490Sstevel@tonic-gate 	case T_UNSPEC:
4500Sstevel@tonic-gate 		return ("UNSPEC");
4510Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */
4520Sstevel@tonic-gate 	default:
4530Sstevel@tonic-gate 		(void) sprintf(nbuf, "%d", type);
4540Sstevel@tonic-gate 		return (nbuf);
4550Sstevel@tonic-gate 	}
4560Sstevel@tonic-gate }
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate /*
4590Sstevel@tonic-gate  * Return a mnemonic for class
4600Sstevel@tonic-gate  */
4610Sstevel@tonic-gate char *
p_class(class)4620Sstevel@tonic-gate p_class(class)
4630Sstevel@tonic-gate 	int class;
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	switch (class) {
4670Sstevel@tonic-gate 	case C_IN:		/* internet class */
4680Sstevel@tonic-gate 		return ("IN");
4690Sstevel@tonic-gate 	case C_HS:		/* hesiod class */
4700Sstevel@tonic-gate 		return ("HS");
4710Sstevel@tonic-gate 	case C_ANY:		/* matches any class */
4720Sstevel@tonic-gate 		return ("ANY");
4730Sstevel@tonic-gate 	default:
4740Sstevel@tonic-gate 		(void) sprintf(nbuf, "%d", class);
4750Sstevel@tonic-gate 		return (nbuf);
4760Sstevel@tonic-gate 	}
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate /*
4800Sstevel@tonic-gate  * Return a mnemonic for a time to live
4810Sstevel@tonic-gate  */
4820Sstevel@tonic-gate char *
p_time(value)4830Sstevel@tonic-gate p_time(value)
4840Sstevel@tonic-gate 	u_long value;
4850Sstevel@tonic-gate {
4860Sstevel@tonic-gate 	int secs, mins, hours;
4870Sstevel@tonic-gate 	register char *p;
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	if (value == 0) {
4900Sstevel@tonic-gate 		strcpy(nbuf, "0 secs");
4910Sstevel@tonic-gate 		return (nbuf);
4920Sstevel@tonic-gate 	}
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 	secs = value % 60;
4950Sstevel@tonic-gate 	value /= 60;
4960Sstevel@tonic-gate 	mins = value % 60;
4970Sstevel@tonic-gate 	value /= 60;
4980Sstevel@tonic-gate 	hours = value % 24;
4990Sstevel@tonic-gate 	value /= 24;
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate #define	PLURALIZE(x)	x, (x == 1) ? "" : "s"
5020Sstevel@tonic-gate 	p = nbuf;
5030Sstevel@tonic-gate 	if (value) {
5040Sstevel@tonic-gate 		(void) sprintf(p, "%d day%s", PLURALIZE(value));
5050Sstevel@tonic-gate 		while (*++p);
5060Sstevel@tonic-gate 	}
5070Sstevel@tonic-gate 	if (hours) {
5080Sstevel@tonic-gate 		if (value)
5090Sstevel@tonic-gate 			*p++ = ' ';
5100Sstevel@tonic-gate 		(void) sprintf(p, "%d hour%s", PLURALIZE(hours));
5110Sstevel@tonic-gate 		while (*++p);
5120Sstevel@tonic-gate 	}
5130Sstevel@tonic-gate 	if (mins) {
5140Sstevel@tonic-gate 		if (value || hours)
5150Sstevel@tonic-gate 			*p++ = ' ';
5160Sstevel@tonic-gate 		(void) sprintf(p, "%d min%s", PLURALIZE(mins));
5170Sstevel@tonic-gate 		while (*++p);
5180Sstevel@tonic-gate 	}
5190Sstevel@tonic-gate 	if (secs || ! (value || hours || mins)) {
5200Sstevel@tonic-gate 		if (value || hours || mins)
5210Sstevel@tonic-gate 			*p++ = ' ';
5220Sstevel@tonic-gate 		(void) sprintf(p, "%d sec%s", PLURALIZE(secs));
5230Sstevel@tonic-gate 	}
5240Sstevel@tonic-gate 	return (nbuf);
5250Sstevel@tonic-gate }
526