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 1994 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) 1983, 1984, 1985, 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 * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifndef _ARPA_NAMESER_H 36*7c478bd9Sstevel@tonic-gate #define _ARPA_NAMESER_H 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 43*7c478bd9Sstevel@tonic-gate extern "C" { 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* 47*7c478bd9Sstevel@tonic-gate * Define constants based on rfc883 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate #define PACKETSZ 512 /* maximum packet size */ 50*7c478bd9Sstevel@tonic-gate #define MAXDNAME 256 /* maximum domain name */ 51*7c478bd9Sstevel@tonic-gate #define MAXCDNAME 255 /* maximum compressed domain name */ 52*7c478bd9Sstevel@tonic-gate #define MAXLABEL 63 /* maximum length of domain label */ 53*7c478bd9Sstevel@tonic-gate /* Number of bytes of fixed size data in query structure */ 54*7c478bd9Sstevel@tonic-gate #define QFIXEDSZ 4 55*7c478bd9Sstevel@tonic-gate /* number of bytes of fixed size data in resource record */ 56*7c478bd9Sstevel@tonic-gate #define RRFIXEDSZ 10 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Internet nameserver port number 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate #define NAMESERVER_PORT 53 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate /* 64*7c478bd9Sstevel@tonic-gate * Currently defined opcodes 65*7c478bd9Sstevel@tonic-gate */ 66*7c478bd9Sstevel@tonic-gate #define QUERY 0x0 /* standard query */ 67*7c478bd9Sstevel@tonic-gate #define IQUERY 0x1 /* inverse query */ 68*7c478bd9Sstevel@tonic-gate #define STATUS 0x2 /* nameserver status query */ 69*7c478bd9Sstevel@tonic-gate /* #define xxx 0x3 */ /* 0x3 reserved */ 70*7c478bd9Sstevel@tonic-gate /* non standard */ 71*7c478bd9Sstevel@tonic-gate #define UPDATEA 0x9 /* add resource record */ 72*7c478bd9Sstevel@tonic-gate #define UPDATED 0xa /* delete a specific resource record */ 73*7c478bd9Sstevel@tonic-gate #define UPDATEDA 0xb /* delete all nemed resource record */ 74*7c478bd9Sstevel@tonic-gate #define UPDATEM 0xc /* modify a specific resource record */ 75*7c478bd9Sstevel@tonic-gate #define UPDATEMA 0xd /* modify all named resource record */ 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate #define ZONEINIT 0xe /* initial zone transfer */ 78*7c478bd9Sstevel@tonic-gate #define ZONEREF 0xf /* incremental zone referesh */ 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* 81*7c478bd9Sstevel@tonic-gate * Currently defined response codes 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate #define NOERROR 0 /* no error */ 84*7c478bd9Sstevel@tonic-gate #define FORMERR 1 /* format error */ 85*7c478bd9Sstevel@tonic-gate #define SERVFAIL 2 /* server failure */ 86*7c478bd9Sstevel@tonic-gate #define NXDOMAIN 3 /* non existent domain */ 87*7c478bd9Sstevel@tonic-gate #define NOTIMP 4 /* not implemented */ 88*7c478bd9Sstevel@tonic-gate #define REFUSED 5 /* query refused */ 89*7c478bd9Sstevel@tonic-gate /* non standard */ 90*7c478bd9Sstevel@tonic-gate #define NOCHANGE 0xf /* update failed to change db */ 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate /* 93*7c478bd9Sstevel@tonic-gate * Type values for resources and queries 94*7c478bd9Sstevel@tonic-gate */ 95*7c478bd9Sstevel@tonic-gate #define T_A 1 /* host address */ 96*7c478bd9Sstevel@tonic-gate #define T_NS 2 /* authoritative server */ 97*7c478bd9Sstevel@tonic-gate #define T_MD 3 /* mail destination */ 98*7c478bd9Sstevel@tonic-gate #define T_MF 4 /* mail forwarder */ 99*7c478bd9Sstevel@tonic-gate #define T_CNAME 5 /* connonical name */ 100*7c478bd9Sstevel@tonic-gate #define T_SOA 6 /* start of authority zone */ 101*7c478bd9Sstevel@tonic-gate #define T_MB 7 /* mailbox domain name */ 102*7c478bd9Sstevel@tonic-gate #define T_MG 8 /* mail group member */ 103*7c478bd9Sstevel@tonic-gate #define T_MR 9 /* mail rename name */ 104*7c478bd9Sstevel@tonic-gate #define T_NULL 10 /* null resource record */ 105*7c478bd9Sstevel@tonic-gate #define T_WKS 11 /* well known service */ 106*7c478bd9Sstevel@tonic-gate #define T_PTR 12 /* domain name pointer */ 107*7c478bd9Sstevel@tonic-gate #define T_HINFO 13 /* host information */ 108*7c478bd9Sstevel@tonic-gate #define T_MINFO 14 /* mailbox information */ 109*7c478bd9Sstevel@tonic-gate #define T_MX 15 /* mail routing information */ 110*7c478bd9Sstevel@tonic-gate #define T_TXT 16 /* text strings */ 111*7c478bd9Sstevel@tonic-gate /* non standard */ 112*7c478bd9Sstevel@tonic-gate #define T_UINFO 100 /* user (finger) information */ 113*7c478bd9Sstevel@tonic-gate #define T_UID 101 /* user ID */ 114*7c478bd9Sstevel@tonic-gate #define T_GID 102 /* group ID */ 115*7c478bd9Sstevel@tonic-gate #define T_UNSPEC 103 /* Unspecified format (binary data) */ 116*7c478bd9Sstevel@tonic-gate /* Query type values which do not appear in resource records */ 117*7c478bd9Sstevel@tonic-gate #define T_AXFR 252 /* transfer zone of authority */ 118*7c478bd9Sstevel@tonic-gate #define T_MAILB 253 /* transfer mailbox records */ 119*7c478bd9Sstevel@tonic-gate #define T_MAILA 254 /* transfer mail agent records */ 120*7c478bd9Sstevel@tonic-gate #define T_ANY 255 /* wildcard match */ 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * Values for class field 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate #define C_IN 1 /* the arpa internet */ 127*7c478bd9Sstevel@tonic-gate #define C_CHAOS 3 /* for chaos net at MIT */ 128*7c478bd9Sstevel@tonic-gate #define C_HS 4 /* for Hesiod name server at MIT */ 129*7c478bd9Sstevel@tonic-gate /* Query class values which do not appear in resource records */ 130*7c478bd9Sstevel@tonic-gate #define C_ANY 255 /* wildcard match */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * Status return codes for T_UNSPEC conversion routines 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate #define CONV_SUCCESS 0 136*7c478bd9Sstevel@tonic-gate #define CONV_OVERFLOW -1 137*7c478bd9Sstevel@tonic-gate #define CONV_BADFMT -2 138*7c478bd9Sstevel@tonic-gate #define CONV_BADCKSUM -3 139*7c478bd9Sstevel@tonic-gate #define CONV_BADBUFLEN -4 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* 142*7c478bd9Sstevel@tonic-gate * Structure for query header, the order of the fields is machine and 143*7c478bd9Sstevel@tonic-gate * compiler dependent, in our case, the bits within a byte are assignd 144*7c478bd9Sstevel@tonic-gate * least significant first, while the order of transmition is most 145*7c478bd9Sstevel@tonic-gate * significant first. This requires a somewhat confusing rearrangement. 146*7c478bd9Sstevel@tonic-gate */ 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate typedef struct { 149*7c478bd9Sstevel@tonic-gate u_short id; /* query identification number */ 150*7c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_HTOL) || defined(BIT_ZERO_ON_LEFT) 151*7c478bd9Sstevel@tonic-gate /* Bit zero on left: SPARC and similar architectures */ 152*7c478bd9Sstevel@tonic-gate /* fields in third byte */ 153*7c478bd9Sstevel@tonic-gate u_char qr:1; /* response flag */ 154*7c478bd9Sstevel@tonic-gate u_char opcode:4; /* purpose of message */ 155*7c478bd9Sstevel@tonic-gate u_char aa:1; /* authoritive answer */ 156*7c478bd9Sstevel@tonic-gate u_char tc:1; /* truncated message */ 157*7c478bd9Sstevel@tonic-gate u_char rd:1; /* recursion desired */ 158*7c478bd9Sstevel@tonic-gate /* fields in fourth byte */ 159*7c478bd9Sstevel@tonic-gate u_char ra:1; /* recursion available */ 160*7c478bd9Sstevel@tonic-gate u_char pr:1; /* primary server required (non standard) */ 161*7c478bd9Sstevel@tonic-gate u_char unused:2; /* unused bits */ 162*7c478bd9Sstevel@tonic-gate u_char rcode:4; /* response code */ 163*7c478bd9Sstevel@tonic-gate #else 164*7c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) || defined(BIT_ZERO_ON_RIGHT) 165*7c478bd9Sstevel@tonic-gate /* Bit zero on right: Intel x86 and similar architectures */ 166*7c478bd9Sstevel@tonic-gate /* fields in third byte */ 167*7c478bd9Sstevel@tonic-gate u_char rd:1; /* recursion desired */ 168*7c478bd9Sstevel@tonic-gate u_char tc:1; /* truncated message */ 169*7c478bd9Sstevel@tonic-gate u_char aa:1; /* authoritive answer */ 170*7c478bd9Sstevel@tonic-gate u_char opcode:4; /* purpose of message */ 171*7c478bd9Sstevel@tonic-gate u_char qr:1; /* response flag */ 172*7c478bd9Sstevel@tonic-gate /* fields in fourth byte */ 173*7c478bd9Sstevel@tonic-gate u_char rcode:4; /* response code */ 174*7c478bd9Sstevel@tonic-gate u_char unused:2; /* unused bits */ 175*7c478bd9Sstevel@tonic-gate u_char pr:1; /* primary server required (non standard) */ 176*7c478bd9Sstevel@tonic-gate u_char ra:1; /* recursion available */ 177*7c478bd9Sstevel@tonic-gate #else 178*7c478bd9Sstevel@tonic-gate /* you must determine what the correct bit order is for your compiler */ 179*7c478bd9Sstevel@tonic-gate UNDEFINED_BIT_ORDER; 180*7c478bd9Sstevel@tonic-gate #endif 181*7c478bd9Sstevel@tonic-gate #endif 182*7c478bd9Sstevel@tonic-gate /* remaining bytes */ 183*7c478bd9Sstevel@tonic-gate u_short qdcount; /* number of question entries */ 184*7c478bd9Sstevel@tonic-gate u_short ancount; /* number of answer entries */ 185*7c478bd9Sstevel@tonic-gate u_short nscount; /* number of authority entries */ 186*7c478bd9Sstevel@tonic-gate u_short arcount; /* number of resource entries */ 187*7c478bd9Sstevel@tonic-gate } HEADER; 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate /* 190*7c478bd9Sstevel@tonic-gate * Defines for handling compressed domain names 191*7c478bd9Sstevel@tonic-gate */ 192*7c478bd9Sstevel@tonic-gate #define INDIR_MASK 0xc0 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate /* 195*7c478bd9Sstevel@tonic-gate * Structure for passing resource records around. 196*7c478bd9Sstevel@tonic-gate */ 197*7c478bd9Sstevel@tonic-gate struct rrec { 198*7c478bd9Sstevel@tonic-gate short r_zone; /* zone number */ 199*7c478bd9Sstevel@tonic-gate short r_class; /* class number */ 200*7c478bd9Sstevel@tonic-gate short r_type; /* type number */ 201*7c478bd9Sstevel@tonic-gate u_long r_ttl; /* time to live */ 202*7c478bd9Sstevel@tonic-gate int r_size; /* size of data area */ 203*7c478bd9Sstevel@tonic-gate char *r_data; /* pointer to data */ 204*7c478bd9Sstevel@tonic-gate }; 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate extern u_short _getshort(); 207*7c478bd9Sstevel@tonic-gate extern u_long _getlong(); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate /* 210*7c478bd9Sstevel@tonic-gate * Inline versions of get/put short/long. 211*7c478bd9Sstevel@tonic-gate * Pointer is advanced; we assume that both arguments 212*7c478bd9Sstevel@tonic-gate * are lvalues and will already be in registers. 213*7c478bd9Sstevel@tonic-gate * cp MUST be u_char *. 214*7c478bd9Sstevel@tonic-gate */ 215*7c478bd9Sstevel@tonic-gate #define GETSHORT(s, cp) { \ 216*7c478bd9Sstevel@tonic-gate (s) = *(cp)++ << 8; \ 217*7c478bd9Sstevel@tonic-gate (s) |= *(cp)++; \ 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate #define GETLONG(l, cp) { \ 221*7c478bd9Sstevel@tonic-gate (l) = *(cp)++ << 8; \ 222*7c478bd9Sstevel@tonic-gate (l) |= *(cp)++; (l) <<= 8; \ 223*7c478bd9Sstevel@tonic-gate (l) |= *(cp)++; (l) <<= 8; \ 224*7c478bd9Sstevel@tonic-gate (l) |= *(cp)++; \ 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate #define PUTSHORT(s, cp) { \ 229*7c478bd9Sstevel@tonic-gate *(cp)++ = (s) >> 8; \ 230*7c478bd9Sstevel@tonic-gate *(cp)++ = (s); \ 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate /* 234*7c478bd9Sstevel@tonic-gate * Warning: PUTLONG destroys its first argument. 235*7c478bd9Sstevel@tonic-gate */ 236*7c478bd9Sstevel@tonic-gate #define PUTLONG(l, cp) { \ 237*7c478bd9Sstevel@tonic-gate (cp)[3] = l; \ 238*7c478bd9Sstevel@tonic-gate (cp)[2] = (l >>= 8); \ 239*7c478bd9Sstevel@tonic-gate (cp)[1] = (l >>= 8); \ 240*7c478bd9Sstevel@tonic-gate (cp)[0] = l >> 8; \ 241*7c478bd9Sstevel@tonic-gate (cp) += sizeof (u_long); \ 242*7c478bd9Sstevel@tonic-gate } 243*7c478bd9Sstevel@tonic-gate 244*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 245*7c478bd9Sstevel@tonic-gate } 246*7c478bd9Sstevel@tonic-gate #endif 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate #endif /* _ARPA_NAMESER_H */ 249