1 /* 2 * Copyright 2002-2009, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 /* 7 * Copyright (c) 1980, 1983, 1988, 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * - 38 * Portions Copyright (c) 1993 by Digital Equipment Corporation. 39 * 40 * Permission to use, copy, modify, and distribute this software for any 41 * purpose with or without fee is hereby granted, provided that the above 42 * copyright notice and this permission notice appear in all copies, and that 43 * the name of Digital Equipment Corporation not be used in advertising or 44 * publicity pertaining to distribution of the document or software without 45 * specific, written prior permission. 46 * 47 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 48 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 49 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 50 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 51 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 52 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 53 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 54 * SOFTWARE. 55 * - 56 * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 57 * All rights reserved. 58 * 59 * Redistribution and use in source and binary forms, with or without 60 * modification, are permitted provided that the following conditions 61 * are met: 62 * 1. Redistributions of source code must retain the above copyright 63 * notice, this list of conditions and the following disclaimer. 64 * 2. Redistributions in binary form must reproduce the above copyright 65 * notice, this list of conditions and the following disclaimer in the 66 * documentation and/or other materials provided with the distribution. 67 * 3. All advertising materials mentioning features or use of this software 68 * must display the following acknowledgement: 69 * This product includes software developed by WIDE Project and 70 * its contributors. 71 * 4. Neither the name of the project nor the names of its contributors 72 * may be used to endorse or promote products derived from this software 73 * without specific prior written permission. 74 * 75 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 76 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 77 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 78 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 79 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 80 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 81 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 82 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 83 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 84 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 85 * SUCH DAMAGE. 86 */ 87 #ifndef _NETDB_H_ 88 #define _NETDB_H_ 89 90 #include <sys/param.h> 91 #include <sys/types.h> 92 #include <sys/cdefs.h> 93 #include <sys/socket.h> 94 #include <netinet/in.h> 95 #include <stdio.h> 96 97 #ifndef _PATH_HEQUIV 98 #define _PATH_HEQUIV "/etc/hosts.equiv" 99 #endif 100 #ifndef _PATH_HOSTS 101 #define _PATH_HOSTS "/etc/hosts" 102 #endif 103 #ifndef _PATH_NETWORKS 104 #define _PATH_NETWORKS "/etc/networks" 105 #endif 106 #ifndef _PATH_PROTOCOLS 107 #define _PATH_PROTOCOLS "/etc/protocols" 108 #endif 109 #ifndef _PATH_SERVICES 110 #define _PATH_SERVICES "/etc/services" 111 #endif 112 113 __BEGIN_DECLS 114 extern int * __h_errno(void); 115 __END_DECLS 116 #define h_errno (*__h_errno()) 117 118 /* 119 * Structures returned by network data base library. All addresses are 120 * supplied in host order, and returned in network order (suitable for 121 * use in system calls). 122 */ 123 struct hostent { 124 char *h_name; /* official name of host */ 125 char **h_aliases; /* alias list */ 126 int h_addrtype; /* host address type */ 127 int h_length; /* length of address */ 128 char **h_addr_list; /* list of addresses from name server */ 129 #define h_addr h_addr_list[0] /* address, for backward compatiblity */ 130 }; 131 132 /* 133 * Assumption here is that a network number 134 * fits in an unsigned long -- probably a poor one. 135 */ 136 struct netent { 137 char *n_name; /* official name of net */ 138 char **n_aliases; /* alias list */ 139 int n_addrtype; /* net address type */ 140 unsigned long n_net; /* network # */ 141 }; 142 143 struct servent { 144 char *s_name; /* official service name */ 145 char **s_aliases; /* alias list */ 146 int s_port; /* port # */ 147 char *s_proto; /* protocol to use */ 148 }; 149 150 struct protoent { 151 char *p_name; /* official protocol name */ 152 char **p_aliases; /* alias list */ 153 int p_proto; /* protocol # */ 154 }; 155 156 struct addrinfo { 157 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 158 int ai_family; /* PF_xxx */ 159 int ai_socktype; /* SOCK_xxx */ 160 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 161 size_t ai_addrlen; /* length of ai_addr */ 162 char *ai_canonname; /* canonical name for hostname */ 163 struct sockaddr *ai_addr; /* binary address */ 164 struct addrinfo *ai_next; /* next structure in linked list */ 165 }; 166 167 /* 168 * Error return codes from gethostbyname() and gethostbyaddr() 169 * (left in extern int h_errno). 170 */ 171 #define NETDB_INTERNAL -1 /* see errno */ 172 #define NETDB_SUCCESS 0 /* no problem */ 173 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 174 #define TRY_AGAIN 2 175 /* Non-Authoritive Host not found, or SERVERFAIL */ 176 #define NO_RECOVERY 3 177 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 178 #define NO_DATA 4 179 /* Valid name, no data record of requested type */ 180 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 181 182 /* 183 * Error return codes from getaddrinfo() 184 */ 185 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 186 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 187 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 188 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 189 #define EAI_FAMILY 5 /* ai_family not supported */ 190 #define EAI_MEMORY 6 /* memory allocation failure */ 191 #define EAI_NODATA 7 /* no address associated with hostname */ 192 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 193 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 194 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 195 #define EAI_SYSTEM 11 /* system error returned in errno */ 196 #define EAI_BADHINTS 12 197 #define EAI_PROTOCOL 13 198 #define EAI_MAX 14 199 200 /* 201 * Flag values for getaddrinfo() 202 */ 203 #define AI_PASSIVE 0x00000001 204 #define AI_CANONNAME 0x00000002 205 #define AI_NUMERICHOST 0x00000004 206 #define AI_MASK 0x00000007 207 208 /* 209 * Flag values for getipnodebyname() 210 */ 211 #define AI_V4MAPPED 0x00000008 212 #define AI_ALL 0x00000010 213 #define AI_ADDRCONFIG 0x00000020 214 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) 215 216 /* 217 * Constants for getnameinfo() 218 */ 219 #define NI_MAXHOST 1025 220 #define NI_MAXSERV 32 221 222 /* 223 * Flag values for getnameinfo() 224 */ 225 #define NI_NOFQDN 0x00000001 226 #define NI_NUMERICHOST 0x00000002 227 #define NI_NAMEREQD 0x00000004 228 #define NI_NUMERICSERV 0x00000008 229 #define NI_DGRAM 0x00000010 230 #define NI_WITHSCOPEID 0x00000020 231 #define NI_NUMERICSCOPE 0x00000040 232 233 /* 234 * Scope delimit character 235 */ 236 #define SCOPE_DELIMITER '%' 237 238 239 __BEGIN_DECLS 240 void endhostent(void); 241 void endnetent(void); 242 void endprotoent(void); 243 void endservent(void); 244 void freehostent(struct hostent *host); 245 struct hostent *gethostbyaddr(const char *address, int length, int type); 246 struct hostent *gethostbyname(const char *name); 247 struct hostent *gethostbyname2(const char *name, int type); 248 struct hostent *gethostent(void); 249 struct hostent *getipnodebyaddr(const void *, size_t, int, int *); 250 struct hostent *getipnodebyname(const char *, int, int, int *); 251 struct netent *getnetbyaddr(unsigned long, int); 252 struct netent *getnetbyname(const char *); 253 struct netent *getnetent(void); 254 struct protoent *getprotobyname(const char *); 255 struct protoent *getprotobynumber(int); 256 struct protoent *getprotoent(void); 257 struct servent *getservbyname(const char *, const char *); 258 struct servent *getservbyport(int, const char *); 259 struct servent *getservent(void); 260 void herror(const char *); 261 const char *hstrerror(int); 262 void sethostent(int); 263 /* void sethostfile(const char *); */ 264 void setnetent(int); 265 void setprotoent(int); 266 void setservent(int); 267 int getaddrinfo(const char *, const char *, 268 const struct addrinfo *, struct addrinfo **); 269 int getnameinfo(const struct sockaddr *, socklen_t, char *, 270 socklen_t, char *, socklen_t, int); 271 void freeaddrinfo(struct addrinfo *); 272 const char *gai_strerror(int); 273 274 struct hostent *gethostbyaddr_r(const char *, int, int, struct hostent *, 275 char *, int, int *); 276 struct hostent *gethostbyname_r(const char *, struct hostent *, 277 char *, int, int *); 278 struct hostent *gethostent_r(struct hostent *, char *, int, int *); 279 void sethostent_r(int); 280 void endhostent_r(void); 281 282 struct netent *getnetbyname_r(const char *, struct netent *, 283 char *, int); 284 struct netent *getnetbyaddr_r(long, int, struct netent *, 285 char *, int); 286 struct netent *getnetent_r(struct netent *, char *, int); 287 void setnetent_r(int); 288 void endnetent_r(void); 289 290 struct protoent *getprotobyname_r(const char *, 291 struct protoent *, char *, int); 292 struct protoent *getprotobynumber_r(int, 293 struct protoent *, char *, int); 294 struct protoent *getprotoent_r(struct protoent *, char *, int); 295 void setprotoent_r(int); 296 void endprotoent_r(void); 297 298 struct servent *getservbyname_r(const char *name, const char *, 299 struct servent *, char *, int); 300 struct servent *getservbyport_r(int port, const char *, 301 struct servent *, char *, int); 302 struct servent *getservent_r(struct servent *, char *, int); 303 void setservent_r(int); 304 void endservent_r(void); 305 __END_DECLS 306 307 #endif /* _NETDB_H_ */ 308