Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
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.

364 lines
14 KiB

24 years ago
  1. /* $OpenBSD: resolv.h,v 1.19 2012/12/05 23:19:57 deraadt Exp $ */
  2. /*
  3. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  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. Neither the name of the project nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. /*
  31. * ++Copyright++ 1983, 1987, 1989, 1993
  32. * -
  33. * Copyright (c) 1983, 1987, 1989, 1993
  34. * The Regents of the University of California. All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. * 1. Redistributions of source code must retain the above copyright
  40. * notice, this list of conditions and the following disclaimer.
  41. * 2. Redistributions in binary form must reproduce the above copyright
  42. * notice, this list of conditions and the following disclaimer in the
  43. * documentation and/or other materials provided with the distribution.
  44. * 3. Neither the name of the University nor the names of its contributors
  45. * may be used to endorse or promote products derived from this software
  46. * without specific prior written permission.
  47. *
  48. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  49. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  52. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  53. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  54. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  57. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  58. * SUCH DAMAGE.
  59. * -
  60. * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  61. *
  62. * Permission to use, copy, modify, and distribute this software for any
  63. * purpose with or without fee is hereby granted, provided that the above
  64. * copyright notice and this permission notice appear in all copies, and that
  65. * the name of Digital Equipment Corporation not be used in advertising or
  66. * publicity pertaining to distribution of the document or software without
  67. * specific, written prior permission.
  68. *
  69. * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  70. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  71. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  72. * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  73. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  74. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  75. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  76. * SOFTWARE.
  77. * -
  78. * --Copyright--
  79. */
  80. /*
  81. * @(#)resolv.h 8.1 (Berkeley) 6/2/93
  82. * $From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $
  83. */
  84. #ifndef _RESOLV_H_
  85. #define _RESOLV_H_
  86. #include <sys/types.h>
  87. #include <sys/socket.h>
  88. #include <stdio.h>
  89. /*
  90. * Revision information. This is the release date in YYYYMMDD format.
  91. * It can change every day so the right thing to do with it is use it
  92. * in preprocessor commands such as "#if (__RES > 19931104)". Do not
  93. * compare for equality; rather, use it to determine whether your resolver
  94. * is new enough to contain a certain feature.
  95. */
  96. #define __RES 19960801
  97. /*
  98. * Resolver configuration file.
  99. * Normally not present, but may contain the address of the
  100. * initial name server(s) to query and the domain search list.
  101. */
  102. #ifndef _PATH_RESCONF
  103. #define _PATH_RESCONF "/etc/resolv.conf"
  104. #endif
  105. /*
  106. * Global defines and variables for resolver stub.
  107. */
  108. #define MAXNS 3 /* max # name servers we'll track */
  109. #define MAXDFLSRCH 3 /* # default domain levels to try */
  110. #define MAXDNSRCH 6 /* max # domains in search path */
  111. #define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
  112. #define MAXDNSLUS 4 /* max # of host lookup types */
  113. #define RES_TIMEOUT 5 /* min. seconds between retries */
  114. #define MAXRESOLVSORT 10 /* number of net to sort on */
  115. #define RES_MAXNDOTS 15 /* should reflect bit field size */
  116. struct __res_state {
  117. int retrans; /* retransmission time interval */
  118. int retry; /* number of times to retransmit */
  119. unsigned int options; /* option flags - see below. */
  120. int nscount; /* number of name servers */
  121. int family[2]; /* specifies which address
  122. * families will be queried and
  123. * in which order */
  124. struct sockaddr_in
  125. nsaddr_list[MAXNS]; /* address of name server */
  126. #define nsaddr nsaddr_list[0] /* for backward compatibility */
  127. unsigned short id; /* current message id */
  128. char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
  129. char defdname[256]; /* default domain (deprecated) */
  130. unsigned int pfcode; /* RES_PRF_ flags - see below. */
  131. unsigned ndots:4; /* threshold for initial abs. query */
  132. unsigned nsort:4; /* number of elements in sort_list[] */
  133. char unused[3];
  134. struct {
  135. struct in_addr addr;
  136. u_int32_t mask;
  137. } sort_list[MAXRESOLVSORT];
  138. char lookups[MAXDNSLUS];
  139. struct timespec restimespec;
  140. time_t reschktime;
  141. };
  142. #if 1 /* INET6 */
  143. /*
  144. * replacement of __res_state, separated to keep binary compatibility.
  145. */
  146. struct __res_state_ext {
  147. struct sockaddr_storage nsaddr_list[MAXNS];
  148. struct {
  149. int af; /* address family for addr, mask */
  150. union {
  151. struct in_addr ina;
  152. struct in6_addr in6a;
  153. } addr, mask;
  154. } sort_list[MAXRESOLVSORT];
  155. };
  156. #endif
  157. /*
  158. * Resolver options (keep these in synch with res_debug.c, please)
  159. */
  160. #define RES_INIT 0x00000001 /* address initialized */
  161. #define RES_DEBUG 0x00000002 /* print debug messages */
  162. #define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
  163. #define RES_USEVC 0x00000008 /* use virtual circuit */
  164. #define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
  165. #define RES_IGNTC 0x00000020 /* ignore trucation errors */
  166. #define RES_RECURSE 0x00000040 /* recursion desired */
  167. #define RES_DEFNAMES 0x00000080 /* use default domain name */
  168. #define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
  169. #define RES_DNSRCH 0x00000200 /* search up local domain tree */
  170. #define RES_INSECURE1 0x00000400 /* type 1 security disabled */
  171. #define RES_INSECURE2 0x00000800 /* type 2 security disabled */
  172. #define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
  173. #define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
  174. /* KAME extensions: use higher bit to avoid conflict with ISC use */
  175. #define RES_USE_EDNS0 0x40000000 /* use EDNS0 */
  176. /* DNSSEC extensions: use higher bit to avoid conflict with ISC use */
  177. #define RES_USE_DNSSEC 0x20000000 /* use DNSSEC using OK bit in OPT */
  178. #define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
  179. /*
  180. * Resolver "pfcode" values. Used by dig.
  181. */
  182. #define RES_PRF_STATS 0x00000001
  183. /* 0x00000002 */
  184. #define RES_PRF_CLASS 0x00000004
  185. #define RES_PRF_CMD 0x00000008
  186. #define RES_PRF_QUES 0x00000010
  187. #define RES_PRF_ANS 0x00000020
  188. #define RES_PRF_AUTH 0x00000040
  189. #define RES_PRF_ADD 0x00000080
  190. #define RES_PRF_HEAD1 0x00000100
  191. #define RES_PRF_HEAD2 0x00000200
  192. #define RES_PRF_TTLID 0x00000400
  193. #define RES_PRF_HEADX 0x00000800
  194. #define RES_PRF_QUERY 0x00001000
  195. #define RES_PRF_REPLY 0x00002000
  196. #define RES_PRF_INIT 0x00004000
  197. /* 0x00008000 */
  198. /* hooks are still experimental as of 4.9.2 */
  199. typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
  200. res_sendhookact;
  201. typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
  202. const unsigned char **query,
  203. int *querylen,
  204. unsigned char *ans,
  205. int anssiz,
  206. int *resplen);
  207. typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
  208. const unsigned char *query,
  209. int querylen,
  210. unsigned char *ans,
  211. int anssiz,
  212. int *resplen);
  213. struct res_sym {
  214. int number; /* Identifying number, like T_MX */
  215. char * name; /* Its symbolic name, like "MX" */
  216. char * humanname; /* Its fun name, like "mail exchanger" */
  217. };
  218. extern struct __res_state _res;
  219. #if 1 /* INET6 */
  220. extern struct __res_state_ext _res_ext;
  221. #endif
  222. extern const struct res_sym __p_class_syms[];
  223. extern const struct res_sym __p_type_syms[];
  224. /* Private routines shared between libc/net, named, nslookup and others. */
  225. #define res_hnok __res_hnok
  226. #define res_ownok __res_ownok
  227. #define res_mailok __res_mailok
  228. #define res_dnok __res_dnok
  229. #define sym_ston __sym_ston
  230. #define sym_ntos __sym_ntos
  231. #define sym_ntop __sym_ntop
  232. #define b64_ntop __b64_ntop
  233. #define b64_pton __b64_pton
  234. #define loc_ntoa __loc_ntoa
  235. #define loc_aton __loc_aton
  236. #define dn_skipname __dn_skipname
  237. #define fp_resstat __fp_resstat
  238. #define fp_query __fp_query
  239. #define fp_nquery __fp_nquery
  240. #define hostalias __hostalias
  241. #define putlong __putlong
  242. #define putshort __putshort
  243. #define p_class __p_class
  244. #define p_time __p_time
  245. #define p_type __p_type
  246. #define p_query __p_query
  247. #define p_cdnname __p_cdnname
  248. #define p_cdname __p_cdname
  249. #define p_fqnname __p_fqnname
  250. #define p_fqname __p_fqname
  251. #define p_rr __p_rr
  252. #define p_option __p_option
  253. #define p_secstodate __p_secstodate
  254. #define dn_count_labels __dn_count_labels
  255. #define dn_comp __dn_comp
  256. #define res_randomid __res_randomid
  257. #define res_send __res_send
  258. #define res_isourserver __res_isourserver
  259. #define res_nameinquery __res_nameinquery
  260. #define res_queriesmatch __res_queriesmatch
  261. #define res_close __res_close
  262. #define res_opt __res_opt
  263. #ifdef BIND_RES_POSIX3
  264. #define dn_expand __dn_expand
  265. #define res_init __res_init
  266. #define res_query __res_query
  267. #define res_search __res_search
  268. #define res_querydomain __res_querydomain
  269. #define res_mkquery __res_mkquery
  270. #endif
  271. __BEGIN_DECLS
  272. int res_hnok(const char *);
  273. int res_ownok(const char *);
  274. int res_mailok(const char *);
  275. int res_dnok(const char *);
  276. int sym_ston(const struct res_sym *, char *, int *);
  277. const char * sym_ntos(const struct res_sym *, int, int *);
  278. const char * sym_ntop(const struct res_sym *, int, int *);
  279. int b64_ntop(unsigned char const *, size_t, char *, size_t);
  280. int b64_pton(char const *, unsigned char *, size_t);
  281. int loc_aton(const char *, unsigned char *);
  282. const char * loc_ntoa(const unsigned char *, char *);
  283. int dn_skipname(const unsigned char *,
  284. const unsigned char *);
  285. void fp_resstat(struct __res_state *, FILE *);
  286. void fp_query(const unsigned char *, FILE *);
  287. void fp_nquery(const unsigned char *, int, FILE *);
  288. const char * hostalias(const char *);
  289. void putlong(u_int32_t, unsigned char *);
  290. void putshort(u_int16_t, unsigned char *);
  291. const char * p_class(int);
  292. const char * p_time(u_int32_t);
  293. const char * p_type(int);
  294. void p_query(const unsigned char *);
  295. const unsigned char * p_cdnname(const unsigned char *, const unsigned char *,
  296. int, FILE *);
  297. const unsigned char * p_cdname(const unsigned char *, const unsigned char *,
  298. FILE *);
  299. const unsigned char * p_fqnname(const unsigned char *, const unsigned char *,
  300. int, char *, int);
  301. const unsigned char * p_fqname(const unsigned char *, const unsigned char *,
  302. FILE *);
  303. const unsigned char * p_rr(const unsigned char *, const unsigned char *,
  304. FILE *);
  305. const char * p_option(unsigned long);
  306. char * p_secstodate(unsigned long);
  307. int dn_count_labels(char *);
  308. int dn_comp(const char *, unsigned char *, int,
  309. unsigned char **, unsigned char **);
  310. int dn_expand(const unsigned char *, const unsigned char *,
  311. const unsigned char *, char *, int);
  312. int res_init(void);
  313. int _res_init(int);
  314. unsigned int res_randomid(void);
  315. int res_query(const char *, int, int, unsigned char *, int)
  316. __attribute__((__bounded__(__string__,4,5)));
  317. int res_search(const char *, int, int, unsigned char *, int)
  318. __attribute__((__bounded__(__string__,4,5)));
  319. int res_querydomain(const char *, const char *, int, int,
  320. unsigned char *, int)
  321. __attribute__((__bounded__(__string__,5,6)));
  322. int res_mkquery(int, const char *, int, int,
  323. const unsigned char *, int, const unsigned char *,
  324. unsigned char *, int)
  325. __attribute__((__bounded__(__string__,5,6)))
  326. __attribute__((__bounded__(__string__,8,9)));
  327. int res_send(const unsigned char *, int, unsigned char *,
  328. int)
  329. __attribute__((__bounded__(__string__,3,4)));
  330. int res_isourserver(const struct sockaddr_in *);
  331. int res_nameinquery(const char *, int, int,
  332. const unsigned char *, const unsigned char *);
  333. int res_queriesmatch(const unsigned char *,
  334. const unsigned char *, const unsigned char *,
  335. const unsigned char *);
  336. void res_close(void);
  337. __END_DECLS
  338. #endif /* !_RESOLV_H_ */