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.

238 lines
9.3 KiB

  1. /* $OpenBSD: netdb.h,v 1.10 2000/05/15 10:50:39 itojun 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. All advertising materials mentioning features or use of this software
  17. * must display the following acknowledgement:
  18. * This product includes software developed by the University of
  19. * California, Berkeley and its contributors.
  20. * 4. Neither the name of the University nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. * -
  36. * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  37. *
  38. * Permission to use, copy, modify, and distribute this software for any
  39. * purpose with or without fee is hereby granted, provided that the above
  40. * copyright notice and this permission notice appear in all copies, and that
  41. * the name of Digital Equipment Corporation not be used in advertising or
  42. * publicity pertaining to distribution of the document or software without
  43. * specific, written prior permission.
  44. *
  45. * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  46. * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  47. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
  48. * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  49. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  50. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  51. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  52. * SOFTWARE.
  53. * -
  54. * --Copyright--
  55. */
  56. /*
  57. * %%% portions-copyright-cmetz-96
  58. * Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
  59. * Reserved. The Inner Net License Version 2 applies to these portions of
  60. * the software.
  61. * You should have received a copy of the license with this software. If
  62. * you didn't get a copy, you may request one from <license@inner.net>.
  63. */
  64. /*
  65. * @(#)netdb.h 8.1 (Berkeley) 6/2/93
  66. * $From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $
  67. */
  68. #ifndef _NETDB_H_
  69. #define _NETDB_H_
  70. #include <sys/param.h>
  71. #if (!defined(BSD)) || (BSD < 199306)
  72. # include <sys/bitypes.h>
  73. #endif
  74. #include <sys/cdefs.h>
  75. #define _PATH_HEQUIV "/etc/hosts.equiv"
  76. #define _PATH_HOSTS "/etc/hosts"
  77. #define _PATH_NETWORKS "/etc/networks"
  78. #define _PATH_PROTOCOLS "/etc/protocols"
  79. #define _PATH_SERVICES "/etc/services"
  80. extern int h_errno;
  81. /*
  82. * Structures returned by network data base library. All addresses are
  83. * supplied in host order, and returned in network order (suitable for
  84. * use in system calls).
  85. */
  86. struct hostent {
  87. char *h_name; /* official name of host */
  88. char **h_aliases; /* alias list */
  89. int h_addrtype; /* host address type */
  90. int h_length; /* length of address */
  91. char **h_addr_list; /* list of addresses from name server */
  92. #define h_addr h_addr_list[0] /* address, for backward compatiblity */
  93. };
  94. /*
  95. * Assumption here is that a network number
  96. * fits in an in_addr_t -- probably a poor one.
  97. */
  98. struct netent {
  99. char *n_name; /* official name of net */
  100. char **n_aliases; /* alias list */
  101. int n_addrtype; /* net address type */
  102. in_addr_t n_net; /* network # */
  103. };
  104. struct servent {
  105. char *s_name; /* official service name */
  106. char **s_aliases; /* alias list */
  107. int s_port; /* port # */
  108. char *s_proto; /* protocol to use */
  109. };
  110. struct protoent {
  111. char *p_name; /* official protocol name */
  112. char **p_aliases; /* alias list */
  113. int p_proto; /* protocol # */
  114. };
  115. /*
  116. * Error return codes from gethostbyname() and gethostbyaddr()
  117. * (left in extern int h_errno).
  118. */
  119. #define NETDB_INTERNAL -1 /* see errno */
  120. #define NETDB_SUCCESS 0 /* no problem */
  121. #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
  122. #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
  123. #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  124. #define NO_DATA 4 /* Valid name, no data record of requested type */
  125. #define NO_ADDRESS NO_DATA /* no address, look for MX record */
  126. /* Values for getaddrinfo() and getnameinfo() */
  127. #define AI_PASSIVE 1 /* socket address is intended for bind() */
  128. #define AI_CANONNAME 2 /* request for canonical name */
  129. #define AI_NUMERICHOST 4 /* don't ever try nameservice */
  130. #define AI_EXT 8 /* enable non-portable extensions */
  131. /* valid flags for addrinfo */
  132. #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
  133. #define NI_NUMERICHOST 1 /* return the host address, not the name */
  134. #define NI_NUMERICSERV 2 /* return the service address, not the name */
  135. #define NI_NOFQDN 4 /* return a short name if in the local domain */
  136. #define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
  137. #define NI_DGRAM 16 /* look up datagram service instead of stream */
  138. #define NI_WITHSCOPEID 32 /* KAME hack: attach scopeid to host portion */
  139. #define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
  140. #define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
  141. /*
  142. * Scope delimit character (KAME hack)
  143. */
  144. #define SCOPE_DELIMITER '%'
  145. #define EAI_BADFLAGS -1 /* invalid value for ai_flags */
  146. #define EAI_NONAME -2 /* name or service is not known */
  147. #define EAI_AGAIN -3 /* temporary failure in name resolution */
  148. #define EAI_FAIL -4 /* non-recoverable failure in name resolution */
  149. #define EAI_NODATA -5 /* no address associated with name */
  150. #define EAI_FAMILY -6 /* ai_family not supported */
  151. #define EAI_SOCKTYPE -7 /* ai_socktype not supported */
  152. #define EAI_SERVICE -8 /* service not supported for ai_socktype */
  153. #define EAI_ADDRFAMILY -9 /* address family for name not supported */
  154. #define EAI_MEMORY -10 /* memory allocation failure */
  155. #define EAI_SYSTEM -11 /* system error (code indicated in errno) */
  156. #define EAI_BADHINTS -12 /* invalid value for hints */
  157. #define EAI_PROTOCOL -13 /* resolved protocol is unknown */
  158. struct addrinfo {
  159. int ai_flags; /* input flags */
  160. int ai_family; /* protocol family for socket */
  161. int ai_socktype; /* socket type */
  162. int ai_protocol; /* protocol for socket */
  163. int ai_addrlen; /* length of socket-address */
  164. struct sockaddr *ai_addr; /* socket-address for socket */
  165. char *ai_canonname; /* canonical name for service location (iff req) */
  166. struct addrinfo *ai_next; /* pointer to next in list */
  167. };
  168. __BEGIN_DECLS
  169. void endhostent __P((void));
  170. void endnetent __P((void));
  171. void endprotoent __P((void));
  172. void endservent __P((void));
  173. struct hostent *gethostbyaddr __P((const char *, int, int));
  174. struct hostent *gethostbyname __P((const char *));
  175. struct hostent *gethostbyname2 __P((const char *, int));
  176. struct hostent *gethostent __P((void));
  177. struct netent *getnetbyaddr __P((in_addr_t, int));
  178. struct netent *getnetbyname __P((const char *));
  179. struct netent *getnetent __P((void));
  180. struct protoent *getprotobyname __P((const char *));
  181. struct protoent *getprotobynumber __P((int));
  182. struct protoent *getprotoent __P((void));
  183. struct servent *getservbyname __P((const char *, const char *));
  184. struct servent *getservbyport __P((int, const char *));
  185. struct servent *getservent __P((void));
  186. void herror __P((const char *));
  187. const char *hstrerror __P((int));
  188. void sethostent __P((int));
  189. /* void sethostfile __P((const char *)); */
  190. void setnetent __P((int));
  191. void setprotoent __P((int));
  192. void setservent __P((int));
  193. int getaddrinfo __P((const char *name, const char *service,
  194. const struct addrinfo *req, struct addrinfo **pai));
  195. void freeaddrinfo __P((struct addrinfo *ai));
  196. int getnameinfo __P((const struct sockaddr *sa, socklen_t addrlen,
  197. char *host, size_t hostlen, char *serv, size_t servlen,
  198. int flags));
  199. char *gai_strerror __P((int ecode));
  200. int net_addrcmp __P((struct sockaddr *, struct sockaddr *));
  201. __END_DECLS
  202. /* This is nec'y to make this include file properly replace the sun version. */
  203. #ifdef sun
  204. #ifdef __GNU_LIBRARY__
  205. #include <rpc/netdb.h>
  206. #else
  207. struct rpcent {
  208. char *r_name; /* name of server for this rpc program */
  209. char **r_aliases; /* alias list */
  210. int r_number; /* rpc program number */
  211. };
  212. struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
  213. #endif /* __GNU_LIBRARY__ */
  214. #endif /* sun */
  215. #endif /* !_NETDB_H_ */