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