1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate /* 31*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*0Sstevel@tonic-gate * The Regents of the University of California 33*0Sstevel@tonic-gate * All Rights Reserved 34*0Sstevel@tonic-gate * 35*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*0Sstevel@tonic-gate * contributors. 38*0Sstevel@tonic-gate */ 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate #include "synonyms.h" 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #include <sys/types.h> 45*0Sstevel@tonic-gate #include <netinet/in.h> 46*0Sstevel@tonic-gate #include <stdio.h> 47*0Sstevel@tonic-gate #include <arpa/nameser.h> 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate extern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time(); 50*0Sstevel@tonic-gate extern char *inet_ntoa(); 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate char *_res_opcodes[] = { 53*0Sstevel@tonic-gate "QUERY", 54*0Sstevel@tonic-gate "IQUERY", 55*0Sstevel@tonic-gate "CQUERYM", 56*0Sstevel@tonic-gate "CQUERYU", 57*0Sstevel@tonic-gate "4", 58*0Sstevel@tonic-gate "5", 59*0Sstevel@tonic-gate "6", 60*0Sstevel@tonic-gate "7", 61*0Sstevel@tonic-gate "8", 62*0Sstevel@tonic-gate "UPDATEA", 63*0Sstevel@tonic-gate "UPDATED", 64*0Sstevel@tonic-gate "UPDATEDA", 65*0Sstevel@tonic-gate "UPDATEM", 66*0Sstevel@tonic-gate "UPDATEMA", 67*0Sstevel@tonic-gate "ZONEINIT", 68*0Sstevel@tonic-gate "ZONEREF", 69*0Sstevel@tonic-gate }; 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate char *_res_resultcodes[] = { 72*0Sstevel@tonic-gate "NOERROR", 73*0Sstevel@tonic-gate "FORMERR", 74*0Sstevel@tonic-gate "SERVFAIL", 75*0Sstevel@tonic-gate "NXDOMAIN", 76*0Sstevel@tonic-gate "NOTIMP", 77*0Sstevel@tonic-gate "REFUSED", 78*0Sstevel@tonic-gate "6", 79*0Sstevel@tonic-gate "7", 80*0Sstevel@tonic-gate "8", 81*0Sstevel@tonic-gate "9", 82*0Sstevel@tonic-gate "10", 83*0Sstevel@tonic-gate "11", 84*0Sstevel@tonic-gate "12", 85*0Sstevel@tonic-gate "13", 86*0Sstevel@tonic-gate "14", 87*0Sstevel@tonic-gate "NOCHANGE", 88*0Sstevel@tonic-gate }; 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate p_query(msg) 91*0Sstevel@tonic-gate char *msg; 92*0Sstevel@tonic-gate { 93*0Sstevel@tonic-gate fp_query(msg, stdout); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate /* 97*0Sstevel@tonic-gate * Print the contents of a query. 98*0Sstevel@tonic-gate * This is intended to be primarily a debugging routine. 99*0Sstevel@tonic-gate */ 100*0Sstevel@tonic-gate fp_query(msg, file) 101*0Sstevel@tonic-gate char *msg; 102*0Sstevel@tonic-gate FILE *file; 103*0Sstevel@tonic-gate { 104*0Sstevel@tonic-gate register char *cp; 105*0Sstevel@tonic-gate register HEADER *hp; 106*0Sstevel@tonic-gate register int n; 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate /* 109*0Sstevel@tonic-gate * Print header fields. 110*0Sstevel@tonic-gate */ 111*0Sstevel@tonic-gate hp = (HEADER *)msg; 112*0Sstevel@tonic-gate cp = msg + sizeof (HEADER); 113*0Sstevel@tonic-gate fprintf(file, "HEADER:\n"); 114*0Sstevel@tonic-gate fprintf(file, "\topcode = %s", _res_opcodes[hp->opcode]); 115*0Sstevel@tonic-gate fprintf(file, ", id = %d", ntohs(hp->id)); 116*0Sstevel@tonic-gate fprintf(file, ", rcode = %s\n", _res_resultcodes[hp->rcode]); 117*0Sstevel@tonic-gate fprintf(file, "\theader flags: "); 118*0Sstevel@tonic-gate if (hp->qr) 119*0Sstevel@tonic-gate fprintf(file, " qr"); 120*0Sstevel@tonic-gate if (hp->aa) 121*0Sstevel@tonic-gate fprintf(file, " aa"); 122*0Sstevel@tonic-gate if (hp->tc) 123*0Sstevel@tonic-gate fprintf(file, " tc"); 124*0Sstevel@tonic-gate if (hp->rd) 125*0Sstevel@tonic-gate fprintf(file, " rd"); 126*0Sstevel@tonic-gate if (hp->ra) 127*0Sstevel@tonic-gate fprintf(file, " ra"); 128*0Sstevel@tonic-gate if (hp->pr) 129*0Sstevel@tonic-gate fprintf(file, " pr"); 130*0Sstevel@tonic-gate fprintf(file, "\n\tqdcount = %d", ntohs(hp->qdcount)); 131*0Sstevel@tonic-gate fprintf(file, ", ancount = %d", ntohs(hp->ancount)); 132*0Sstevel@tonic-gate fprintf(file, ", nscount = %d", ntohs(hp->nscount)); 133*0Sstevel@tonic-gate fprintf(file, ", arcount = %d\n\n", ntohs(hp->arcount)); 134*0Sstevel@tonic-gate /* 135*0Sstevel@tonic-gate * Print question records. 136*0Sstevel@tonic-gate */ 137*0Sstevel@tonic-gate if (n = ntohs(hp->qdcount)) { 138*0Sstevel@tonic-gate fprintf(file, "QUESTIONS:\n"); 139*0Sstevel@tonic-gate while (--n >= 0) { 140*0Sstevel@tonic-gate fprintf(file, "\t"); 141*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 142*0Sstevel@tonic-gate if (cp == NULL) 143*0Sstevel@tonic-gate return; 144*0Sstevel@tonic-gate fprintf(file, ", type = %s", p_type(_getshort(cp))); 145*0Sstevel@tonic-gate cp += sizeof (u_short); 146*0Sstevel@tonic-gate fprintf(file, ", class = %s\n\n", 147*0Sstevel@tonic-gate p_class(_getshort(cp))); 148*0Sstevel@tonic-gate cp += sizeof (u_short); 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate } 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * Print authoritative answer records 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate if (n = ntohs(hp->ancount)) { 155*0Sstevel@tonic-gate fprintf(file, "ANSWERS:\n"); 156*0Sstevel@tonic-gate while (--n >= 0) { 157*0Sstevel@tonic-gate fprintf(file, "\t"); 158*0Sstevel@tonic-gate cp = p_rr(cp, msg, file); 159*0Sstevel@tonic-gate if (cp == NULL) 160*0Sstevel@tonic-gate return; 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate } 163*0Sstevel@tonic-gate /* 164*0Sstevel@tonic-gate * print name server records 165*0Sstevel@tonic-gate */ 166*0Sstevel@tonic-gate if (n = ntohs(hp->nscount)) { 167*0Sstevel@tonic-gate fprintf(file, "NAME SERVERS:\n"); 168*0Sstevel@tonic-gate while (--n >= 0) { 169*0Sstevel@tonic-gate fprintf(file, "\t"); 170*0Sstevel@tonic-gate cp = p_rr(cp, msg, file); 171*0Sstevel@tonic-gate if (cp == NULL) 172*0Sstevel@tonic-gate return; 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate /* 176*0Sstevel@tonic-gate * print additional records 177*0Sstevel@tonic-gate */ 178*0Sstevel@tonic-gate if (n = ntohs(hp->arcount)) { 179*0Sstevel@tonic-gate fprintf(file, "ADDITIONAL RECORDS:\n"); 180*0Sstevel@tonic-gate while (--n >= 0) { 181*0Sstevel@tonic-gate fprintf(file, "\t"); 182*0Sstevel@tonic-gate cp = p_rr(cp, msg, file); 183*0Sstevel@tonic-gate if (cp == NULL) 184*0Sstevel@tonic-gate return; 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate char * 190*0Sstevel@tonic-gate p_cdname(cp, msg, file) 191*0Sstevel@tonic-gate char *cp, *msg; 192*0Sstevel@tonic-gate FILE *file; 193*0Sstevel@tonic-gate { 194*0Sstevel@tonic-gate char name[MAXDNAME]; 195*0Sstevel@tonic-gate int n; 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate if ((n = dn_expand(msg, msg + 512, cp, name, sizeof (name))) < 0) 198*0Sstevel@tonic-gate return (NULL); 199*0Sstevel@tonic-gate if (name[0] == '\0') { 200*0Sstevel@tonic-gate name[0] = '.'; 201*0Sstevel@tonic-gate name[1] = '\0'; 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate fputs(name, file); 204*0Sstevel@tonic-gate return (cp + n); 205*0Sstevel@tonic-gate } 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate /* 208*0Sstevel@tonic-gate * Print resource record fields in human readable form. 209*0Sstevel@tonic-gate */ 210*0Sstevel@tonic-gate char * 211*0Sstevel@tonic-gate p_rr(cp, msg, file) 212*0Sstevel@tonic-gate char *cp, *msg; 213*0Sstevel@tonic-gate FILE *file; 214*0Sstevel@tonic-gate { 215*0Sstevel@tonic-gate int type, class, dlen, n, c; 216*0Sstevel@tonic-gate struct in_addr inaddr; 217*0Sstevel@tonic-gate char *cp1, *cp2; 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate if ((cp = p_cdname(cp, msg, file)) == NULL) 220*0Sstevel@tonic-gate return (NULL); /* compression error */ 221*0Sstevel@tonic-gate fprintf(file, "\n\ttype = %s", p_type(type = _getshort(cp))); 222*0Sstevel@tonic-gate cp += sizeof (u_short); 223*0Sstevel@tonic-gate fprintf(file, ", class = %s", p_class(class = _getshort(cp))); 224*0Sstevel@tonic-gate cp += sizeof (u_short); 225*0Sstevel@tonic-gate fprintf(file, ", ttl = %s", p_time(_getlong(cp))); 226*0Sstevel@tonic-gate cp += sizeof (u_long); 227*0Sstevel@tonic-gate fprintf(file, ", dlen = %d\n", dlen = _getshort(cp)); 228*0Sstevel@tonic-gate cp += sizeof (u_short); 229*0Sstevel@tonic-gate cp1 = cp; 230*0Sstevel@tonic-gate /* 231*0Sstevel@tonic-gate * Print type specific data, if appropriate 232*0Sstevel@tonic-gate */ 233*0Sstevel@tonic-gate switch (type) { 234*0Sstevel@tonic-gate case T_A: 235*0Sstevel@tonic-gate switch (class) { 236*0Sstevel@tonic-gate case C_IN: 237*0Sstevel@tonic-gate case C_HS: 238*0Sstevel@tonic-gate #ifdef SYSV 239*0Sstevel@tonic-gate memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr)); 240*0Sstevel@tonic-gate #else 241*0Sstevel@tonic-gate bcopy(cp, (char *)&inaddr, sizeof (inaddr)); 242*0Sstevel@tonic-gate #endif 243*0Sstevel@tonic-gate if (dlen == 4) { 244*0Sstevel@tonic-gate fprintf(file, "\tinternet address = %s\n", 245*0Sstevel@tonic-gate inet_ntoa(inaddr)); 246*0Sstevel@tonic-gate cp += dlen; 247*0Sstevel@tonic-gate } else if (dlen == 7) { 248*0Sstevel@tonic-gate fprintf(file, "\tinternet address = %s", 249*0Sstevel@tonic-gate inet_ntoa(inaddr)); 250*0Sstevel@tonic-gate fprintf(file, ", protocol = %d", cp[4]); 251*0Sstevel@tonic-gate fprintf(file, ", port = %d\n", 252*0Sstevel@tonic-gate (cp[5] << 8) + cp[6]); 253*0Sstevel@tonic-gate cp += dlen; 254*0Sstevel@tonic-gate } 255*0Sstevel@tonic-gate break; 256*0Sstevel@tonic-gate default: 257*0Sstevel@tonic-gate cp += dlen; 258*0Sstevel@tonic-gate } 259*0Sstevel@tonic-gate break; 260*0Sstevel@tonic-gate case T_CNAME: 261*0Sstevel@tonic-gate case T_MB: 262*0Sstevel@tonic-gate case T_MG: 263*0Sstevel@tonic-gate case T_MR: 264*0Sstevel@tonic-gate case T_NS: 265*0Sstevel@tonic-gate case T_PTR: 266*0Sstevel@tonic-gate fprintf(file, "\tdomain name = "); 267*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 268*0Sstevel@tonic-gate fprintf(file, "\n"); 269*0Sstevel@tonic-gate break; 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate case T_HINFO: 272*0Sstevel@tonic-gate if (n = *cp++) { 273*0Sstevel@tonic-gate fprintf(file, "\tCPU=%.*s\n", n, cp); 274*0Sstevel@tonic-gate cp += n; 275*0Sstevel@tonic-gate } 276*0Sstevel@tonic-gate if (n = *cp++) { 277*0Sstevel@tonic-gate fprintf(file, "\tOS=%.*s\n", n, cp); 278*0Sstevel@tonic-gate cp += n; 279*0Sstevel@tonic-gate } 280*0Sstevel@tonic-gate break; 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate case T_SOA: 283*0Sstevel@tonic-gate fprintf(file, "\torigin = "); 284*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 285*0Sstevel@tonic-gate fprintf(file, "\n\tmail addr = "); 286*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 287*0Sstevel@tonic-gate fprintf(file, "\n\tserial = %ld", _getlong(cp)); 288*0Sstevel@tonic-gate cp += sizeof (u_long); 289*0Sstevel@tonic-gate fprintf(file, "\n\trefresh = %s", p_time(_getlong(cp))); 290*0Sstevel@tonic-gate cp += sizeof (u_long); 291*0Sstevel@tonic-gate fprintf(file, "\n\tretry = %s", p_time(_getlong(cp))); 292*0Sstevel@tonic-gate cp += sizeof (u_long); 293*0Sstevel@tonic-gate fprintf(file, "\n\texpire = %s", p_time(_getlong(cp))); 294*0Sstevel@tonic-gate cp += sizeof (u_long); 295*0Sstevel@tonic-gate fprintf(file, "\n\tmin = %s\n", p_time(_getlong(cp))); 296*0Sstevel@tonic-gate cp += sizeof (u_long); 297*0Sstevel@tonic-gate break; 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate case T_MX: 300*0Sstevel@tonic-gate fprintf(file, "\tpreference = %ld,", _getshort(cp)); 301*0Sstevel@tonic-gate cp += sizeof (u_short); 302*0Sstevel@tonic-gate fprintf(file, " name = "); 303*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 304*0Sstevel@tonic-gate break; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate case T_TXT: 307*0Sstevel@tonic-gate (void) fputs("\t\"", file); 308*0Sstevel@tonic-gate cp2 = cp1 + dlen; 309*0Sstevel@tonic-gate while (cp < cp2) { 310*0Sstevel@tonic-gate if (n = (unsigned char) *cp++) { 311*0Sstevel@tonic-gate for (c = n; c > 0 && cp < cp2; c--) 312*0Sstevel@tonic-gate if (*cp == '\n') { 313*0Sstevel@tonic-gate (void) putc('\\', file); 314*0Sstevel@tonic-gate (void) putc(*cp++, file); 315*0Sstevel@tonic-gate } else 316*0Sstevel@tonic-gate (void) putc(*cp++, file); 317*0Sstevel@tonic-gate } 318*0Sstevel@tonic-gate } 319*0Sstevel@tonic-gate (void) fputs("\"\n", file); 320*0Sstevel@tonic-gate break; 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gate case T_MINFO: 323*0Sstevel@tonic-gate fprintf(file, "\trequests = "); 324*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 325*0Sstevel@tonic-gate fprintf(file, "\n\terrors = "); 326*0Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 327*0Sstevel@tonic-gate break; 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate case T_UINFO: 330*0Sstevel@tonic-gate fprintf(file, "\t%s\n", cp); 331*0Sstevel@tonic-gate cp += dlen; 332*0Sstevel@tonic-gate break; 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate case T_UID: 335*0Sstevel@tonic-gate case T_GID: 336*0Sstevel@tonic-gate if (dlen == 4) { 337*0Sstevel@tonic-gate fprintf(file, "\t%ld\n", _getlong(cp)); 338*0Sstevel@tonic-gate cp += sizeof (int); 339*0Sstevel@tonic-gate } 340*0Sstevel@tonic-gate break; 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate case T_WKS: 343*0Sstevel@tonic-gate if (dlen < sizeof (u_long) + 1) 344*0Sstevel@tonic-gate break; 345*0Sstevel@tonic-gate #ifdef SYSV 346*0Sstevel@tonic-gate memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr)); 347*0Sstevel@tonic-gate #else 348*0Sstevel@tonic-gate bcopy(cp, (char *)&inaddr, sizeof (inaddr)); 349*0Sstevel@tonic-gate #endif 350*0Sstevel@tonic-gate cp += sizeof (u_long); 351*0Sstevel@tonic-gate fprintf(file, "\tinternet address = %s, protocol = %d\n\t", 352*0Sstevel@tonic-gate inet_ntoa(inaddr), *cp++); 353*0Sstevel@tonic-gate n = 0; 354*0Sstevel@tonic-gate while (cp < cp1 + dlen) { 355*0Sstevel@tonic-gate c = *cp++; 356*0Sstevel@tonic-gate do { 357*0Sstevel@tonic-gate if (c & 0200) 358*0Sstevel@tonic-gate fprintf(file, " %d", n); 359*0Sstevel@tonic-gate c <<= 1; 360*0Sstevel@tonic-gate } while (++n & 07); 361*0Sstevel@tonic-gate } 362*0Sstevel@tonic-gate putc('\n', file); 363*0Sstevel@tonic-gate break; 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC 366*0Sstevel@tonic-gate case T_UNSPEC: 367*0Sstevel@tonic-gate { 368*0Sstevel@tonic-gate int NumBytes = 8; 369*0Sstevel@tonic-gate char *DataPtr; 370*0Sstevel@tonic-gate int i; 371*0Sstevel@tonic-gate 372*0Sstevel@tonic-gate if (dlen < NumBytes) NumBytes = dlen; 373*0Sstevel@tonic-gate fprintf(file, "\tFirst %d bytes of hex data:", 374*0Sstevel@tonic-gate NumBytes); 375*0Sstevel@tonic-gate for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++) 376*0Sstevel@tonic-gate fprintf(file, " %x", *DataPtr); 377*0Sstevel@tonic-gate fputs("\n", file); 378*0Sstevel@tonic-gate cp += dlen; 379*0Sstevel@tonic-gate } 380*0Sstevel@tonic-gate break; 381*0Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */ 382*0Sstevel@tonic-gate 383*0Sstevel@tonic-gate default: 384*0Sstevel@tonic-gate fprintf(file, "\t???\n"); 385*0Sstevel@tonic-gate cp += dlen; 386*0Sstevel@tonic-gate } 387*0Sstevel@tonic-gate if (cp != cp1 + dlen) { 388*0Sstevel@tonic-gate fprintf(file, "packet size error (%#x != %#x)\n", cp, cp1+dlen); 389*0Sstevel@tonic-gate cp = NULL; 390*0Sstevel@tonic-gate } 391*0Sstevel@tonic-gate fprintf(file, "\n"); 392*0Sstevel@tonic-gate return (cp); 393*0Sstevel@tonic-gate } 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate static char nbuf[40]; 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate /* 398*0Sstevel@tonic-gate * Return a string for the type 399*0Sstevel@tonic-gate */ 400*0Sstevel@tonic-gate char * 401*0Sstevel@tonic-gate p_type(type) 402*0Sstevel@tonic-gate int type; 403*0Sstevel@tonic-gate { 404*0Sstevel@tonic-gate switch (type) { 405*0Sstevel@tonic-gate case T_A: 406*0Sstevel@tonic-gate return ("A"); 407*0Sstevel@tonic-gate case T_NS: /* authoritative server */ 408*0Sstevel@tonic-gate return ("NS"); 409*0Sstevel@tonic-gate case T_CNAME: /* canonical name */ 410*0Sstevel@tonic-gate return ("CNAME"); 411*0Sstevel@tonic-gate case T_SOA: /* start of authority zone */ 412*0Sstevel@tonic-gate return ("SOA"); 413*0Sstevel@tonic-gate case T_MB: /* mailbox domain name */ 414*0Sstevel@tonic-gate return ("MB"); 415*0Sstevel@tonic-gate case T_MG: /* mail group member */ 416*0Sstevel@tonic-gate return ("MG"); 417*0Sstevel@tonic-gate case T_MR: /* mail rename name */ 418*0Sstevel@tonic-gate return ("MR"); 419*0Sstevel@tonic-gate case T_NULL: /* null resource record */ 420*0Sstevel@tonic-gate return ("NULL"); 421*0Sstevel@tonic-gate case T_WKS: /* well known service */ 422*0Sstevel@tonic-gate return ("WKS"); 423*0Sstevel@tonic-gate case T_PTR: /* domain name pointer */ 424*0Sstevel@tonic-gate return ("PTR"); 425*0Sstevel@tonic-gate case T_HINFO: /* host information */ 426*0Sstevel@tonic-gate return ("HINFO"); 427*0Sstevel@tonic-gate case T_MINFO: /* mailbox information */ 428*0Sstevel@tonic-gate return ("MINFO"); 429*0Sstevel@tonic-gate case T_MX: /* mail routing info */ 430*0Sstevel@tonic-gate return ("MX"); 431*0Sstevel@tonic-gate case T_TXT: /* text */ 432*0Sstevel@tonic-gate return ("TXT"); 433*0Sstevel@tonic-gate case T_AXFR: /* zone transfer */ 434*0Sstevel@tonic-gate return ("AXFR"); 435*0Sstevel@tonic-gate case T_MAILB: /* mail box */ 436*0Sstevel@tonic-gate return ("MAILB"); 437*0Sstevel@tonic-gate case T_MAILA: /* mail address */ 438*0Sstevel@tonic-gate return ("MAILA"); 439*0Sstevel@tonic-gate case T_ANY: /* matches any type */ 440*0Sstevel@tonic-gate return ("ANY"); 441*0Sstevel@tonic-gate case T_UINFO: 442*0Sstevel@tonic-gate return ("UINFO"); 443*0Sstevel@tonic-gate case T_UID: 444*0Sstevel@tonic-gate return ("UID"); 445*0Sstevel@tonic-gate case T_GID: 446*0Sstevel@tonic-gate return ("GID"); 447*0Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC 448*0Sstevel@tonic-gate case T_UNSPEC: 449*0Sstevel@tonic-gate return ("UNSPEC"); 450*0Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */ 451*0Sstevel@tonic-gate default: 452*0Sstevel@tonic-gate (void) sprintf(nbuf, "%d", type); 453*0Sstevel@tonic-gate return (nbuf); 454*0Sstevel@tonic-gate } 455*0Sstevel@tonic-gate } 456*0Sstevel@tonic-gate 457*0Sstevel@tonic-gate /* 458*0Sstevel@tonic-gate * Return a mnemonic for class 459*0Sstevel@tonic-gate */ 460*0Sstevel@tonic-gate char * 461*0Sstevel@tonic-gate p_class(class) 462*0Sstevel@tonic-gate int class; 463*0Sstevel@tonic-gate { 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate switch (class) { 466*0Sstevel@tonic-gate case C_IN: /* internet class */ 467*0Sstevel@tonic-gate return ("IN"); 468*0Sstevel@tonic-gate case C_HS: /* hesiod class */ 469*0Sstevel@tonic-gate return ("HS"); 470*0Sstevel@tonic-gate case C_ANY: /* matches any class */ 471*0Sstevel@tonic-gate return ("ANY"); 472*0Sstevel@tonic-gate default: 473*0Sstevel@tonic-gate (void) sprintf(nbuf, "%d", class); 474*0Sstevel@tonic-gate return (nbuf); 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate } 477*0Sstevel@tonic-gate 478*0Sstevel@tonic-gate /* 479*0Sstevel@tonic-gate * Return a mnemonic for a time to live 480*0Sstevel@tonic-gate */ 481*0Sstevel@tonic-gate char * 482*0Sstevel@tonic-gate p_time(value) 483*0Sstevel@tonic-gate u_long value; 484*0Sstevel@tonic-gate { 485*0Sstevel@tonic-gate int secs, mins, hours; 486*0Sstevel@tonic-gate register char *p; 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gate if (value == 0) { 489*0Sstevel@tonic-gate strcpy(nbuf, "0 secs"); 490*0Sstevel@tonic-gate return (nbuf); 491*0Sstevel@tonic-gate } 492*0Sstevel@tonic-gate 493*0Sstevel@tonic-gate secs = value % 60; 494*0Sstevel@tonic-gate value /= 60; 495*0Sstevel@tonic-gate mins = value % 60; 496*0Sstevel@tonic-gate value /= 60; 497*0Sstevel@tonic-gate hours = value % 24; 498*0Sstevel@tonic-gate value /= 24; 499*0Sstevel@tonic-gate 500*0Sstevel@tonic-gate #define PLURALIZE(x) x, (x == 1) ? "" : "s" 501*0Sstevel@tonic-gate p = nbuf; 502*0Sstevel@tonic-gate if (value) { 503*0Sstevel@tonic-gate (void) sprintf(p, "%d day%s", PLURALIZE(value)); 504*0Sstevel@tonic-gate while (*++p); 505*0Sstevel@tonic-gate } 506*0Sstevel@tonic-gate if (hours) { 507*0Sstevel@tonic-gate if (value) 508*0Sstevel@tonic-gate *p++ = ' '; 509*0Sstevel@tonic-gate (void) sprintf(p, "%d hour%s", PLURALIZE(hours)); 510*0Sstevel@tonic-gate while (*++p); 511*0Sstevel@tonic-gate } 512*0Sstevel@tonic-gate if (mins) { 513*0Sstevel@tonic-gate if (value || hours) 514*0Sstevel@tonic-gate *p++ = ' '; 515*0Sstevel@tonic-gate (void) sprintf(p, "%d min%s", PLURALIZE(mins)); 516*0Sstevel@tonic-gate while (*++p); 517*0Sstevel@tonic-gate } 518*0Sstevel@tonic-gate if (secs || ! (value || hours || mins)) { 519*0Sstevel@tonic-gate if (value || hours || mins) 520*0Sstevel@tonic-gate *p++ = ' '; 521*0Sstevel@tonic-gate (void) sprintf(p, "%d sec%s", PLURALIZE(secs)); 522*0Sstevel@tonic-gate } 523*0Sstevel@tonic-gate return (nbuf); 524*0Sstevel@tonic-gate } 525