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