Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
9.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nameser.h
  5. Abstract:
  6. Definitions for the DNS resolver and nameserver.
  7. Author:
  8. Mike Massa (mikemas) Jan 31, 1992
  9. Revision History:
  10. Who When What
  11. -------- -------- ----------------------------------------------
  12. mikemas 01-31-92 created
  13. Notes:
  14. --*/
  15. /******************************************************************
  16. *
  17. * SpiderTCP BIND
  18. *
  19. * Copyright 1990 Spider Systems Limited
  20. *
  21. * NAMESER.H
  22. *
  23. ******************************************************************/
  24. /*
  25. * /usr/projects/tcp/SCCS.rel3/rel/src/include/arpa/0/s.nameser.h
  26. * @(#)nameser.h 5.3
  27. *
  28. * Last delta created 14:06:04 3/4/91
  29. * This file extracted 11:19:28 3/8/91
  30. *
  31. * Modifications:
  32. *
  33. * GSS 20 Jul 90 New File
  34. */
  35. /*
  36. * Copyright (c) 1983, 1989 Regents of the University of California.
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms are permitted
  40. * provided that: (1) source distributions retain this entire copyright
  41. * notice and comment, and (2) distributions including binaries display
  42. * the following acknowledgement: ``This product includes software
  43. * developed by the University of California, Berkeley and its contributors''
  44. * in the documentation or other materials provided with the distribution
  45. * and in all advertising materials mentioning features or use of this
  46. * software. Neither the name of the University nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  50. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  51. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  52. *
  53. * @(#)nameser.h 5.24 (Berkeley) 6/1/90
  54. */
  55. #ifndef _NAMESER_INCLUDED
  56. #define _NAMESER_INCLUDED
  57. /*
  58. * Define constants based on rfc883
  59. */
  60. #define PACKETSZ 512 /* maximum packet size */
  61. #define MAXDNAME 256 /* maximum domain name */
  62. #define MAXCDNAME 255 /* maximum compressed domain name */
  63. #define MAXLABEL 63 /* maximum length of domain label */
  64. /* Number of bytes of fixed size data in query structure */
  65. #define QFIXEDSZ 4
  66. /* number of bytes of fixed size data in resource record */
  67. #define RRFIXEDSZ 10
  68. /*
  69. * Internet nameserver port number
  70. */
  71. #define NAMESERVER_PORT 53
  72. /*
  73. * Currently defined opcodes
  74. */
  75. #define QUERY 0x0 /* standard query */
  76. #define IQUERY 0x1 /* inverse query */
  77. #define STATUS 0x2 /* nameserver status query */
  78. /*#define xxx 0x3 /* 0x3 reserved */
  79. /* non standard */
  80. #define UPDATEA 0x9 /* add resource record */
  81. #define UPDATED 0xa /* delete a specific resource record */
  82. #define UPDATEDA 0xb /* delete all nemed resource record */
  83. #define UPDATEM 0xc /* modify a specific resource record */
  84. #define UPDATEMA 0xd /* modify all named resource record */
  85. #define ZONEINIT 0xe /* initial zone transfer */
  86. #define ZONEREF 0xf /* incremental zone referesh */
  87. /*
  88. * Currently defined response codes
  89. */
  90. #ifndef NOERROR
  91. #define NOERROR 0 /* no error */
  92. #endif
  93. #define FORMERR 1 /* format error */
  94. #define SERVFAIL 2 /* server failure */
  95. #define NXDOMAIN 3 /* non existent domain */
  96. #define NOTIMP 4 /* not implemented */
  97. #define REFUSED 5 /* query refused */
  98. /* non standard */
  99. #define NOCHANGE 0xf /* update failed to change db */
  100. /*
  101. * Type values for resources and queries
  102. */
  103. #define T_A 1 /* host address */
  104. #define T_NS 2 /* authoritative server */
  105. #define T_MD 3 /* mail destination */
  106. #define T_MF 4 /* mail forwarder */
  107. #define T_CNAME 5 /* connonical name */
  108. #define T_SOA 6 /* start of authority zone */
  109. #define T_MB 7 /* mailbox domain name */
  110. #define T_MG 8 /* mail group member */
  111. #define T_MR 9 /* mail rename name */
  112. #define T_NULL 10 /* null resource record */
  113. #define T_WKS 11 /* well known service */
  114. #define T_PTR 12 /* domain name pointer */
  115. #define T_HINFO 13 /* host information */
  116. #define T_MINFO 14 /* mailbox information */
  117. #define T_MX 15 /* mail routing information */
  118. #define T_TXT 16 /* text strings */
  119. #define T_AFSDB 18 /* AFS database servers */
  120. #define T_ATMA 34 /* ATM endpoint address */
  121. /* non standard */
  122. #define T_UINFO 100 /* user (finger) information */
  123. #define T_UID 101 /* user ID */
  124. #define T_GID 102 /* group ID */
  125. #define T_UNSPEC 103 /* Unspecified format (binary data) */
  126. /* Query type values which do not appear in resource records */
  127. #define T_AXFR 252 /* transfer zone of authority */
  128. #define T_MAILB 253 /* transfer mailbox records */
  129. #define T_MAILA 254 /* transfer mail agent records */
  130. #define T_ANY 255 /* wildcard match */
  131. /*
  132. * Values for class field
  133. */
  134. #define C_IN 1 /* the arpa internet */
  135. #define C_CHAOS 3 /* for chaos net at MIT */
  136. #define C_HS 4 /* for Hesiod name server at MIT */
  137. /* Query class values which do not appear in resource records */
  138. #define C_ANY 255 /* wildcard match */
  139. /*
  140. * Status return codes for T_UNSPEC conversion routines
  141. */
  142. #define CONV_SUCCESS 0
  143. #define CONV_OVERFLOW -1
  144. #define CONV_BADFMT -2
  145. #define CONV_BADCKSUM -3
  146. #define CONV_BADBUFLEN -4
  147. #ifndef BYTE_ORDER
  148. #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax) */
  149. #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
  150. #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
  151. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(MIPSEL) || \
  152. defined(BIT_ZERO_ON_RIGHT)
  153. #define BYTE_ORDER LITTLE_ENDIAN
  154. #endif
  155. #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
  156. defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
  157. defined(MIPSEB) || defined (BIT_ZERO_ON_LEFT)
  158. #define BYTE_ORDER BIG_ENDIAN
  159. #endif
  160. #ifndef BYTE_ORDER /* still not defined */
  161. #if defined(u3b2) || defined(m68k)
  162. #define BYTE_ORDER BIG_ENDIAN
  163. #endif
  164. #if defined(i286) || defined(i386) || defined(_AMD64_) || defined(_IA64_)
  165. #define BYTE_ORDER LITTLE_ENDIAN
  166. #endif
  167. #endif /* ~BYTE_ORDER */
  168. #endif /* BYTE_ORDER */
  169. #ifndef BYTE_ORDER
  170. /* you must determine what the correct bit order is for your compiler */
  171. UNDEFINED_BIT_ORDER;
  172. #endif
  173. /*
  174. * Structure for query header, the order of the fields is machine and
  175. * compiler dependent, in our case, the bits within a byte are assignd
  176. * least significant first, while the order of transmition is most
  177. * significant first. This requires a somewhat confusing rearrangement.
  178. */
  179. typedef struct {
  180. unsigned short id; /* query identification number */
  181. #if BYTE_ORDER == BIG_ENDIAN
  182. /* fields in third byte */
  183. unsigned char qr:1; /* response flag */
  184. unsigned char opcode:4; /* purpose of message */
  185. unsigned char aa:1; /* authoritive answer */
  186. unsigned char tc:1; /* truncated message */
  187. unsigned char rd:1; /* recursion desired */
  188. /* fields in fourth byte */
  189. unsigned char ra:1; /* recursion available */
  190. unsigned char pr:1; /* primary server required (non standard) */
  191. unsigned char unused:2; /* unused bits */
  192. unsigned char rcode:4; /* response code */
  193. #endif
  194. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  195. /* fields in third byte */
  196. unsigned char rd:1; /* recursion desired */
  197. unsigned char tc:1; /* truncated message */
  198. unsigned char aa:1; /* authoritive answer */
  199. unsigned char opcode:4; /* purpose of message */
  200. unsigned char qr:1; /* response flag */
  201. /* fields in fourth byte */
  202. unsigned char rcode:4; /* response code */
  203. unsigned char unused:2; /* unused bits */
  204. unsigned char pr:1; /* primary server required (non standard) */
  205. unsigned char ra:1; /* recursion available */
  206. #endif
  207. /* remaining bytes */
  208. unsigned short qdcount; /* number of question entries */
  209. unsigned short ancount; /* number of answer entries */
  210. unsigned short nscount; /* number of authority entries */
  211. unsigned short arcount; /* number of resource entries */
  212. } HEADER;
  213. /*
  214. * Defines for handling compressed domain names
  215. */
  216. #define INDIR_MASK 0xc0
  217. /*
  218. * Structure for passing resource records around.
  219. */
  220. struct rrec {
  221. short r_zone; /* zone number */
  222. short r_class; /* class number */
  223. short r_type; /* type number */
  224. unsigned long r_ttl; /* time to live */
  225. int r_size; /* size of data area */
  226. char *r_data; /* pointer to data */
  227. };
  228. extern unsigned short _getshort();
  229. extern unsigned long _getlong();
  230. /*
  231. * Inline versions of get/put short/long.
  232. * Pointer is advanced; we assume that both arguments
  233. * are lvalues and will already be in registers.
  234. * cp MUST be unsigned char *.
  235. */
  236. #define GETSHORT(s, cp) { \
  237. (s) = *(cp)++ << 8; \
  238. (s) |= *(cp)++; \
  239. }
  240. #define GETLONG(l, cp) { \
  241. (l) = *(cp)++ << 8; \
  242. (l) |= *(cp)++; (l) <<= 8; \
  243. (l) |= *(cp)++; (l) <<= 8; \
  244. (l) |= *(cp)++; \
  245. }
  246. #define PUTSHORT(s, cp) { \
  247. *(cp)++ = (s) >> 8; \
  248. *(cp)++ = (s); \
  249. }
  250. /*
  251. * Warning: PUTLONG destroys its first argument.
  252. */
  253. #define PUTLONG(l, cp) { \
  254. (cp)[3] = l; \
  255. (cp)[2] = (l >>= 8); \
  256. (cp)[1] = (l >>= 8); \
  257. (cp)[0] = l >> 8; \
  258. (cp) += sizeof(unsigned long); \
  259. }
  260. #endif // _NAMESER_INCLUDED