| 1 | /* Modified for emx by hv 1994,1996
|
|---|
| 2 | *
|
|---|
| 3 | * Copyright (c) 1983, 1989 Regents of the University of California.
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * 3. All advertising materials mentioning features or use of this software
|
|---|
| 15 | * must display the following acknowledgement:
|
|---|
| 16 | * This product includes software developed by the University of
|
|---|
| 17 | * California, Berkeley and its contributors.
|
|---|
| 18 | * 4. Neither the name of the University nor the names of its contributors
|
|---|
| 19 | * may be used to endorse or promote products derived from this software
|
|---|
| 20 | * without specific prior written permission.
|
|---|
| 21 | *
|
|---|
| 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|---|
| 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|---|
| 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|---|
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|---|
| 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|---|
| 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|---|
| 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|---|
| 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|---|
| 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|---|
| 32 | * SUCH DAMAGE.
|
|---|
| 33 | *
|
|---|
| 34 | * from: @(#)nameser.h 5.25 (Berkeley) 4/3/91
|
|---|
| 35 | * $Id: nameser.h,v 1.4 1993/10/27 00:10:40 mycroft Exp $
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #ifndef _NAMESER_H_
|
|---|
| 39 | #define _NAMESER_H_
|
|---|
| 40 |
|
|---|
| 41 | #if defined (__cplusplus)
|
|---|
| 42 | extern "C" {
|
|---|
| 43 | #endif
|
|---|
| 44 |
|
|---|
| 45 | #include <sys/param.h> /* htons() etc. */
|
|---|
| 46 | #include <machine/endian.h> /* BYTE ORDER etc. */
|
|---|
| 47 |
|
|---|
| 48 | /*
|
|---|
| 49 | * Define constants based on rfc883
|
|---|
| 50 | */
|
|---|
| 51 | #define PACKETSZ 512 /* maximum packet size */
|
|---|
| 52 | #define MAXDNAME 256 /* maximum domain name */
|
|---|
| 53 | #define MAXCDNAME 255 /* maximum compressed domain name */
|
|---|
| 54 | #define MAXLABEL 63 /* maximum length of domain label */
|
|---|
| 55 | /* Number of bytes of fixed size data in query structure */
|
|---|
| 56 | #define QFIXEDSZ 4
|
|---|
| 57 | /* number of bytes of fixed size data in resource record */
|
|---|
| 58 | #define RRFIXEDSZ 10
|
|---|
| 59 |
|
|---|
| 60 | /*
|
|---|
| 61 | * Internet nameserver port number
|
|---|
| 62 | */
|
|---|
| 63 | #define NAMESERVER_PORT 53
|
|---|
| 64 |
|
|---|
| 65 | /*
|
|---|
| 66 | * Currently defined opcodes
|
|---|
| 67 | */
|
|---|
| 68 | #define QUERY 0x0 /* standard query */
|
|---|
| 69 | #define IQUERY 0x1 /* inverse query */
|
|---|
| 70 | #define STATUS 0x2 /* nameserver status query */
|
|---|
| 71 | /*#define xxx 0x3 0x3 reserved */
|
|---|
| 72 | /* non standard */
|
|---|
| 73 | /* IBM has changed these codes in TCP/IP for OS/2 */
|
|---|
| 74 | #define UPDATEA 100 /* add resource record */
|
|---|
| 75 | #define UPDATED 101 /* delete a specific resource record */
|
|---|
| 76 | #define UPDATEM 102 /* modify a specific resource record */
|
|---|
| 77 | #define ZONEINIT 103 /* initial zone transfer */
|
|---|
| 78 | #define ZONEREF 104 /* 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 100 /* 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 | #define C_IN 1 /* the arpa internet */
|
|---|
| 126 | #define C_CHAOS 3 /* for chaos net at MIT */
|
|---|
| 127 | #define C_HS 4 /* for Hesiod name server at MIT */
|
|---|
| 128 | /* Query class values which do not appear in resource records */
|
|---|
| 129 | #define C_ANY 255 /* wildcard match */
|
|---|
| 130 |
|
|---|
| 131 | /*
|
|---|
| 132 | * Status return codes for T_UNSPEC conversion routines
|
|---|
| 133 | */
|
|---|
| 134 | #define CONV_SUCCESS 0
|
|---|
| 135 | #define CONV_OVERFLOW -1
|
|---|
| 136 | #define CONV_BADFMT -2
|
|---|
| 137 | #define CONV_BADCKSUM -3
|
|---|
| 138 | #define CONV_BADBUFLEN -4
|
|---|
| 139 |
|
|---|
| 140 | /*
|
|---|
| 141 | * Structure for query header, the order of the fields is machine and
|
|---|
| 142 | * compiler dependent, in our case, the bits within a byte are assignd
|
|---|
| 143 | * least significant first, while the order of transmition is most
|
|---|
| 144 | * significant first. This requires a somewhat confusing rearrangement.
|
|---|
| 145 | */
|
|---|
| 146 | typedef struct {
|
|---|
| 147 | u_short id; /* query identification number */
|
|---|
| 148 | #if BYTE_ORDER == BIG_ENDIAN
|
|---|
| 149 | /* fields in third byte */
|
|---|
| 150 | u_char qr:1; /* response flag */
|
|---|
| 151 | u_char opcode:4; /* purpose of message */
|
|---|
| 152 | u_char aa:1; /* authoritive answer */
|
|---|
| 153 | u_char tc:1; /* truncated message */
|
|---|
| 154 | u_char rd:1; /* recursion desired */
|
|---|
| 155 | /* fields in fourth byte */
|
|---|
| 156 | u_char ra:1; /* recursion available */
|
|---|
| 157 | u_char pr:1; /* primary server required (non standard) */
|
|---|
| 158 | u_char unused:2; /* unused bits */
|
|---|
| 159 | u_char rcode:4; /* response code */
|
|---|
| 160 | #endif
|
|---|
| 161 | #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
|
|---|
| 162 | /* fields in third byte */
|
|---|
| 163 | u_char rd:1; /* recursion desired */
|
|---|
| 164 | u_char tc:1; /* truncated message */
|
|---|
| 165 | u_char aa:1; /* authoritive answer */
|
|---|
| 166 | u_char opcode:4; /* purpose of message */
|
|---|
| 167 | u_char qr:1; /* response flag */
|
|---|
| 168 | /* fields in fourth byte */
|
|---|
| 169 | u_char rcode:4; /* response code */
|
|---|
| 170 | u_char unused:2; /* unused bits */
|
|---|
| 171 | u_char pr:1; /* primary server required (non standard) */
|
|---|
| 172 | u_char ra:1; /* recursion available */
|
|---|
| 173 | #endif
|
|---|
| 174 | /* remaining bytes */
|
|---|
| 175 | u_short qdcount; /* number of question entries */
|
|---|
| 176 | u_short ancount; /* number of answer entries */
|
|---|
| 177 | u_short nscount; /* number of authority entries */
|
|---|
| 178 | u_short arcount; /* number of resource entries */
|
|---|
| 179 | } HEADER;
|
|---|
| 180 |
|
|---|
| 181 | /*
|
|---|
| 182 | * Defines for handling compressed domain names
|
|---|
| 183 | */
|
|---|
| 184 | #define INDIR_MASK 0xc0
|
|---|
| 185 |
|
|---|
| 186 | /*
|
|---|
| 187 | * Structure for passing resource records around.
|
|---|
| 188 | */
|
|---|
| 189 | #pragma pack(4)
|
|---|
| 190 | struct rrec {
|
|---|
| 191 | short r_zone; /* zone number */
|
|---|
| 192 | short r_class; /* class number */
|
|---|
| 193 | short r_type; /* type number */
|
|---|
| 194 | u_long r_ttl; /* time to live */
|
|---|
| 195 | int r_size; /* size of data area */
|
|---|
| 196 | char *r_data; /* pointer to data */
|
|---|
| 197 | };
|
|---|
| 198 | #pragma pack()
|
|---|
| 199 |
|
|---|
| 200 | /*
|
|---|
| 201 | * Inline versions of get/put short/long.
|
|---|
| 202 | * Pointer is advanced; we assume that both arguments
|
|---|
| 203 | * are lvalues and will already be in registers.
|
|---|
| 204 | * cp MUST be u_char *.
|
|---|
| 205 | */
|
|---|
| 206 | #define GETSHORT(s, cp) { \
|
|---|
| 207 | (s) = *(cp)++ << 8; \
|
|---|
| 208 | (s) |= *(cp)++; \
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | #define GETLONG(l, cp) { \
|
|---|
| 212 | (l) = *(cp)++ << 8; \
|
|---|
| 213 | (l) |= *(cp)++; (l) <<= 8; \
|
|---|
| 214 | (l) |= *(cp)++; (l) <<= 8; \
|
|---|
| 215 | (l) |= *(cp)++; \
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 | #define PUTSHORT(s, cp) { \
|
|---|
| 220 | *(cp)++ = (s) >> 8; \
|
|---|
| 221 | *(cp)++ = (s); \
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /*
|
|---|
| 225 | * Warning: PUTLONG destroys its first argument.
|
|---|
| 226 | */
|
|---|
| 227 | #define PUTLONG(l, cp) { \
|
|---|
| 228 | (cp)[3] = l; \
|
|---|
| 229 | (cp)[2] = (l >>= 8); \
|
|---|
| 230 | (cp)[1] = (l >>= 8); \
|
|---|
| 231 | (cp)[0] = l >> 8; \
|
|---|
| 232 | (cp) += sizeof(u_long); \
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /* function prototypes */
|
|---|
| 236 | u_short _getshort(u_char*);
|
|---|
| 237 | u_long _getlong(u_char*);
|
|---|
| 238 | void putshort(u_short, u_char *);
|
|---|
| 239 | void putlong(u_long, u_char *);
|
|---|
| 240 | int dn_expand(__const__ u_char*, __const__ u_char*, __const__ u_char*,
|
|---|
| 241 | u_char*, int);
|
|---|
| 242 | int dn_comp(__const__ u_char*, u_char*, int, u_char**, u_char**);
|
|---|
| 243 | int dn_find(u_char*, u_char*, u_char**, u_char**);
|
|---|
| 244 | int dn_skipname(__const__ u_char*, __const__ u_char*);
|
|---|
| 245 | int res_init(void);
|
|---|
| 246 | int res_mkquery(int, __const__ char*, int, int, __const__ char*,
|
|---|
| 247 | int, __const__ struct rrec*, char*, int);
|
|---|
| 248 | int res_send(__const__ char*, int, char*, int);
|
|---|
| 249 | int res_query(char*, int, int, u_char*, int);
|
|---|
| 250 | int res_search(char*, int, int, u_char*, int);
|
|---|
| 251 | int res_querydomain(char*, char*, int, int, u_char*, int);
|
|---|
| 252 |
|
|---|
| 253 | #if defined (__cplusplus)
|
|---|
| 254 | }
|
|---|
| 255 | #endif
|
|---|
| 256 |
|
|---|
| 257 | #endif /* !_NAMESER_H_ */
|
|---|