PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/DE2_115_WEB_SERVER_RGMII_ENET0/Software/web_bsp/iniche/src/h/nameser.h

https://gitlab.com/rainbowguardians/RainbowHard
C Header | 427 lines | 254 code | 40 blank | 133 comment | 37 complexity | 1e9c552c4c69dffd085e5b876268b3da MD5 | raw file
  1. /*
  2. * FILENAME: nameser.h
  3. *
  4. * Copyright 2000 By InterNiche Technologies Inc. All rights reserved
  5. *
  6. *
  7. * MODULE: DNS
  8. *
  9. *
  10. * PORTABLE: yes
  11. */
  12. /* Additional Copyrights: */
  13. /*
  14. * Copyright (c) 1982, 1986 Regents of the University of California.
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions
  19. * are met:
  20. * 1. Redistributions of source code must retain the above copyright
  21. * notice, this list of conditions and the following disclaimer.
  22. * 2. Redistributions in binary form must reproduce the above copyright
  23. * notice, this list of conditions and the following disclaimer in the
  24. * documentation and/or other materials provided with the distribution.
  25. * 3. [rescinded 22 July 1999]
  26. * 4. Neither the name of the University nor the names of its contributors
  27. * may be used to endorse or promote products derived from this software
  28. * without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  31. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  34. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  39. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  40. * SUCH DAMAGE.
  41. *
  42. *
  43. * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  44. *
  45. * Permission to use, copy, modify, and distribute this software for any
  46. * purpose with or without fee is hereby granted, provided that the above
  47. * copyright notice and this permission notice appear in all copies, and that
  48. * the name of Digital Equipment Corporation not be used in advertising or
  49. * publicity pertaining to distribution of the document or software without
  50. * specific, written prior permission.
  51. *
  52. * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  53. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  54. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  55. * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  56. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  57. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  58. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  59. * SOFTWARE.
  60. * -
  61. * --Copyright--
  62. */
  63. #ifndef __ARPA_NAMESER_H__
  64. #define __ARPA_NAMESER_H__
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /*
  69. * @(#)nameser.h 8.1 (Berkeley) 6/2/93
  70. * $Id: nameser.h,v 1.1.2.2 2007/11/02 00:46:58 steveh Exp $
  71. */
  72. /*
  73. * revision information. this is the release date in YYYYMMDD format.
  74. * it can change every day so the right thing to do with it is use it
  75. * in preprocessor commands such as "#if (__BIND > 19931104)". do not
  76. * compare for equality; rather, use it to determine whether your resolver
  77. * is new enough to contain a certain feature.
  78. */
  79. #define __BIND 19950621 /* interface version stamp */
  80. /*
  81. * Define constants based on rfc883
  82. */
  83. #define PACKETSZ 512 /* maximum packet size */
  84. #define MAXDNAME 256 /* maximum domain name */
  85. #define MAXCDNAME 255 /* maximum compressed domain name */
  86. #define MAXLABEL 63 /* maximum length of domain label */
  87. #define HFIXEDSZ 12 /* #/bytes of fixed data in header */
  88. #define QFIXEDSZ 4 /* #/bytes of fixed data in query */
  89. #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
  90. #define INT32SZ 4 /* for systems without 32-bit ints */
  91. #define INT16SZ 2 /* for systems without 16-bit ints */
  92. #define INADDRSZ 4 /* for sizeof(struct inaddr) != 4 */
  93. /*
  94. * Internet nameserver port number
  95. */
  96. #define NAMESERVER_PORT 53
  97. /*
  98. * Currently defined opcodes
  99. */
  100. #define QUERY 0x0 /* standard query */
  101. #define IQUERY 0x1 /* inverse query */
  102. #define STATUS 0x2 /* nameserver status query */
  103. /* 0x3 0x3 reserved */
  104. #define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
  105. /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
  106. # define UPDATEA 0x9 /* add resource record */
  107. # define UPDATED 0xa /* delete a specific resource record */
  108. # define UPDATEDA 0xb /* delete all named resource record */
  109. # define UPDATEM 0xc /* modify a specific resource record */
  110. # define UPDATEMA 0xd /* modify all named resource record */
  111. # define ZONEINIT 0xe /* initial zone transfer */
  112. # define ZONEREF 0xf /* incremental zone referesh */
  113. /*
  114. * Currently defined response codes
  115. */
  116. #define NSNOERROR 0 /* no error */
  117. #define FORMERR 1 /* format error */
  118. #define SERVFAIL 2 /* server failure */
  119. #define NXDOMAIN 3 /* non existent domain */
  120. #define NOTIMP 4 /* not implemented */
  121. #define REFUSED 5 /* query refused */
  122. /* non standard */
  123. # define NOCHANGE 0xf /* update failed to change db */
  124. /*
  125. * DDNS response codes
  126. */
  127. #define YXDOMAIN (6)
  128. #define YXRRSET (7)
  129. #define NXRRSET (8)
  130. #define NOTAUTH (9)
  131. #define NOTZONE (10)
  132. #define C_ANY 255 /* wildcard match */
  133. #define C_NONE (254)
  134. #define C_IN 1 /* the arpa internet */
  135. /*
  136. * Type values for resources and queries
  137. */
  138. #define T_A 1 /* host address */
  139. #define T_NS 2 /* authoritative server */
  140. #define T_MD 3 /* mail destination */
  141. #define T_MF 4 /* mail forwarder */
  142. #define T_CNAME 5 /* canonical name */
  143. #define T_SOA 6 /* start of authority zone */
  144. #define T_MB 7 /* mailbox domain name */
  145. #define T_MG 8 /* mail group member */
  146. #define T_MR 9 /* mail rename name */
  147. #define T_NULL 10 /* null resource record */
  148. #define T_WKS 11 /* well known service */
  149. #define T_PTR 12 /* domain name pointer */
  150. #define T_HINFO 13 /* host information */
  151. #define T_MINFO 14 /* mailbox information */
  152. #define T_MX 15 /* mail routing information */
  153. #define T_TXT 16 /* text strings */
  154. #define T_RP 17 /* responsible person */
  155. #define T_AFSDB 18 /* AFS cell database */
  156. #define T_X25 19 /* X_25 calling address */
  157. #define T_ISDN 20 /* ISDN calling address */
  158. #define T_RT 21 /* router */
  159. #define T_NSAP 22 /* NSAP address */
  160. #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
  161. #define T_SIG 24 /* security signature */
  162. #define T_KEY 25 /* security key */
  163. #define T_PX 26 /* X.400 mail mapping */
  164. #define T_GPOS 27 /* geographical position (withdrawn) */
  165. #define T_AAAA 28 /* IP6 Address */
  166. #define T_LOC 29 /* Location Information */
  167. /* non standard */
  168. #define T_UINFO 100 /* user (finger) information */
  169. #define T_UID 101 /* user ID */
  170. #define T_GID 102 /* group ID */
  171. #define T_UNSPEC 103 /* Unspecified format (binary data) */
  172. /* Query type values which do not appear in resource records */
  173. #define T_AXFR 252 /* transfer zone of authority */
  174. #define T_MAILB 253 /* transfer mailbox records */
  175. #define T_MAILA 254 /* transfer mail agent records */
  176. #define T_ANY 255 /* wildcard match */
  177. /*
  178. * Values for class field
  179. */
  180. #define C_IN 1 /* the arpa internet */
  181. #define C_CHAOS 3 /* for chaos net (MIT) */
  182. #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
  183. /* Query class values which do not appear in resource records */
  184. #define C_ANY 255 /* wildcard match */
  185. /*
  186. * Status return codes for T_UNSPEC conversion routines
  187. */
  188. #define CONV_SUCCESS 0
  189. #define CONV_OVERFLOW (-1)
  190. #define CONV_BADFMT (-2)
  191. #define CONV_BADCKSUM (-3)
  192. #define CONV_BADBUFLEN (-4)
  193. #ifndef BYTE_ORDER
  194. #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
  195. #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
  196. #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
  197. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
  198. defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
  199. defined(__alpha__) || defined(__alpha)
  200. #define BYTE_ORDER LITTLE_ENDIAN
  201. #endif
  202. #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
  203. defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
  204. defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
  205. defined(apollo) || defined(__convex__) || defined(_CRAY) || \
  206. defined(__hppa) || defined(__hp9000) || \
  207. defined(__hp9000s300) || defined(__hp9000s700) || \
  208. defined (BIT_ZERO_ON_LEFT) || defined(m68k)
  209. #define BYTE_ORDER BIG_ENDIAN
  210. #endif
  211. #endif /* BYTE_ORDER */
  212. #if !defined(BYTE_ORDER) || \
  213. (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
  214. BYTE_ORDER != PDP_ENDIAN)
  215. {
  216. /* you must determine what the correct bit order is for
  217. * your compiler - the next line is an intentional error
  218. * which will force your compiles to bomb until you fix
  219. * the above macros.
  220. */
  221. error "Undefined or invalid BYTE_ORDER";
  222. }
  223. #endif
  224. #ifdef NS_DDNS
  225. #define MAX_NAM_LEN 256
  226. struct ResRec
  227. {
  228. struct ResRec *next; /* pointer to next RR */
  229. char name[MAX_NAM_LEN]; /* name */
  230. unsigned short type; /* type */
  231. unsigned short dclass; /* class */
  232. unsigned long ttl; /* TTL */
  233. short RDlength; /* length of Rdata */
  234. int flags; /* keep track of processing within a chain */
  235. char *RdataP; /* Rdata, N.b., this still points into
  236. * the original msg! */
  237. };
  238. typedef struct ResRec RR;
  239. /* RR flags */
  240. #define RR_CH_MATCHED (1)
  241. #define NS_UPDATE (5) /* DDNS update */
  242. struct DQDesc
  243. {
  244. char zone[MAX_NAM_LEN]; /* ZONE */
  245. RR *perqsP; /* pointer to prerequisites */
  246. RR *upsP; /* pointer to updates */
  247. RR *addsP; /* pointer to addition RRs */
  248. };
  249. typedef struct DQDesc DQDESC;
  250. DQDESC * dns_parse_ddqry(u_char * msg, int msglen, int buflen, int errCode);
  251. int dns_dynup(DQDESC * DQDp);
  252. #endif
  253. /*
  254. * Structure for query header. The order of the fields is machine- and
  255. * compiler-dependent, depending on the byte/bit order and the layout
  256. * of bit fields. We use bit fields only in int variables, as this
  257. * is all ANSI requires. This requires a somewhat confusing rearrangement.
  258. */
  259. #if 1 /* We don't use bit fields they are not portable ** Narayan **/
  260. typedef struct
  261. {
  262. unsigned short id; /* query ident number */
  263. unsigned char bits [2];
  264. unsigned short qdcount; /* number of question entries */
  265. unsigned short ancount; /* number of answer entries */
  266. unsigned short nscount; /* number of authority entries */
  267. unsigned short arcount; /* number of resource entries */
  268. } HEADER;
  269. #define HEADER_GET_RCODE(x) ((x)->bits [1] & 0xf)
  270. #define HEADER_GET_PR(x) ((x)->bits[1] & 0x40)
  271. #define HEADER_GET_RA(x) ((x)->bits [1] & 0x80)
  272. #define HEADER_GET_RD(x) ((x)->bits [0] & 0x1)
  273. #define HEADER_GET_TC(x) ((x)->bits [0] & 0x2)
  274. #define HEADER_GET_AA(x) ((x)->bits [0] & 0x4)
  275. #define HEADER_GET_OPCODE(x) (((x)->bits [0] >> 3) & 0xF)
  276. #define HEADER_GET_QR(x) ((x)->bits [0] & 0x80)
  277. #define HEADER_CLR_PR(x) ((x)->bits [1] & ~0x40)
  278. #define HEADER_SET_PR(x) ((x)->bits [1] |= 0x40)
  279. #define HEADER_SET_RA(x) ((x)->bits [1] |= 0x80)
  280. #define HEADER_SET_RD(x) ((x)->bits [0] |= 0x1)
  281. #define HEADER_CLR_RD(x) ((x)->bits [0] &= ~0x1)
  282. #define HEADER_SET_TC(x) ((x)->bits [0] |= 0x2)
  283. #define HEADER_CLR_TC(x) ((x)->bits [0] &= ~0x2)
  284. #define HEADER_SET_AA(x) ((x)->bits [0] |= 0x4)
  285. #define HEADER_CLR_AA(x) ((x)->bits [0] &= ~0x4)
  286. #define HEADER_SET_RCODE(x,v) {(x)->bits [1] |= ((v) & 0xf);}
  287. #define HEADER_SET_QR(x) ((x)->bits [0] |= 0x80)
  288. #define HEADER_CLR_QR(x) ((x)->bits [0] &= ~0x80)
  289. #define HEADER_SET_OPCODE(h,code) {(h)->bits [0] |= ((code) << 3);}
  290. #else /* Use BIT-Fields */
  291. typedef struct
  292. {
  293. unsigned id :16; /* query identification number */
  294. #if BYTE_ORDER == BIG_ENDIAN
  295. /* fields in third byte */
  296. unsigned qr: 1; /* response flag */
  297. unsigned opcode: 4; /* purpose of message */
  298. unsigned aa: 1; /* authoritive answer */
  299. unsigned tc: 1; /* truncated message */
  300. unsigned rd: 1; /* recursion desired */
  301. /* fields in fourth byte */
  302. unsigned ra: 1; /* recursion available */
  303. unsigned pr: 1; /* primary server reqd (nonstd) */
  304. unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
  305. unsigned rcode :4; /* response code */
  306. #endif
  307. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  308. /* fields in third byte */
  309. unsigned rd :1; /* recursion desired */
  310. unsigned tc :1; /* truncated message */
  311. unsigned aa :1; /* authoritive answer */
  312. unsigned opcode :4; /* purpose of message */
  313. unsigned qr :1; /* response flag */
  314. /* fields in fourth byte */
  315. unsigned rcode :4; /* response code */
  316. unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
  317. unsigned pr: 1; /* primary server reqd (nonstd) */
  318. unsigned ra :1; /* recursion available */
  319. #endif
  320. /* remaining bytes */
  321. unsigned qdcount :16; /* number of question entries */
  322. unsigned ancount :16; /* number of answer entries */
  323. unsigned nscount :16; /* number of authority entries */
  324. unsigned arcount :16; /* number of resource entries */
  325. } HEADER;
  326. #endif /* 0 */
  327. /*
  328. * Defines for handling compressed domain names
  329. */
  330. #define INDIR_MASK 0xc0
  331. /*
  332. * Structure for passing resource records around.
  333. */
  334. struct rrec {
  335. int16_t r_zone; /* zone number */
  336. int16_t r_class; /* class number */
  337. int16_t r_type; /* type number */
  338. u_int32_t r_ttl; /* time to live */
  339. int r_size; /* size of data area */
  340. char * r_data; /* pointer to data */
  341. };
  342. /*
  343. * Inline versions of get/put short/long. Pointer is advanced.
  344. *
  345. * These macros demonstrate the property of C whereby it can be
  346. * portable or it can be elegant but rarely both.
  347. */
  348. #define GETSHORT(s, cp) { \
  349. u_char *t_cp = (u_char *)(cp); \
  350. (s) = ((u_int16_t)t_cp[0] << 8) \
  351. | ((u_int16_t)t_cp[1]) \
  352. ; \
  353. (cp) += INT16SZ; \
  354. }
  355. #define GETLONG(l, cp) { \
  356. u_char *t_cp = (u_char *)(cp); \
  357. (l) = ((u_int32_t)t_cp[0] << 24) \
  358. | ((u_int32_t)t_cp[1] << 16) \
  359. | ((u_int32_t)t_cp[2] << 8) \
  360. | ((u_int32_t)t_cp[3]) \
  361. ; \
  362. (cp) += INT32SZ; \
  363. }
  364. #define PUTSHORT(s, cp) { \
  365. u_int16_t t_s = (u_int16_t)(s); \
  366. u_char *t_cp = (u_char *)(cp); \
  367. *t_cp++ = (u_char)(t_s >> 8); \
  368. *t_cp = (u_char)t_s; \
  369. (cp) += INT16SZ; \
  370. }
  371. #define PUTLONG(l, cp) { \
  372. u_int32_t t_l = (u_int32_t)(l); \
  373. u_char *t_cp = (u_char *)(cp); \
  374. *t_cp++ = (u_char)(t_l >> 24); \
  375. *t_cp++ = (u_char)(t_l >> 16); \
  376. *t_cp++ = (u_char)(t_l >> 8); \
  377. *t_cp = (u_char)t_l; \
  378. (cp) += INT32SZ; \
  379. }
  380. #define syslog(l,fmt)
  381. #define syslog1(l,fmt,a)
  382. #define syslog2(l,fmt,a,b)
  383. #define syslog3(l,fmt,a,b,c)
  384. #ifdef __cplusplus
  385. }
  386. #endif
  387. #endif /* !__ARPA__NAMESER_H__ */