1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 */
9
10 /* Copyright Sean Kelly 2005 - 2009.
11 * Distributed under the Boost Software License, Version 1.0.
12 * (See accompanying file LICENSE or copy at
13 * http://www.boost.org/LICENSE_1_0.txt)
14 */
15 module core.sys.posix.arpa.inet;
16
17 private import core.sys.posix.config;
18 public import core.stdc.inttypes; // for uint32_t, uint16_t
19 public import core.sys.posix.sys.socket; // for socklen_t
20
21 version (OSX)
22 version = Darwin;
23 else version (iOS)
24 version = Darwin;
25 else version (TVOS)
26 version = Darwin;
27 else version (WatchOS)
28 version = Darwin;
29
version(Posix)30 version (Posix):
31 extern (C) nothrow @nogc:
32
33 //
34 // Required
35 //
36 /*
37 NOTE: The following must must be defined in core.sys.posix.arpa.inet to break
38 a circular import: in_port_t, in_addr_t, struct in_addr, INET_ADDRSTRLEN.
39
40 in_port_t // from core.sys.posix.netinet.in_
41 in_addr_t // from core.sys.posix.netinet.in_
42
43 struct in_addr // from core.sys.posix.netinet.in_
44 INET_ADDRSTRLEN // from core.sys.posix.netinet.in_
45
46 uint32_t // from core.stdc.inttypes
47 uint16_t // from core.stdc.inttypes
48
49 uint32_t htonl(uint32_t);
50 uint16_t htons(uint16_t);
51 uint32_t ntohl(uint32_t);
52 uint16_t ntohs(uint16_t);
53
54 in_addr_t inet_addr(in char*);
55 char* inet_ntoa(in_addr);
56 // per spec: const char* inet_ntop(int, const void*, char*, socklen_t);
57 char* inet_ntop(int, in void*, char*, socklen_t);
58 int inet_pton(int, in char*, void*);
59 */
60
61 version (CRuntime_Glibc)
62 {
63 alias uint16_t in_port_t;
64 alias uint32_t in_addr_t;
65
66 struct in_addr
67 {
68 in_addr_t s_addr;
69 }
70
71 enum INET_ADDRSTRLEN = 16;
72
73 @trusted pure
74 {
75 uint32_t htonl(uint32_t);
76 uint16_t htons(uint16_t);
77 uint32_t ntohl(uint32_t);
78 uint16_t ntohs(uint16_t);
79 }
80
81 in_addr_t inet_addr(in char*);
82 char* inet_ntoa(in_addr);
83 const(char)* inet_ntop(int, in void*, char*, socklen_t);
84 int inet_pton(int, in char*, void*);
85 }
version(Darwin)86 else version (Darwin)
87 {
88 alias uint16_t in_port_t;
89 alias uint32_t in_addr_t;
90
91 struct in_addr
92 {
93 in_addr_t s_addr;
94 }
95
96 enum INET_ADDRSTRLEN = 16;
97
98 @trusted pure
99 {
100 uint32_t htonl(uint32_t);
101 uint16_t htons(uint16_t);
102 uint32_t ntohl(uint32_t);
103 uint16_t ntohs(uint16_t);
104 }
105
106 in_addr_t inet_addr(in char*);
107 char* inet_ntoa(in_addr);
108 const(char)* inet_ntop(int, in void*, char*, socklen_t);
109 int inet_pton(int, in char*, void*);
110 }
version(FreeBSD)111 else version (FreeBSD)
112 {
113 alias uint16_t in_port_t;
114 alias uint32_t in_addr_t;
115
116 struct in_addr
117 {
118 in_addr_t s_addr;
119 }
120
121 enum INET_ADDRSTRLEN = 16;
122
123 @trusted pure
124 {
125 uint32_t htonl(uint32_t);
126 uint16_t htons(uint16_t);
127 uint32_t ntohl(uint32_t);
128 uint16_t ntohs(uint16_t);
129 }
130
131 in_addr_t inet_addr(in char*);
132 char* inet_ntoa(in_addr);
133 const(char)* inet_ntop(int, in void*, char*, socklen_t);
134 int inet_pton(int, in char*, void*);
135 }
version(NetBSD)136 else version (NetBSD)
137 {
138 alias uint16_t in_port_t;
139 alias uint32_t in_addr_t;
140
141 struct in_addr
142 {
143 in_addr_t s_addr;
144 }
145
146 enum INET_ADDRSTRLEN = 16;
147
148 @trusted pure
149 {
150 uint32_t htonl(uint32_t);
151 uint16_t htons(uint16_t);
152 uint32_t ntohl(uint32_t);
153 uint16_t ntohs(uint16_t);
154 }
155
156 in_addr_t inet_addr(in char*);
157 char* inet_ntoa(in_addr);
158 const(char)* inet_ntop(int, in void*, char*, socklen_t);
159 int inet_pton(int, in char*, void*);
160 }
version(DragonFlyBSD)161 else version (DragonFlyBSD)
162 {
163 alias uint16_t in_port_t;
164 alias uint32_t in_addr_t;
165
166 struct in_addr
167 {
168 in_addr_t s_addr;
169 }
170
171 enum INET_ADDRSTRLEN = 16;
172
173 @trusted pure
174 {
175 uint32_t htonl(uint32_t);
176 uint16_t htons(uint16_t);
177 uint32_t ntohl(uint32_t);
178 uint16_t ntohs(uint16_t);
179 }
180
181 in_addr_t inet_addr(in char*);
182 char* inet_ntoa(in_addr);
183 const(char)* inet_ntop(int, in void*, char*, socklen_t);
184 int inet_pton(int, in char*, void*);
185 }
version(Solaris)186 else version (Solaris)
187 {
188 alias uint16_t in_port_t;
189 alias uint32_t in_addr_t;
190
191 struct in_addr
192 {
193 in_addr_t s_addr;
194 }
195 enum INET_ADDRSTRLEN = 16;
196
197 @trusted pure
198 {
199 uint32_t htonl(uint32_t);
200 uint16_t htons(uint16_t);
201 uint32_t ntohl(uint32_t);
202 uint16_t ntohs(uint16_t);
203 }
204
205 in_addr_t inet_addr(in char*);
206 char* inet_ntoa(in_addr);
207 const(char)* inet_ntop(int, in void*, char*, socklen_t);
208 int inet_pton(int, in char*, void*);
209 }
version(CRuntime_Bionic)210 else version (CRuntime_Bionic)
211 {
212 alias uint32_t in_addr_t;
213
214 struct in_addr
215 {
216 in_addr_t s_addr;
217 }
218
219 enum INET_ADDRSTRLEN = 16;
220
221 @safe pure extern (D)
222 {
223 private
224 {
225 uint32_t __swap32( uint32_t x )
226 {
227 uint32_t byte32_swap = (x & 0xff) << 24 | (x &0xff00) << 8 |
228 (x & 0xff0000) >> 8 | (x & 0xff000000) >> 24;
229 return byte32_swap;
230 }
231
232 uint16_t __swap16( uint16_t x )
233 {
234 uint16_t byte16_swap = (x & 0xff) << 8 | (x & 0xff00) >> 8;
235 return byte16_swap;
236 }
237 }
238
239 uint32_t htonl(uint32_t x) { return __swap32(x); }
240 uint16_t htons(uint16_t x) { return __swap16(x); }
241 uint32_t ntohl(uint32_t x) { return __swap32(x); }
242 uint16_t ntohs(uint16_t x) { return __swap16(x); }
243 }
244
245 in_addr_t inet_addr(in char*);
246 char* inet_ntoa(in_addr);
247 const(char)* inet_ntop(int, in void*, char*, size_t);
248 int inet_pton(int, in char*, void*);
249 }
version(CRuntime_Musl)250 else version (CRuntime_Musl)
251 {
252 alias uint16_t in_port_t;
253 alias uint32_t in_addr_t;
254
255 struct in_addr
256 {
257 in_addr_t s_addr;
258 }
259
260 enum INET_ADDRSTRLEN = 16;
261
262 @trusted pure
263 {
264 uint32_t htonl(uint32_t);
265 uint16_t htons(uint16_t);
266 uint32_t ntohl(uint32_t);
267 uint16_t ntohs(uint16_t);
268 }
269
270 in_addr_t inet_addr(in char*);
271 char* inet_ntoa(in_addr);
272 const(char)* inet_ntop(int, in void*, char*, socklen_t);
273 int inet_pton(int, in char*, void*);
274 }
version(CRuntime_UClibc)275 else version (CRuntime_UClibc)
276 {
277 alias uint16_t in_port_t;
278 alias uint32_t in_addr_t;
279
280 struct in_addr
281 {
282 in_addr_t s_addr;
283 }
284
285 enum INET_ADDRSTRLEN = 16;
286
287 @trusted pure
288 {
289 uint32_t htonl(uint32_t);
290 uint16_t htons(uint16_t);
291 uint32_t ntohl(uint32_t);
292 uint16_t ntohs(uint16_t);
293 }
294
295 in_addr_t inet_addr(in char*);
296 char* inet_ntoa(in_addr);
297 const(char)* inet_ntop(int, in void*, char*, socklen_t);
298 int inet_pton(int, in char*, void*);
299 }
300
301 //
302 // IPV6 (IP6)
303 //
304 /*
305 NOTE: The following must must be defined in core.sys.posix.arpa.inet to break
306 a circular import: INET6_ADDRSTRLEN.
307
308 INET6_ADDRSTRLEN // from core.sys.posix.netinet.in_
309 */
310
version(CRuntime_Glibc)311 version (CRuntime_Glibc)
312 {
313 enum INET6_ADDRSTRLEN = 46;
314 }
version(Darwin)315 else version (Darwin)
316 {
317 enum INET6_ADDRSTRLEN = 46;
318 }
version(FreeBSD)319 else version (FreeBSD)
320 {
321 enum INET6_ADDRSTRLEN = 46;
322 }
version(NetBSD)323 else version (NetBSD)
324 {
325 enum INET6_ADDRSTRLEN = 46;
326 }
version(DragonFlyBSD)327 else version (DragonFlyBSD)
328 {
329 enum INET6_ADDRSTRLEN = 46;
330 }
version(Solaris)331 else version (Solaris)
332 {
333 enum INET6_ADDRSTRLEN = 46;
334 }
version(CRuntime_Bionic)335 else version (CRuntime_Bionic)
336 {
337 enum INET6_ADDRSTRLEN = 46;
338 }
version(CRuntime_UClibc)339 else version (CRuntime_UClibc)
340 {
341 enum INET6_ADDRSTRLEN = 46;
342 }
343