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 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21e8031f0aSraf 227c478bd9Sstevel@tonic-gate /* 23*bd0e95e6SGary Mills * Copyright 2015 Gary Mills 247257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 337c478bd9Sstevel@tonic-gate * The Regents of the University of California 347c478bd9Sstevel@tonic-gate * All Rights Reserved 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 377c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 387c478bd9Sstevel@tonic-gate * contributors. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <sys/types.h> 42*bd0e95e6SGary Mills #include <sys/socket.h> 437c478bd9Sstevel@tonic-gate #include <netinet/in.h> 44*bd0e95e6SGary Mills #include <arpa/inet.h> 457c478bd9Sstevel@tonic-gate #include <stdio.h> 46*bd0e95e6SGary Mills #include <string.h> 477c478bd9Sstevel@tonic-gate #include <arpa/nameser.h> 48*bd0e95e6SGary Mills #include <resolv.h> 49*bd0e95e6SGary Mills #include "crossl.h" 507c478bd9Sstevel@tonic-gate 516a1c6faaSanay 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 916a1c6faaSanay 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 */ 1026a1c6faaSanay 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 200*bd0e95e6SGary Mills if ((n = dn_expand((u_char *)msg, (u_char *)(msg + 512), (u_char *)cp, 201*bd0e95e6SGary Mills (u_char *)name, sizeof (name))) < 0) 2027c478bd9Sstevel@tonic-gate return (NULL); 2037c478bd9Sstevel@tonic-gate if (name[0] == '\0') { 2047c478bd9Sstevel@tonic-gate name[0] = '.'; 2057c478bd9Sstevel@tonic-gate name[1] = '\0'; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate fputs(name, file); 2087c478bd9Sstevel@tonic-gate return (cp + n); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * Print resource record fields in human readable form. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate char * 2157c478bd9Sstevel@tonic-gate p_rr(cp, msg, file) 2167c478bd9Sstevel@tonic-gate char *cp, *msg; 2177c478bd9Sstevel@tonic-gate FILE *file; 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate int type, class, dlen, n, c; 2207c478bd9Sstevel@tonic-gate struct in_addr inaddr; 2217c478bd9Sstevel@tonic-gate char *cp1, *cp2; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate if ((cp = p_cdname(cp, msg, file)) == NULL) 2247c478bd9Sstevel@tonic-gate return (NULL); /* compression error */ 2257c478bd9Sstevel@tonic-gate fprintf(file, "\n\ttype = %s", p_type(type = _getshort(cp))); 2267c478bd9Sstevel@tonic-gate cp += sizeof (u_short); 2277c478bd9Sstevel@tonic-gate fprintf(file, ", class = %s", p_class(class = _getshort(cp))); 2287c478bd9Sstevel@tonic-gate cp += sizeof (u_short); 2297c478bd9Sstevel@tonic-gate fprintf(file, ", ttl = %s", p_time(_getlong(cp))); 2307c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 2317c478bd9Sstevel@tonic-gate fprintf(file, ", dlen = %d\n", dlen = _getshort(cp)); 2327c478bd9Sstevel@tonic-gate cp += sizeof (u_short); 2337c478bd9Sstevel@tonic-gate cp1 = cp; 2347c478bd9Sstevel@tonic-gate /* 2357c478bd9Sstevel@tonic-gate * Print type specific data, if appropriate 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate switch (type) { 2387c478bd9Sstevel@tonic-gate case T_A: 2397c478bd9Sstevel@tonic-gate switch (class) { 2407c478bd9Sstevel@tonic-gate case C_IN: 2417c478bd9Sstevel@tonic-gate case C_HS: 2427c478bd9Sstevel@tonic-gate #ifdef SYSV 2437c478bd9Sstevel@tonic-gate memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr)); 2447c478bd9Sstevel@tonic-gate #else 2457c478bd9Sstevel@tonic-gate bcopy(cp, (char *)&inaddr, sizeof (inaddr)); 2467c478bd9Sstevel@tonic-gate #endif 2477c478bd9Sstevel@tonic-gate if (dlen == 4) { 2487c478bd9Sstevel@tonic-gate fprintf(file, "\tinternet address = %s\n", 2497c478bd9Sstevel@tonic-gate inet_ntoa(inaddr)); 2507c478bd9Sstevel@tonic-gate cp += dlen; 2517c478bd9Sstevel@tonic-gate } else if (dlen == 7) { 2527c478bd9Sstevel@tonic-gate fprintf(file, "\tinternet address = %s", 2537c478bd9Sstevel@tonic-gate inet_ntoa(inaddr)); 2547c478bd9Sstevel@tonic-gate fprintf(file, ", protocol = %d", cp[4]); 2557c478bd9Sstevel@tonic-gate fprintf(file, ", port = %d\n", 2567c478bd9Sstevel@tonic-gate (cp[5] << 8) + cp[6]); 2577c478bd9Sstevel@tonic-gate cp += dlen; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate break; 2607c478bd9Sstevel@tonic-gate default: 2617c478bd9Sstevel@tonic-gate cp += dlen; 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate break; 2647c478bd9Sstevel@tonic-gate case T_CNAME: 2657c478bd9Sstevel@tonic-gate case T_MB: 2667c478bd9Sstevel@tonic-gate case T_MG: 2677c478bd9Sstevel@tonic-gate case T_MR: 2687c478bd9Sstevel@tonic-gate case T_NS: 2697c478bd9Sstevel@tonic-gate case T_PTR: 2707c478bd9Sstevel@tonic-gate fprintf(file, "\tdomain name = "); 2717c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 2727c478bd9Sstevel@tonic-gate fprintf(file, "\n"); 2737c478bd9Sstevel@tonic-gate break; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate case T_HINFO: 2767c478bd9Sstevel@tonic-gate if (n = *cp++) { 2777c478bd9Sstevel@tonic-gate fprintf(file, "\tCPU=%.*s\n", n, cp); 2787c478bd9Sstevel@tonic-gate cp += n; 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate if (n = *cp++) { 2817c478bd9Sstevel@tonic-gate fprintf(file, "\tOS=%.*s\n", n, cp); 2827c478bd9Sstevel@tonic-gate cp += n; 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate break; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate case T_SOA: 2877c478bd9Sstevel@tonic-gate fprintf(file, "\torigin = "); 2887c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 2897c478bd9Sstevel@tonic-gate fprintf(file, "\n\tmail addr = "); 2907c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 2917c478bd9Sstevel@tonic-gate fprintf(file, "\n\tserial = %ld", _getlong(cp)); 2927c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 2937c478bd9Sstevel@tonic-gate fprintf(file, "\n\trefresh = %s", p_time(_getlong(cp))); 2947c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 2957c478bd9Sstevel@tonic-gate fprintf(file, "\n\tretry = %s", p_time(_getlong(cp))); 2967c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 2977c478bd9Sstevel@tonic-gate fprintf(file, "\n\texpire = %s", p_time(_getlong(cp))); 2987c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 2997c478bd9Sstevel@tonic-gate fprintf(file, "\n\tmin = %s\n", p_time(_getlong(cp))); 3007c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 3017c478bd9Sstevel@tonic-gate break; 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate case T_MX: 3047c478bd9Sstevel@tonic-gate fprintf(file, "\tpreference = %ld,", _getshort(cp)); 3057c478bd9Sstevel@tonic-gate cp += sizeof (u_short); 3067c478bd9Sstevel@tonic-gate fprintf(file, " name = "); 3077c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 3087c478bd9Sstevel@tonic-gate break; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate case T_TXT: 3117c478bd9Sstevel@tonic-gate (void) fputs("\t\"", file); 3127c478bd9Sstevel@tonic-gate cp2 = cp1 + dlen; 3137c478bd9Sstevel@tonic-gate while (cp < cp2) { 3147c478bd9Sstevel@tonic-gate if (n = (unsigned char) *cp++) { 3157c478bd9Sstevel@tonic-gate for (c = n; c > 0 && cp < cp2; c--) 3167c478bd9Sstevel@tonic-gate if (*cp == '\n') { 3177c478bd9Sstevel@tonic-gate (void) putc('\\', file); 3187c478bd9Sstevel@tonic-gate (void) putc(*cp++, file); 3197c478bd9Sstevel@tonic-gate } else 3207c478bd9Sstevel@tonic-gate (void) putc(*cp++, file); 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate (void) fputs("\"\n", file); 3247c478bd9Sstevel@tonic-gate break; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate case T_MINFO: 3277c478bd9Sstevel@tonic-gate fprintf(file, "\trequests = "); 3287c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 3297c478bd9Sstevel@tonic-gate fprintf(file, "\n\terrors = "); 3307c478bd9Sstevel@tonic-gate cp = p_cdname(cp, msg, file); 3317c478bd9Sstevel@tonic-gate break; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate case T_UINFO: 3347c478bd9Sstevel@tonic-gate fprintf(file, "\t%s\n", cp); 3357c478bd9Sstevel@tonic-gate cp += dlen; 3367c478bd9Sstevel@tonic-gate break; 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate case T_UID: 3397c478bd9Sstevel@tonic-gate case T_GID: 3407c478bd9Sstevel@tonic-gate if (dlen == 4) { 3417c478bd9Sstevel@tonic-gate fprintf(file, "\t%ld\n", _getlong(cp)); 3427c478bd9Sstevel@tonic-gate cp += sizeof (int); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate break; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate case T_WKS: 3477c478bd9Sstevel@tonic-gate if (dlen < sizeof (u_long) + 1) 3487c478bd9Sstevel@tonic-gate break; 3497c478bd9Sstevel@tonic-gate #ifdef SYSV 3507c478bd9Sstevel@tonic-gate memcpy((void *)&inaddr, (void *)cp, sizeof (inaddr)); 3517c478bd9Sstevel@tonic-gate #else 3527c478bd9Sstevel@tonic-gate bcopy(cp, (char *)&inaddr, sizeof (inaddr)); 3537c478bd9Sstevel@tonic-gate #endif 3547c478bd9Sstevel@tonic-gate cp += sizeof (u_long); 3557c478bd9Sstevel@tonic-gate fprintf(file, "\tinternet address = %s, protocol = %d\n\t", 3567c478bd9Sstevel@tonic-gate inet_ntoa(inaddr), *cp++); 3577c478bd9Sstevel@tonic-gate n = 0; 3587c478bd9Sstevel@tonic-gate while (cp < cp1 + dlen) { 3597c478bd9Sstevel@tonic-gate c = *cp++; 3607c478bd9Sstevel@tonic-gate do { 3617c478bd9Sstevel@tonic-gate if (c & 0200) 3627c478bd9Sstevel@tonic-gate fprintf(file, " %d", n); 3637c478bd9Sstevel@tonic-gate c <<= 1; 3647c478bd9Sstevel@tonic-gate } while (++n & 07); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate putc('\n', file); 3677c478bd9Sstevel@tonic-gate break; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC 3707c478bd9Sstevel@tonic-gate case T_UNSPEC: 3717c478bd9Sstevel@tonic-gate { 3727c478bd9Sstevel@tonic-gate int NumBytes = 8; 3737c478bd9Sstevel@tonic-gate char *DataPtr; 3747c478bd9Sstevel@tonic-gate int i; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate if (dlen < NumBytes) NumBytes = dlen; 3777c478bd9Sstevel@tonic-gate fprintf(file, "\tFirst %d bytes of hex data:", 3787c478bd9Sstevel@tonic-gate NumBytes); 3797c478bd9Sstevel@tonic-gate for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++) 3807c478bd9Sstevel@tonic-gate fprintf(file, " %x", *DataPtr); 3817c478bd9Sstevel@tonic-gate fputs("\n", file); 3827c478bd9Sstevel@tonic-gate cp += dlen; 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */ 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate default: 3887c478bd9Sstevel@tonic-gate fprintf(file, "\t???\n"); 3897c478bd9Sstevel@tonic-gate cp += dlen; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate if (cp != cp1 + dlen) { 3927c478bd9Sstevel@tonic-gate fprintf(file, "packet size error (%#x != %#x)\n", cp, cp1+dlen); 3937c478bd9Sstevel@tonic-gate cp = NULL; 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate fprintf(file, "\n"); 3967c478bd9Sstevel@tonic-gate return (cp); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate static char nbuf[40]; 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate /* 4027c478bd9Sstevel@tonic-gate * Return a string for the type 4037c478bd9Sstevel@tonic-gate */ 4047c478bd9Sstevel@tonic-gate char * 4057c478bd9Sstevel@tonic-gate p_type(type) 4067c478bd9Sstevel@tonic-gate int type; 4077c478bd9Sstevel@tonic-gate { 4087c478bd9Sstevel@tonic-gate switch (type) { 4097c478bd9Sstevel@tonic-gate case T_A: 4107c478bd9Sstevel@tonic-gate return ("A"); 4117c478bd9Sstevel@tonic-gate case T_NS: /* authoritative server */ 4127c478bd9Sstevel@tonic-gate return ("NS"); 4137c478bd9Sstevel@tonic-gate case T_CNAME: /* canonical name */ 4147c478bd9Sstevel@tonic-gate return ("CNAME"); 4157c478bd9Sstevel@tonic-gate case T_SOA: /* start of authority zone */ 4167c478bd9Sstevel@tonic-gate return ("SOA"); 4177c478bd9Sstevel@tonic-gate case T_MB: /* mailbox domain name */ 4187c478bd9Sstevel@tonic-gate return ("MB"); 4197c478bd9Sstevel@tonic-gate case T_MG: /* mail group member */ 4207c478bd9Sstevel@tonic-gate return ("MG"); 4217c478bd9Sstevel@tonic-gate case T_MR: /* mail rename name */ 4227c478bd9Sstevel@tonic-gate return ("MR"); 4237c478bd9Sstevel@tonic-gate case T_NULL: /* null resource record */ 4247c478bd9Sstevel@tonic-gate return ("NULL"); 4257c478bd9Sstevel@tonic-gate case T_WKS: /* well known service */ 4267c478bd9Sstevel@tonic-gate return ("WKS"); 4277c478bd9Sstevel@tonic-gate case T_PTR: /* domain name pointer */ 4287c478bd9Sstevel@tonic-gate return ("PTR"); 4297c478bd9Sstevel@tonic-gate case T_HINFO: /* host information */ 4307c478bd9Sstevel@tonic-gate return ("HINFO"); 4317c478bd9Sstevel@tonic-gate case T_MINFO: /* mailbox information */ 4327c478bd9Sstevel@tonic-gate return ("MINFO"); 4337c478bd9Sstevel@tonic-gate case T_MX: /* mail routing info */ 4347c478bd9Sstevel@tonic-gate return ("MX"); 4357c478bd9Sstevel@tonic-gate case T_TXT: /* text */ 4367c478bd9Sstevel@tonic-gate return ("TXT"); 4377c478bd9Sstevel@tonic-gate case T_AXFR: /* zone transfer */ 4387c478bd9Sstevel@tonic-gate return ("AXFR"); 4397c478bd9Sstevel@tonic-gate case T_MAILB: /* mail box */ 4407c478bd9Sstevel@tonic-gate return ("MAILB"); 4417c478bd9Sstevel@tonic-gate case T_MAILA: /* mail address */ 4427c478bd9Sstevel@tonic-gate return ("MAILA"); 4437c478bd9Sstevel@tonic-gate case T_ANY: /* matches any type */ 4447c478bd9Sstevel@tonic-gate return ("ANY"); 4457c478bd9Sstevel@tonic-gate case T_UINFO: 4467c478bd9Sstevel@tonic-gate return ("UINFO"); 4477c478bd9Sstevel@tonic-gate case T_UID: 4487c478bd9Sstevel@tonic-gate return ("UID"); 4497c478bd9Sstevel@tonic-gate case T_GID: 4507c478bd9Sstevel@tonic-gate return ("GID"); 4517c478bd9Sstevel@tonic-gate #ifdef ALLOW_T_UNSPEC 4527c478bd9Sstevel@tonic-gate case T_UNSPEC: 4537c478bd9Sstevel@tonic-gate return ("UNSPEC"); 4547c478bd9Sstevel@tonic-gate #endif /* ALLOW_T_UNSPEC */ 4557c478bd9Sstevel@tonic-gate default: 4567c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "%d", type); 4577c478bd9Sstevel@tonic-gate return (nbuf); 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* 4627c478bd9Sstevel@tonic-gate * Return a mnemonic for class 4637c478bd9Sstevel@tonic-gate */ 4647c478bd9Sstevel@tonic-gate char * 4657c478bd9Sstevel@tonic-gate p_class(class) 4667c478bd9Sstevel@tonic-gate int class; 4677c478bd9Sstevel@tonic-gate { 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate switch (class) { 4707c478bd9Sstevel@tonic-gate case C_IN: /* internet class */ 4717c478bd9Sstevel@tonic-gate return ("IN"); 4727c478bd9Sstevel@tonic-gate case C_HS: /* hesiod class */ 4737c478bd9Sstevel@tonic-gate return ("HS"); 4747c478bd9Sstevel@tonic-gate case C_ANY: /* matches any class */ 4757c478bd9Sstevel@tonic-gate return ("ANY"); 4767c478bd9Sstevel@tonic-gate default: 4777c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "%d", class); 4787c478bd9Sstevel@tonic-gate return (nbuf); 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * Return a mnemonic for a time to live 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate char * 4867c478bd9Sstevel@tonic-gate p_time(value) 4877c478bd9Sstevel@tonic-gate u_long value; 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate int secs, mins, hours; 4907c478bd9Sstevel@tonic-gate register char *p; 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate if (value == 0) { 4937c478bd9Sstevel@tonic-gate strcpy(nbuf, "0 secs"); 4947c478bd9Sstevel@tonic-gate return (nbuf); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate secs = value % 60; 4987c478bd9Sstevel@tonic-gate value /= 60; 4997c478bd9Sstevel@tonic-gate mins = value % 60; 5007c478bd9Sstevel@tonic-gate value /= 60; 5017c478bd9Sstevel@tonic-gate hours = value % 24; 5027c478bd9Sstevel@tonic-gate value /= 24; 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate #define PLURALIZE(x) x, (x == 1) ? "" : "s" 5057c478bd9Sstevel@tonic-gate p = nbuf; 5067c478bd9Sstevel@tonic-gate if (value) { 5077c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d day%s", PLURALIZE(value)); 5087c478bd9Sstevel@tonic-gate while (*++p); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate if (hours) { 5117c478bd9Sstevel@tonic-gate if (value) 5127c478bd9Sstevel@tonic-gate *p++ = ' '; 5137c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d hour%s", PLURALIZE(hours)); 5147c478bd9Sstevel@tonic-gate while (*++p); 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate if (mins) { 5177c478bd9Sstevel@tonic-gate if (value || hours) 5187c478bd9Sstevel@tonic-gate *p++ = ' '; 5197c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d min%s", PLURALIZE(mins)); 5207c478bd9Sstevel@tonic-gate while (*++p); 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate if (secs || ! (value || hours || mins)) { 5237c478bd9Sstevel@tonic-gate if (value || hours || mins) 5247c478bd9Sstevel@tonic-gate *p++ = ' '; 5257c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d sec%s", PLURALIZE(secs)); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate return (nbuf); 5287c478bd9Sstevel@tonic-gate } 529