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