comparison druntime/import/core/sys/posix/netinet/in_.d @ 1458:e0b2d67cfe7c

Added druntime (this should be removed once it works).
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 02 Jun 2009 17:43:06 +0100
parents
children
comparison
equal deleted inserted replaced
1456:7b218ec1044f 1458:e0b2d67cfe7c
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>.
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 *
9 * Copyright Sean Kelly 2005 - 2009.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE_1_0.txt or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
13 */
14 module core.sys.posix.netinet.in_;
15
16 private import core.sys.posix.config;
17 public import core.stdc.inttypes; // for uint32_t, uint16_t, uint8_t
18 public import core.sys.posix.arpa.inet;
19 public import core.sys.posix.sys.socket; // for sa_family_t
20
21 extern (C):
22
23 //
24 // Required
25 //
26 /*
27 NOTE: The following must must be defined in core.sys.posix.arpa.inet to break
28 a circular import: in_port_t, in_addr_t, struct in_addr, INET_ADDRSTRLEN.
29
30 in_port_t
31 in_addr_t
32
33 sa_family_t // from core.sys.posix.sys.socket
34 uint8_t // from core.stdc.inttypes
35 uint32_t // from core.stdc.inttypes
36
37 struct in_addr
38 {
39 in_addr_t s_addr;
40 }
41
42 struct sockaddr_in
43 {
44 sa_family_t sin_family;
45 in_port_t sin_port;
46 in_addr sin_addr;
47 }
48
49 IPPROTO_IP
50 IPPROTO_ICMP
51 IPPROTO_TCP
52 IPPROTO_UDP
53
54 INADDR_ANY
55 INADDR_BROADCAST
56
57 INET_ADDRSTRLEN
58
59 htonl() // from core.sys.posix.arpa.inet
60 htons() // from core.sys.posix.arpa.inet
61 ntohl() // from core.sys.posix.arpa.inet
62 ntohs() // from core.sys.posix.arpa.inet
63 */
64
65 version( linux )
66 {
67 private enum __SOCK_SIZE__ = 16;
68
69 struct sockaddr_in
70 {
71 sa_family_t sin_family;
72 in_port_t sin_port;
73 in_addr sin_addr;
74
75 /* Pad to size of `struct sockaddr'. */
76 ubyte[__SOCK_SIZE__ - sa_family_t.sizeof -
77 in_port_t.sizeof - in_addr.sizeof] __pad;
78 }
79
80 enum
81 {
82 IPPROTO_IP = 0,
83 IPPROTO_ICMP = 1,
84 IPPROTO_TCP = 6,
85 IPPROTO_UDP = 17
86 }
87
88 enum uint INADDR_ANY = 0x00000000;
89 enum uint INADDR_BROADCAST = 0xffffffff;
90
91 enum INET_ADDRSTRLEN = 16;
92 }
93 else version( OSX )
94 {
95 private enum __SOCK_SIZE__ = 16;
96
97 struct sockaddr_in
98 {
99 ubyte sin_len;
100 sa_family_t sin_family;
101 in_port_t sin_port;
102 in_addr sin_addr;
103 ubyte[8] sin_zero;
104 }
105
106 enum
107 {
108 IPPROTO_IP = 0,
109 IPPROTO_ICMP = 1,
110 IPPROTO_TCP = 6,
111 IPPROTO_UDP = 17
112 }
113
114 enum uint INADDR_ANY = 0x00000000;
115 enum uint INADDR_BROADCAST = 0xffffffff;
116
117 enum INET_ADDRSTRLEN = 16;
118 }
119 else version( freebsd )
120 {
121 private enum __SOCK_SIZE__ = 16;
122
123 struct sockaddr_in
124 {
125 ubyte sin_len;
126 sa_family_t sin_family;
127 in_port_t sin_port;
128 in_addr sin_addr;
129 ubyte[8] sin_zero;
130 }
131
132 enum
133 {
134 IPPROTO_IP = 0,
135 IPPROTO_ICMP = 1,
136 IPPROTO_TCP = 6,
137 IPPROTO_UDP = 17
138 }
139
140 enum uint INADDR_ANY = 0x00000000;
141 enum uint INADDR_BROADCAST = 0xffffffff;
142 }
143
144
145 //
146 // IPV6 (IP6)
147 //
148 /*
149 NOTE: The following must must be defined in core.sys.posix.arpa.inet to break
150 a circular import: INET6_ADDRSTRLEN.
151
152 struct in6_addr
153 {
154 uint8_t[16] s6_addr;
155 }
156
157 struct sockaddr_in6
158 {
159 sa_family_t sin6_family;
160 in_port_t sin6_port;
161 uint32_t sin6_flowinfo;
162 in6_addr sin6_addr;
163 uint32_t sin6_scope_id;
164 }
165
166 extern in6_addr in6addr_any;
167 extern in6_addr in6addr_loopback;
168
169 struct ipv6_mreq
170 {
171 in6_addr ipv6mr_multiaddr;
172 uint ipv6mr_interface;
173 }
174
175 IPPROTO_IPV6
176
177 INET6_ADDRSTRLEN
178
179 IPV6_JOIN_GROUP
180 IPV6_LEAVE_GROUP
181 IPV6_MULTICAST_HOPS
182 IPV6_MULTICAST_IF
183 IPV6_MULTICAST_LOOP
184 IPV6_UNICAST_HOPS
185 IPV6_V6ONLY
186
187 // macros
188 int IN6_IS_ADDR_UNSPECIFIED(in6_addr*)
189 int IN6_IS_ADDR_LOOPBACK(in6_addr*)
190 int IN6_IS_ADDR_MULTICAST(in6_addr*)
191 int IN6_IS_ADDR_LINKLOCAL(in6_addr*)
192 int IN6_IS_ADDR_SITELOCAL(in6_addr*)
193 int IN6_IS_ADDR_V4MAPPED(in6_addr*)
194 int IN6_IS_ADDR_V4COMPAT(in6_addr*)
195 int IN6_IS_ADDR_MC_NODELOCAL(in6_addr*)
196 int IN6_IS_ADDR_MC_LINKLOCAL(in6_addr*)
197 int IN6_IS_ADDR_MC_SITELOCAL(in6_addr*)
198 int IN6_IS_ADDR_MC_ORGLOCAL(in6_addr*)
199 int IN6_IS_ADDR_MC_GLOBAL(in6_addr*)
200 */
201
202 version ( linux )
203 {
204 struct in6_addr
205 {
206 union
207 {
208 uint8_t[16] s6_addr;
209 uint16_t[8] s6_addr16;
210 uint32_t[4] s6_addr32;
211 }
212 }
213
214 struct sockaddr_in6
215 {
216 sa_family_t sin6_family;
217 in_port_t sin6_port;
218 uint32_t sin6_flowinfo;
219 in6_addr sin6_addr;
220 uint32_t sin6_scope_id;
221 }
222
223 extern in6_addr in6addr_any;
224 extern in6_addr in6addr_loopback;
225
226 struct ipv6_mreq
227 {
228 in6_addr ipv6mr_multiaddr;
229 uint ipv6mr_interface;
230 }
231
232 enum : uint
233 {
234 IPPROTO_IPV6 = 41,
235
236 INET6_ADDRSTRLEN = 46,
237
238 IPV6_JOIN_GROUP = 20,
239 IPV6_LEAVE_GROUP = 21,
240 IPV6_MULTICAST_HOPS = 18,
241 IPV6_MULTICAST_IF = 17,
242 IPV6_MULTICAST_LOOP = 19,
243 IPV6_UNICAST_HOPS = 16,
244 IPV6_V6ONLY = 26
245 }
246
247 // macros
248 extern (D) int IN6_IS_ADDR_UNSPECIFIED( in6_addr* addr )
249 {
250 return (cast(uint32_t*) addr)[0] == 0 &&
251 (cast(uint32_t*) addr)[1] == 0 &&
252 (cast(uint32_t*) addr)[2] == 0 &&
253 (cast(uint32_t*) addr)[3] == 0;
254 }
255
256 extern (D) int IN6_IS_ADDR_LOOPBACK( in6_addr* addr )
257 {
258 return (cast(uint32_t*) addr)[0] == 0 &&
259 (cast(uint32_t*) addr)[1] == 0 &&
260 (cast(uint32_t*) addr)[2] == 0 &&
261 (cast(uint32_t*) addr)[3] == htonl( 1 );
262 }
263
264 extern (D) int IN6_IS_ADDR_MULTICAST( in6_addr* addr )
265 {
266 return (cast(uint8_t*) addr)[0] == 0xff;
267 }
268
269 extern (D) int IN6_IS_ADDR_LINKLOCAL( in6_addr* addr )
270 {
271 return ((cast(uint32_t*) addr)[0] & htonl( 0xffc00000 )) == htonl( 0xfe800000 );
272 }
273
274 extern (D) int IN6_IS_ADDR_SITELOCAL( in6_addr* addr )
275 {
276 return ((cast(uint32_t*) addr)[0] & htonl( 0xffc00000 )) == htonl( 0xfec00000 );
277 }
278
279 extern (D) int IN6_IS_ADDR_V4MAPPED( in6_addr* addr )
280 {
281 return (cast(uint32_t*) addr)[0] == 0 &&
282 (cast(uint32_t*) addr)[1] == 0 &&
283 (cast(uint32_t*) addr)[2] == htonl( 0xffff );
284 }
285
286 extern (D) int IN6_IS_ADDR_V4COMPAT( in6_addr* addr )
287 {
288 return (cast(uint32_t*) addr)[0] == 0 &&
289 (cast(uint32_t*) addr)[1] == 0 &&
290 (cast(uint32_t*) addr)[2] == 0 &&
291 ntohl( (cast(uint32_t*) addr)[3] ) > 1;
292 }
293
294 extern (D) int IN6_IS_ADDR_MC_NODELOCAL( in6_addr* addr )
295 {
296 return IN6_IS_ADDR_MULTICAST( addr ) &&
297 ((cast(uint8_t*) addr)[1] & 0xf) == 0x1;
298 }
299
300 extern (D) int IN6_IS_ADDR_MC_LINKLOCAL( in6_addr* addr )
301 {
302 return IN6_IS_ADDR_MULTICAST( addr ) &&
303 ((cast(uint8_t*) addr)[1] & 0xf) == 0x2;
304 }
305
306 extern (D) int IN6_IS_ADDR_MC_SITELOCAL( in6_addr* addr )
307 {
308 return IN6_IS_ADDR_MULTICAST(addr) &&
309 ((cast(uint8_t*) addr)[1] & 0xf) == 0x5;
310 }
311
312 extern (D) int IN6_IS_ADDR_MC_ORGLOCAL( in6_addr* addr )
313 {
314 return IN6_IS_ADDR_MULTICAST( addr) &&
315 ((cast(uint8_t*) addr)[1] & 0xf) == 0x8;
316 }
317
318 extern (D) int IN6_IS_ADDR_MC_GLOBAL( in6_addr* addr )
319 {
320 return IN6_IS_ADDR_MULTICAST( addr ) &&
321 ((cast(uint8_t*) addr)[1] & 0xf) == 0xe;
322 }
323 }
324 else version( OSX )
325 {
326 struct in6_addr
327 {
328 union
329 {
330 uint8_t[16] s6_addr;
331 uint16_t[8] s6_addr16;
332 uint32_t[4] s6_addr32;
333 }
334 }
335
336 struct sockaddr_in6
337 {
338 uint8_t sin6_len;
339 sa_family_t sin6_family;
340 in_port_t sin6_port;
341 uint32_t sin6_flowinfo;
342 in6_addr sin6_addr;
343 uint32_t sin6_scope_id;
344 }
345
346 extern in6_addr in6addr_any;
347 extern in6_addr in6addr_loopback;
348
349 struct ipv6_mreq
350 {
351 in6_addr ipv6mr_multiaddr;
352 uint ipv6mr_interface;
353 }
354
355 enum : uint
356 {
357 IPPROTO_IPV6 = 41,
358
359 INET6_ADDRSTRLEN = 46,
360
361 IPV6_JOIN_GROUP = 12,
362 IPV6_LEAVE_GROUP = 13,
363 IPV6_MULTICAST_HOPS = 10,
364 IPV6_MULTICAST_IF = 9,
365 IPV6_MULTICAST_LOOP = 11,
366 IPV6_UNICAST_HOPS = 4,
367 IPV6_V6ONLY = 27
368 }
369
370 // macros
371 extern (D) int IN6_IS_ADDR_UNSPECIFIED( in6_addr* addr )
372 {
373 return (cast(uint32_t*) addr)[0] == 0 &&
374 (cast(uint32_t*) addr)[1] == 0 &&
375 (cast(uint32_t*) addr)[2] == 0 &&
376 (cast(uint32_t*) addr)[3] == 0;
377 }
378
379 extern (D) int IN6_IS_ADDR_LOOPBACK( in6_addr* addr )
380 {
381 return (cast(uint32_t*) addr)[0] == 0 &&
382 (cast(uint32_t*) addr)[1] == 0 &&
383 (cast(uint32_t*) addr)[2] == 0 &&
384 (cast(uint32_t*) addr)[3] == ntohl( 1 );
385 }
386
387 extern (D) int IN6_IS_ADDR_MULTICAST( in6_addr* addr )
388 {
389 return addr.s6_addr[0] == 0xff;
390 }
391
392 extern (D) int IN6_IS_ADDR_LINKLOCAL( in6_addr* addr )
393 {
394 return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0x80;
395 }
396
397 extern (D) int IN6_IS_ADDR_SITELOCAL( in6_addr* addr )
398 {
399 return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0xc0;
400 }
401
402 extern (D) int IN6_IS_ADDR_V4MAPPED( in6_addr* addr )
403 {
404 return (cast(uint32_t*) addr)[0] == 0 &&
405 (cast(uint32_t*) addr)[1] == 0 &&
406 (cast(uint32_t*) addr)[2] == ntohl( 0x0000ffff );
407 }
408
409 extern (D) int IN6_IS_ADDR_V4COMPAT( in6_addr* addr )
410 {
411 return (cast(uint32_t*) addr)[0] == 0 &&
412 (cast(uint32_t*) addr)[1] == 0 &&
413 (cast(uint32_t*) addr)[2] == 0 &&
414 (cast(uint32_t*) addr)[3] != 0 &&
415 (cast(uint32_t*) addr)[3] != ntohl( 1 );
416 }
417
418 extern (D) int IN6_IS_ADDR_MC_NODELOCAL( in6_addr* addr )
419 {
420 return IN6_IS_ADDR_MULTICAST( addr ) &&
421 ((cast(uint8_t*) addr)[1] & 0xf) == 0x1;
422 }
423
424 extern (D) int IN6_IS_ADDR_MC_LINKLOCAL( in6_addr* addr )
425 {
426 return IN6_IS_ADDR_MULTICAST( addr ) &&
427 ((cast(uint8_t*) addr)[1] & 0xf) == 0x2;
428 }
429
430 extern (D) int IN6_IS_ADDR_MC_SITELOCAL( in6_addr* addr )
431 {
432 return IN6_IS_ADDR_MULTICAST(addr) &&
433 ((cast(uint8_t*) addr)[1] & 0xf) == 0x5;
434 }
435
436 extern (D) int IN6_IS_ADDR_MC_ORGLOCAL( in6_addr* addr )
437 {
438 return IN6_IS_ADDR_MULTICAST( addr) &&
439 ((cast(uint8_t*) addr)[1] & 0xf) == 0x8;
440 }
441
442 extern (D) int IN6_IS_ADDR_MC_GLOBAL( in6_addr* addr )
443 {
444 return IN6_IS_ADDR_MULTICAST( addr ) &&
445 ((cast(uint8_t*) addr)[1] & 0xf) == 0xe;
446 }
447 }
448
449
450 //
451 // Raw Sockets (RS)
452 //
453 /*
454 IPPROTO_RAW
455 */
456
457 version (linux )
458 {
459 enum uint IPPROTO_RAW = 255;
460 }
461 else version( OSX )
462 {
463 enum uint IPPROTO_RAW = 255;
464 }