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