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