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 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(const scope 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, const scope void*, char*, socklen_t);
58 int inet_pton(int, const scope 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(const scope char*);
82 char* inet_ntoa(in_addr);
83 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
84 int inet_pton(int, const scope 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(const scope char*);
107 char* inet_ntoa(in_addr);
108 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
109 int inet_pton(int, const scope 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(const scope char*);
132 char* inet_ntoa(in_addr);
133 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
134 int inet_pton(int, const scope 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(const scope char*);
157 char* inet_ntoa(in_addr);
158 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
159 int inet_pton(int, const scope char*, void*);
160 }
version(OpenBSD)161 else version (OpenBSD)
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 @safe pure extern (D)
174 {
175 private
176 {
177 uint32_t __swap32( uint32_t x )
178 {
179 uint32_t byte32_swap = (x & 0xff) << 24 | (x &0xff00) << 8 |
180 (x & 0xff0000) >> 8 | (x & 0xff000000) >> 24;
181 return byte32_swap;
182 }
183
184 uint16_t __swap16( uint16_t x )
185 {
186 uint16_t byte16_swap = (x & 0xff) << 8 | (x & 0xff00) >> 8;
187 return byte16_swap;
188 }
189 }
190
191 uint32_t htonl(uint32_t x) { return __swap32(x); }
192 uint16_t htons(uint16_t x) { return __swap16(x); }
193 uint32_t ntohl(uint32_t x) { return __swap32(x); }
194 uint16_t ntohs(uint16_t x) { return __swap16(x); }
195 }
196
197 in_addr_t inet_addr(const scope char*);
198 char* inet_ntoa(in_addr);
199 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
200 int inet_pton(int, const scope char*, void*);
201 }
version(DragonFlyBSD)202 else version (DragonFlyBSD)
203 {
204 alias uint16_t in_port_t;
205 alias uint32_t in_addr_t;
206
207 struct in_addr
208 {
209 in_addr_t s_addr;
210 }
211
212 enum INET_ADDRSTRLEN = 16;
213
214 @trusted pure
215 {
216 uint32_t htonl(uint32_t);
217 uint16_t htons(uint16_t);
218 uint32_t ntohl(uint32_t);
219 uint16_t ntohs(uint16_t);
220 }
221
222 in_addr_t inet_addr(const scope char*);
223 char* inet_ntoa(in_addr);
224 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
225 int inet_pton(int, const scope char*, void*);
226 }
version(Solaris)227 else version (Solaris)
228 {
229 alias uint16_t in_port_t;
230 alias uint32_t in_addr_t;
231
232 struct in_addr
233 {
234 in_addr_t s_addr;
235 }
236 enum INET_ADDRSTRLEN = 16;
237
238 @trusted pure
239 {
240 uint32_t htonl(uint32_t);
241 uint16_t htons(uint16_t);
242 uint32_t ntohl(uint32_t);
243 uint16_t ntohs(uint16_t);
244 }
245
246 in_addr_t inet_addr(const scope char*);
247 char* inet_ntoa(in_addr);
248 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
249 int inet_pton(int, const scope char*, void*);
250 }
version(CRuntime_Bionic)251 else version (CRuntime_Bionic)
252 {
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 @safe pure extern (D)
263 {
264 private
265 {
266 uint32_t __swap32( uint32_t x )
267 {
268 uint32_t byte32_swap = (x & 0xff) << 24 | (x &0xff00) << 8 |
269 (x & 0xff0000) >> 8 | (x & 0xff000000) >> 24;
270 return byte32_swap;
271 }
272
273 uint16_t __swap16( uint16_t x )
274 {
275 uint16_t byte16_swap = (x & 0xff) << 8 | (x & 0xff00) >> 8;
276 return byte16_swap;
277 }
278 }
279
280 uint32_t htonl(uint32_t x) { return __swap32(x); }
281 uint16_t htons(uint16_t x) { return __swap16(x); }
282 uint32_t ntohl(uint32_t x) { return __swap32(x); }
283 uint16_t ntohs(uint16_t x) { return __swap16(x); }
284 }
285
286 in_addr_t inet_addr(const scope char*);
287 char* inet_ntoa(in_addr);
288 const(char)* inet_ntop(int, const scope void*, char*, size_t);
289 int inet_pton(int, const scope char*, void*);
290 }
version(CRuntime_Musl)291 else version (CRuntime_Musl)
292 {
293 alias uint16_t in_port_t;
294 alias uint32_t in_addr_t;
295
296 struct in_addr
297 {
298 in_addr_t s_addr;
299 }
300
301 enum INET_ADDRSTRLEN = 16;
302
303 @trusted pure
304 {
305 uint32_t htonl(uint32_t);
306 uint16_t htons(uint16_t);
307 uint32_t ntohl(uint32_t);
308 uint16_t ntohs(uint16_t);
309 }
310
311 in_addr_t inet_addr(const scope char*);
312 char* inet_ntoa(in_addr);
313 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
314 int inet_pton(int, const scope char*, void*);
315 }
version(CRuntime_UClibc)316 else version (CRuntime_UClibc)
317 {
318 alias uint16_t in_port_t;
319 alias uint32_t in_addr_t;
320
321 struct in_addr
322 {
323 in_addr_t s_addr;
324 }
325
326 enum INET_ADDRSTRLEN = 16;
327
328 @trusted pure
329 {
330 uint32_t htonl(uint32_t);
331 uint16_t htons(uint16_t);
332 uint32_t ntohl(uint32_t);
333 uint16_t ntohs(uint16_t);
334 }
335
336 in_addr_t inet_addr(const scope char*);
337 char* inet_ntoa(in_addr);
338 const(char)* inet_ntop(int, const scope void*, char*, socklen_t);
339 int inet_pton(int, const scope char*, void*);
340 }
341
342 //
343 // IPV6 (IP6)
344 //
345 /*
346 NOTE: The following must must be defined in core.sys.posix.arpa.inet to break
347 a circular import: INET6_ADDRSTRLEN.
348
349 INET6_ADDRSTRLEN // from core.sys.posix.netinet.in_
350 */
351
version(CRuntime_Glibc)352 version (CRuntime_Glibc)
353 {
354 enum INET6_ADDRSTRLEN = 46;
355 }
version(Darwin)356 else version (Darwin)
357 {
358 enum INET6_ADDRSTRLEN = 46;
359 }
version(FreeBSD)360 else version (FreeBSD)
361 {
362 enum INET6_ADDRSTRLEN = 46;
363 }
version(NetBSD)364 else version (NetBSD)
365 {
366 enum INET6_ADDRSTRLEN = 46;
367 }
version(OpenBSD)368 else version (OpenBSD)
369 {
370 enum INET6_ADDRSTRLEN = 46;
371 }
version(DragonFlyBSD)372 else version (DragonFlyBSD)
373 {
374 enum INET6_ADDRSTRLEN = 46;
375 }
version(Solaris)376 else version (Solaris)
377 {
378 enum INET6_ADDRSTRLEN = 46;
379 }
version(CRuntime_Bionic)380 else version (CRuntime_Bionic)
381 {
382 enum INET6_ADDRSTRLEN = 46;
383 }
version(CRuntime_UClibc)384 else version (CRuntime_UClibc)
385 {
386 enum INET6_ADDRSTRLEN = 46;
387 }
388