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.

334 lines
12 KiB

  1. /* $OpenBSD: netdb.h,v 1.32 2014/04/28 21:38:59 sperreault 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/cdefs.h>
  86. #if __BSD_VISIBLE
  87. #include <sys/param.h>
  88. #endif
  89. #include <netinet/in.h>
  90. #ifndef _SOCKLEN_T_DEFINED_
  91. #define _SOCKLEN_T_DEFINED_
  92. typedef __socklen_t socklen_t; /* length type for network syscalls */
  93. #endif
  94. #define _PATH_HEQUIV "/etc/hosts.equiv"
  95. #define _PATH_HOSTS "/etc/hosts"
  96. #define _PATH_NETWORKS "/etc/networks"
  97. #define _PATH_PROTOCOLS "/etc/protocols"
  98. #define _PATH_SERVICES "/etc/services"
  99. /*
  100. * Structures returned by network data base library. All addresses are
  101. * supplied in host order, and returned in network order (suitable for
  102. * use in system calls).
  103. */
  104. struct hostent {
  105. char *h_name; /* official name of host */
  106. char **h_aliases; /* alias list */
  107. int h_addrtype; /* host address type */
  108. int h_length; /* length of address */
  109. char **h_addr_list; /* list of addresses from name server */
  110. #define h_addr h_addr_list[0] /* address, for backward compatibility */
  111. };
  112. /*
  113. * Assumption here is that a network number
  114. * fits in an in_addr_t -- probably a poor one.
  115. */
  116. struct netent {
  117. char *n_name; /* official name of net */
  118. char **n_aliases; /* alias list */
  119. int n_addrtype; /* net address type */
  120. in_addr_t n_net; /* network # */
  121. };
  122. struct servent {
  123. char *s_name; /* official service name */
  124. char **s_aliases; /* alias list */
  125. int s_port; /* port # */
  126. char *s_proto; /* protocol to use */
  127. };
  128. struct protoent {
  129. char *p_name; /* official protocol name */
  130. char **p_aliases; /* alias list */
  131. int p_proto; /* protocol # */
  132. };
  133. #if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
  134. extern int h_errno;
  135. /*
  136. * Error return codes from gethostbyname() and gethostbyaddr()
  137. * (left in extern int h_errno).
  138. */
  139. #define NETDB_INTERNAL -1 /* see errno */
  140. #define NETDB_SUCCESS 0 /* no problem */
  141. #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
  142. #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
  143. #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  144. #define NO_DATA 4 /* Valid name, no data record of requested type */
  145. #define NO_ADDRESS NO_DATA /* no address */
  146. #endif /* __BSD_VISIBLE || __POSIX_VISIBLE < 200809 */
  147. /* Values for getaddrinfo() and getnameinfo() */
  148. #define AI_PASSIVE 1 /* socket address is intended for bind() */
  149. #define AI_CANONNAME 2 /* request for canonical name */
  150. #define AI_NUMERICHOST 4 /* don't ever try hostname lookup */
  151. #define AI_EXT 8 /* enable non-portable extensions */
  152. #define AI_NUMERICSERV 16 /* don't ever try servname lookup */
  153. #define AI_FQDN 32 /* return the FQDN that was resolved */
  154. #define AI_ADDRCONFIG 64 /* return configured address families only */
  155. /* valid flags for addrinfo */
  156. #define AI_MASK \
  157. (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN | \
  158. AI_ADDRCONFIG)
  159. #define NI_NUMERICHOST 1 /* return the host address, not the name */
  160. #define NI_NUMERICSERV 2 /* return the service address, not the name */
  161. #define NI_NOFQDN 4 /* return a short name if in the local domain */
  162. #define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
  163. #define NI_DGRAM 16 /* look up datagram service instead of stream */
  164. /* #define NI_NUMERICSCOPE 32 return the scope number, not the name */
  165. #if __BSD_VISIBLE
  166. #define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
  167. #define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
  168. /*
  169. * Scope delimit character (KAME hack)
  170. */
  171. #define SCOPE_DELIMITER '%'
  172. #endif
  173. #define EAI_BADFLAGS -1 /* invalid value for ai_flags */
  174. #define EAI_NONAME -2 /* name or service is not known */
  175. #define EAI_AGAIN -3 /* temporary failure in name resolution */
  176. #define EAI_FAIL -4 /* non-recoverable failure in name resolution */
  177. #define EAI_NODATA -5 /* no address associated with name */
  178. #define EAI_FAMILY -6 /* ai_family not supported */
  179. #define EAI_SOCKTYPE -7 /* ai_socktype not supported */
  180. #define EAI_SERVICE -8 /* service not supported for ai_socktype */
  181. #define EAI_ADDRFAMILY -9 /* address family for name not supported */
  182. #define EAI_MEMORY -10 /* memory allocation failure */
  183. #define EAI_SYSTEM -11 /* system error (code indicated in errno) */
  184. #define EAI_BADHINTS -12 /* invalid value for hints */
  185. #define EAI_PROTOCOL -13 /* resolved protocol is unknown */
  186. #define EAI_OVERFLOW -14 /* argument buffer overflow */
  187. struct addrinfo {
  188. int ai_flags; /* input flags */
  189. int ai_family; /* protocol family for socket */
  190. int ai_socktype; /* socket type */
  191. int ai_protocol; /* protocol for socket */
  192. socklen_t ai_addrlen; /* length of socket-address */
  193. struct sockaddr *ai_addr; /* socket-address for socket */
  194. char *ai_canonname; /* canonical name for service location (iff req) */
  195. struct addrinfo *ai_next; /* pointer to next in list */
  196. };
  197. #if __BSD_VISIBLE
  198. /*
  199. * Flags for getrrsetbyname()
  200. */
  201. #define RRSET_VALIDATED 1
  202. /*
  203. * Return codes for getrrsetbyname()
  204. */
  205. #define ERRSET_SUCCESS 0
  206. #define ERRSET_NOMEMORY 1
  207. #define ERRSET_FAIL 2
  208. #define ERRSET_INVAL 3
  209. #define ERRSET_NONAME 4
  210. #define ERRSET_NODATA 5
  211. /*
  212. * Structures used by getrrsetbyname() and freerrset()
  213. */
  214. struct rdatainfo {
  215. unsigned int rdi_length; /* length of data */
  216. unsigned char *rdi_data; /* record data */
  217. };
  218. struct rrsetinfo {
  219. unsigned int rri_flags; /* RRSET_VALIDATED ... */
  220. unsigned int rri_rdclass; /* class number */
  221. unsigned int rri_rdtype; /* RR type number */
  222. unsigned int rri_ttl; /* time to live */
  223. unsigned int rri_nrdatas; /* size of rdatas array */
  224. unsigned int rri_nsigs; /* size of sigs array */
  225. char *rri_name; /* canonical name */
  226. struct rdatainfo *rri_rdatas; /* individual records */
  227. struct rdatainfo *rri_sigs; /* individual signatures */
  228. };
  229. struct servent_data {
  230. void *fp;
  231. char **aliases;
  232. int maxaliases;
  233. int stayopen;
  234. char *line;
  235. };
  236. struct protoent_data {
  237. void *fp;
  238. char **aliases;
  239. int maxaliases;
  240. int stayopen;
  241. char *line;
  242. };
  243. #endif
  244. __BEGIN_DECLS
  245. void endhostent(void);
  246. void endnetent(void);
  247. void endprotoent(void);
  248. void endservent(void);
  249. #if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
  250. struct hostent *gethostbyaddr(const void *, socklen_t, int);
  251. struct hostent *gethostbyname(const char *);
  252. #endif
  253. #if __BSD_VISIBLE
  254. struct hostent *gethostbyname2(const char *, int);
  255. #endif
  256. struct hostent *gethostent(void);
  257. struct netent *getnetbyaddr(in_addr_t, int);
  258. struct netent *getnetbyname(const char *);
  259. struct netent *getnetent(void);
  260. struct protoent *getprotobyname(const char *);
  261. struct protoent *getprotobynumber(int);
  262. struct protoent *getprotoent(void);
  263. struct servent *getservbyname(const char *, const char *);
  264. struct servent *getservbyport(int, const char *);
  265. struct servent *getservent(void);
  266. #if __BSD_VISIBLE
  267. void herror(const char *);
  268. const char *hstrerror(int);
  269. #endif
  270. void sethostent(int);
  271. /* void sethostfile(const char *); */
  272. void setnetent(int);
  273. void setprotoent(int);
  274. void setservent(int);
  275. #if __BSD_VISIBLE
  276. void endprotoent_r(struct protoent_data *);
  277. void endservent_r(struct servent_data *);
  278. int getprotobyname_r(const char *, struct protoent *,
  279. struct protoent_data *);
  280. int getprotobynumber_r(int, struct protoent *,
  281. struct protoent_data *);
  282. int getservbyname_r(const char *, const char *, struct servent *,
  283. struct servent_data *);
  284. int getservbyport_r(int, const char *, struct servent *,
  285. struct servent_data *);
  286. int getservent_r(struct servent *, struct servent_data *);
  287. int getprotoent_r(struct protoent *, struct protoent_data *);
  288. void setprotoent_r(int, struct protoent_data *);
  289. void setservent_r(int, struct servent_data *);
  290. #endif
  291. int getaddrinfo(const char *, const char *,
  292. const struct addrinfo *, struct addrinfo **);
  293. void freeaddrinfo(struct addrinfo *);
  294. int getnameinfo(const struct sockaddr *, socklen_t,
  295. char *, size_t, char *, size_t, int);
  296. const char *gai_strerror(int);
  297. #if __BSD_VISIBLE
  298. int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
  299. void freerrset(struct rrsetinfo *);
  300. #endif
  301. __END_DECLS
  302. #endif /* !_NETDB_H_ */