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