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.

332 lines
12 KiB

  1. /* $OpenBSD: netdb.h,v 1.27 2009/06/02 16:47:50 jasper Exp $ */
  2. /*
  3. * ++Copyright++ 1980, 1983, 1988, 1993
  4. * -
  5. * Copyright (c) 1980, 1983, 1988, 1993
  6. * The Regents of the University of California. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the University nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. * -
  32. * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  33. *
  34. * Permission to use, copy, modify, and distribute this software for any
  35. * purpose with or without fee is hereby granted, provided that the above
  36. * copyright notice and this permission notice appear in all copies, and that
  37. * the name of Digital Equipment Corporation not be used in advertising or
  38. * publicity pertaining to distribution of the document or software without
  39. * specific, written prior permission.
  40. *
  41. * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  42. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  43. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  44. * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  45. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  46. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  47. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  48. * SOFTWARE.
  49. * -
  50. * --Copyright--
  51. */
  52. /*
  53. * Copyright (c) 1995, 1996, 1997, 1998, 1999 Craig Metz. All rights reserved.
  54. *
  55. * Redistribution and use in source and binary forms, with or without
  56. * modification, are permitted provided that the following conditions
  57. * are met:
  58. * 1. Redistributions of source code must retain the above copyright
  59. * notice, this list of conditions and the following disclaimer.
  60. * 2. Redistributions in binary form must reproduce the above copyright
  61. * notice, this list of conditions and the following disclaimer in the
  62. * documentation and/or other materials provided with the distribution.
  63. * 3. Neither the name of the author nor the names of any contributors
  64. * may be used to endorse or promote products derived from this software
  65. * without specific prior written permission.
  66. *
  67. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  68. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  71. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  72. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  73. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  74. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  77. * SUCH DAMAGE.
  78. */
  79. /*
  80. * @(#)netdb.h 8.1 (Berkeley) 6/2/93
  81. * $From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $
  82. */
  83. #ifndef _NETDB_H_
  84. #define _NETDB_H_
  85. #include <sys/param.h>
  86. #include <sys/cdefs.h>
  87. #define _PATH_HEQUIV "/etc/hosts.equiv"
  88. #define _PATH_HOSTS "/etc/hosts"
  89. #define _PATH_NETWORKS "/etc/networks"
  90. #define _PATH_PROTOCOLS "/etc/protocols"
  91. #define _PATH_SERVICES "/etc/services"
  92. extern int h_errno;
  93. /*
  94. * Structures returned by network data base library. All addresses are
  95. * supplied in host order, and returned in network order (suitable for
  96. * use in system calls).
  97. */
  98. struct hostent {
  99. char *h_name; /* official name of host */
  100. char **h_aliases; /* alias list */
  101. int h_addrtype; /* host address type */
  102. int h_length; /* length of address */
  103. char **h_addr_list; /* list of addresses from name server */
  104. #define h_addr h_addr_list[0] /* address, for backward compatibility */
  105. };
  106. /*
  107. * Assumption here is that a network number
  108. * fits in an in_addr_t -- probably a poor one.
  109. */
  110. struct netent {
  111. char *n_name; /* official name of net */
  112. char **n_aliases; /* alias list */
  113. int n_addrtype; /* net address type */
  114. in_addr_t n_net; /* network # */
  115. };
  116. struct servent {
  117. char *s_name; /* official service name */
  118. char **s_aliases; /* alias list */
  119. int s_port; /* port # */
  120. char *s_proto; /* protocol to use */
  121. };
  122. struct protoent {
  123. char *p_name; /* official protocol name */
  124. char **p_aliases; /* alias list */
  125. int p_proto; /* protocol # */
  126. };
  127. /*
  128. * Error return codes from gethostbyname() and gethostbyaddr()
  129. * (left in extern int h_errno).
  130. */
  131. #define NETDB_INTERNAL -1 /* see errno */
  132. #define NETDB_SUCCESS 0 /* no problem */
  133. #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
  134. #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
  135. #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  136. #define NO_DATA 4 /* Valid name, no data record of requested type */
  137. #define NO_ADDRESS NO_DATA /* no address */
  138. /* Values for getaddrinfo() and getnameinfo() */
  139. #define AI_PASSIVE 1 /* socket address is intended for bind() */
  140. #define AI_CANONNAME 2 /* request for canonical name */
  141. #define AI_NUMERICHOST 4 /* don't ever try hostname lookup */
  142. #define AI_EXT 8 /* enable non-portable extensions */
  143. #define AI_NUMERICSERV 16 /* don't ever try servname lookup */
  144. /* valid flags for addrinfo */
  145. #define AI_MASK \
  146. (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
  147. #define NI_NUMERICHOST 1 /* return the host address, not the name */
  148. #define NI_NUMERICSERV 2 /* return the service address, not the name */
  149. #define NI_NOFQDN 4 /* return a short name if in the local domain */
  150. #define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
  151. #define NI_DGRAM 16 /* look up datagram service instead of stream */
  152. #define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
  153. #define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
  154. /*
  155. * Scope delimit character (KAME hack)
  156. */
  157. #define SCOPE_DELIMITER '%'
  158. #define EAI_BADFLAGS -1 /* invalid value for ai_flags */
  159. #define EAI_NONAME -2 /* name or service is not known */
  160. #define EAI_AGAIN -3 /* temporary failure in name resolution */
  161. #define EAI_FAIL -4 /* non-recoverable failure in name resolution */
  162. #define EAI_NODATA -5 /* no address associated with name */
  163. #define EAI_FAMILY -6 /* ai_family not supported */
  164. #define EAI_SOCKTYPE -7 /* ai_socktype not supported */
  165. #define EAI_SERVICE -8 /* service not supported for ai_socktype */
  166. #define EAI_ADDRFAMILY -9 /* address family for name not supported */
  167. #define EAI_MEMORY -10 /* memory allocation failure */
  168. #define EAI_SYSTEM -11 /* system error (code indicated in errno) */
  169. #define EAI_BADHINTS -12 /* invalid value for hints */
  170. #define EAI_PROTOCOL -13 /* resolved protocol is unknown */
  171. #define EAI_OVERFLOW -14 /* argument buffer overflow */
  172. struct addrinfo {
  173. int ai_flags; /* input flags */
  174. int ai_family; /* protocol family for socket */
  175. int ai_socktype; /* socket type */
  176. int ai_protocol; /* protocol for socket */
  177. socklen_t ai_addrlen; /* length of socket-address */
  178. struct sockaddr *ai_addr; /* socket-address for socket */
  179. char *ai_canonname; /* canonical name for service location (iff req) */
  180. struct addrinfo *ai_next; /* pointer to next in list */
  181. };
  182. /*
  183. * Flags for getrrsetbyname()
  184. */
  185. #define RRSET_VALIDATED 1
  186. /*
  187. * Return codes for getrrsetbyname()
  188. */
  189. #define ERRSET_SUCCESS 0
  190. #define ERRSET_NOMEMORY 1
  191. #define ERRSET_FAIL 2
  192. #define ERRSET_INVAL 3
  193. #define ERRSET_NONAME 4
  194. #define ERRSET_NODATA 5
  195. /*
  196. * Structures used by getrrsetbyname() and freerrset()
  197. */
  198. struct rdatainfo {
  199. unsigned int rdi_length; /* length of data */
  200. unsigned char *rdi_data; /* record data */
  201. };
  202. struct rrsetinfo {
  203. unsigned int rri_flags; /* RRSET_VALIDATED ... */
  204. unsigned int rri_rdclass; /* class number */
  205. unsigned int rri_rdtype; /* RR type number */
  206. unsigned int rri_ttl; /* time to live */
  207. unsigned int rri_nrdatas; /* size of rdatas array */
  208. unsigned int rri_nsigs; /* size of sigs array */
  209. char *rri_name; /* canonical name */
  210. struct rdatainfo *rri_rdatas; /* individual records */
  211. struct rdatainfo *rri_sigs; /* individual signatures */
  212. };
  213. #if __BSD_VISIBLE
  214. struct servent_data {
  215. void *fp;
  216. char **aliases;
  217. int maxaliases;
  218. int stayopen;
  219. char *line;
  220. };
  221. struct protoent_data {
  222. void *fp;
  223. char **aliases;
  224. int maxaliases;
  225. int stayopen;
  226. char *line;
  227. };
  228. #endif
  229. __BEGIN_DECLS
  230. void endhostent(void);
  231. void endnetent(void);
  232. void endprotoent(void);
  233. #if __BSD_VISIBLE
  234. void endprotoent_r(struct protoent_data *);
  235. #endif
  236. void endservent(void);
  237. #if __BSD_VISIBLE
  238. void endservent_r(struct servent_data *);
  239. #endif
  240. struct hostent *gethostbyaddr(const void *, socklen_t, int);
  241. struct hostent *gethostbyname(const char *);
  242. struct hostent *gethostbyname2(const char *, int);
  243. struct hostent *gethostent(void);
  244. struct netent *getnetbyaddr(in_addr_t, int);
  245. struct netent *getnetbyname(const char *);
  246. struct netent *getnetent(void);
  247. struct protoent *getprotobyname(const char *);
  248. struct protoent *getprotobynumber(int);
  249. struct protoent *getprotoent(void);
  250. #if __BSD_VISIBLE
  251. int getprotobyname_r(const char *, struct protoent *,
  252. struct protoent_data *);
  253. int getprotobynumber_r(int, struct protoent *,
  254. struct protoent_data *);
  255. int getprotoent_r(struct protoent *, struct protoent_data *);
  256. #endif
  257. struct servent *getservbyname(const char *, const char *);
  258. struct servent *getservbyport(int, const char *);
  259. struct servent *getservent(void);
  260. #if __BSD_VISIBLE
  261. int getservbyname_r(const char *, const char *, struct servent *,
  262. struct servent_data *);
  263. int getservbyport_r(int, const char *, struct servent *,
  264. struct servent_data *);
  265. int getservent_r(struct servent *, struct servent_data *);
  266. #endif
  267. void herror(const char *);
  268. const char *hstrerror(int);
  269. void sethostent(int);
  270. /* void sethostfile(const char *); */
  271. void setnetent(int);
  272. void setprotoent(int);
  273. #if __BSD_VISIBLE
  274. void setprotoent_r(int, struct protoent_data *);
  275. #endif
  276. void setservent(int);
  277. #if __BSD_VISIBLE
  278. void setservent_r(int, struct servent_data *);
  279. #endif
  280. int getaddrinfo(const char *, const char *,
  281. const struct addrinfo *, struct addrinfo **);
  282. void freeaddrinfo(struct addrinfo *);
  283. int getnameinfo(const struct sockaddr *, socklen_t,
  284. char *, size_t, char *, size_t, int);
  285. const char *gai_strerror(int);
  286. int net_addrcmp(struct sockaddr *, struct sockaddr *);
  287. int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
  288. void freerrset(struct rrsetinfo *);
  289. __END_DECLS
  290. /* This is nec'y to make this include file properly replace the sun version. */
  291. #ifdef sun
  292. #ifdef __GNU_LIBRARY__
  293. #include <rpc/netdb.h>
  294. #else
  295. struct rpcent {
  296. char *r_name; /* name of server for this rpc program */
  297. char **r_aliases; /* alias list */
  298. int r_number; /* rpc program number */
  299. };
  300. struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
  301. #endif /* __GNU_LIBRARY__ */
  302. #endif /* sun */
  303. #endif /* !_NETDB_H_ */