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.

329 lines
12 KiB

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