netdb.h revision 1.1 1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14 /*! \file */
15
16 #ifndef IRS_NETDB_H
17 #define IRS_NETDB_H 1
18
19 #include <stddef.h> /* Required on FreeBSD (and others?) for size_t. */
20 #include <netdb.h> /* Contractual provision. */
21
22 /*
23 * Undefine all #defines we are interested in as <netdb.h> may or may not have
24 * defined them.
25 */
26
27 /*
28 * Error return codes from gethostbyname() and gethostbyaddr()
29 * (left in extern int h_errno).
30 */
31
32 #undef NETDB_INTERNAL
33 #undef NETDB_SUCCESS
34 #undef HOST_NOT_FOUND
35 #undef TRY_AGAIN
36 #undef NO_RECOVERY
37 #undef NO_DATA
38 #undef NO_ADDRESS
39
40 #define NETDB_INTERNAL -1 /* see errno */
41 #define NETDB_SUCCESS 0 /* no problem */
42 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
43 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
44 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
45 #define NO_DATA 4 /* Valid name, no data record of requested type */
46 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
47
48 /*
49 * Error return codes from getaddrinfo(). EAI_INSECUREDATA is our own extension
50 * and it's very unlikely to be already defined, but undef it just in case; it
51 * at least doesn't do any harm.
52 */
53
54 #undef EAI_ADDRFAMILY
55 #undef EAI_AGAIN
56 #undef EAI_BADFLAGS
57 #undef EAI_FAIL
58 #undef EAI_FAMILY
59 #undef EAI_MEMORY
60 #undef EAI_NODATA
61 #undef EAI_NONAME
62 #undef EAI_SERVICE
63 #undef EAI_SOCKTYPE
64 #undef EAI_SYSTEM
65 #undef EAI_BADHINTS
66 #undef EAI_PROTOCOL
67 #undef EAI_OVERFLOW
68 #undef EAI_INSECUREDATA
69 #undef EAI_MAX
70
71 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
72 #define EAI_AGAIN 2 /* temporary failure in name resolution */
73 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
74 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
75 #define EAI_FAMILY 5 /* ai_family not supported */
76 #define EAI_MEMORY 6 /* memory allocation failure */
77 #define EAI_NODATA 7 /* no address associated with hostname */
78 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
79 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
80 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
81 #define EAI_SYSTEM 11 /* system error returned in errno */
82 #define EAI_BADHINTS 12
83 #define EAI_PROTOCOL 13
84 #define EAI_OVERFLOW 14
85 #define EAI_INSECUREDATA 15
86 #define EAI_MAX 16
87
88 /*
89 * Flag values for getaddrinfo()
90 */
91 #undef AI_PASSIVE
92 #undef AI_CANONNAME
93 #undef AI_NUMERICHOST
94
95 #define AI_PASSIVE 0x00000001
96 #define AI_CANONNAME 0x00000002
97 #define AI_NUMERICHOST 0x00000004
98
99 /*
100 * Flag values for getipnodebyname()
101 */
102 #undef AI_V4MAPPED
103 #undef AI_ALL
104 #undef AI_ADDRCONFIG
105 #undef AI_DEFAULT
106
107 #define AI_V4MAPPED 0x00000008
108 #define AI_ALL 0x00000010
109 #define AI_ADDRCONFIG 0x00000020
110 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
111
112 /*
113 * Constants for getnameinfo()
114 */
115 #undef NI_MAXHOST
116 #undef NI_MAXSERV
117
118 #define NI_MAXHOST 1025
119 #define NI_MAXSERV 32
120
121 /*
122 * Flag values for getnameinfo()
123 */
124 #undef NI_NOFQDN
125 #undef NI_NUMERICHOST
126 #undef NI_NAMEREQD
127 #undef NI_NUMERICSERV
128 #undef NI_DGRAM
129 #undef NI_NUMERICSCOPE
130
131 #define NI_NOFQDN 0x00000001
132 #define NI_NUMERICHOST 0x00000002
133 #define NI_NAMEREQD 0x00000004
134 #define NI_NUMERICSERV 0x00000008
135 #define NI_DGRAM 0x00000010
136
137 /*
138 * Define to map into irs_ namespace.
139 */
140
141 #ifndef __NetBSD__
142 #define IRS_NAMESPACE
143 #endif
144
145 #ifdef IRS_NAMESPACE
146
147 /*
148 * Use our versions not the ones from the C library.
149 */
150
151 #ifdef getnameinfo
152 #undef getnameinfo
153 #endif
154 #define getnameinfo irs_getnameinfo
155
156 #ifdef getaddrinfo
157 #undef getaddrinfo
158 #endif
159 #define getaddrinfo irs_getaddrinfo
160
161 #ifdef freeaddrinfo
162 #undef freeaddrinfo
163 #endif
164 #define freeaddrinfo irs_freeaddrinfo
165
166 #ifdef gai_strerror
167 #undef gai_strerror
168 #endif
169 #define gai_strerror irs_gai_strerror
170
171 int
172 getaddrinfo(const char *hostname, const char *servname,
173 const struct addrinfo *hints, struct addrinfo **res);
174
175 int
176 getnameinfo(const struct sockaddr *sa, socklen_t salen,
177 char *host, socklen_t hostlen,
178 char *serv, socklen_t servlen,
179 int flags);
180
181 void freeaddrinfo (struct addrinfo *ai);
182
183 const char *
184 gai_strerror(int ecode);
185
186 #endif /* IRS_NAMESPACE */
187
188 /*
189 * Tell Emacs to use C mode on this file.
190 * Local variables:
191 * mode: c
192 * End:
193 */
194
195 #endif /* IRS_NETDB_H */
196