comparison druntime/import/stdc/posix/netinet/in_.d @ 760:6f33b427bfd1

Seems like hg ignores .di files, so I missed a bunch of stuff. complete druntime should be there now :)
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 12 Nov 2008 00:19:18 +0100
parents
children
comparison
equal deleted inserted replaced
759:d3eb054172f9 760:6f33b427bfd1
1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Public Domain
5 * License: Public Domain
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 */
9 module stdc.posix.netinet.in_;
10
11 private import stdc.posix.config;
12 public import stdc.inttypes : uint32_t, uint16_t, uint8_t;
13 public import stdc.posix.arpa.inet;
14 public import stdc.posix.sys.socket; // for sa_family_t
15
16 extern (C):
17
18 //
19 // Required
20 //
21 /*
22 NOTE: The following must must be defined in stdc.posix.arpa.inet to break
23 a circular import: in_port_t, in_addr_t, struct in_addr, INET_ADDRSTRLEN.
24
25 in_port_t
26 in_addr_t
27
28 sa_family_t // from stdc.posix.sys.socket
29 uint8_t // from stdc.inttypes
30 uint32_t // from stdc.inttypes
31
32 struct in_addr
33 {
34 in_addr_t s_addr;
35 }
36
37 struct sockaddr_in
38 {
39 sa_family_t sin_family;
40 in_port_t sin_port;
41 in_addr sin_addr;
42 }
43
44 IPPROTO_IP
45 IPPROTO_ICMP
46 IPPROTO_TCP
47 IPPROTO_UDP
48
49 INADDR_ANY
50 INADDR_BROADCAST
51
52 INET_ADDRSTRLEN
53
54 htonl() // from stdc.posix.arpa.inet
55 htons() // from stdc.posix.arpa.inet
56 ntohl() // from stdc.posix.arpa.inet
57 ntohs() // from stdc.posix.arpa.inet
58 */
59
60 version( linux )
61 {
62 private const __SOCK_SIZE__ = 16;
63
64 struct sockaddr_in
65 {
66 sa_family_t sin_family;
67 in_port_t sin_port;
68 in_addr sin_addr;
69
70 /* Pad to size of `struct sockaddr'. */
71 ubyte[__SOCK_SIZE__ - sa_family_t.sizeof -
72 in_port_t.sizeof - in_addr.sizeof] __pad;
73 }
74
75 enum
76 {
77 IPPROTO_IP = 0,
78 IPPROTO_ICMP = 1,
79 IPPROTO_TCP = 6,
80 IPPROTO_UDP = 17
81 }
82
83 const uint INADDR_ANY = 0x00000000;
84 const uint INADDR_BROADCAST = 0xffffffff;
85 }
86 else version( darwin )
87 {
88 private const __SOCK_SIZE__ = 16;
89
90 struct sockaddr_in
91 {
92 ubyte sin_len;
93 sa_family_t sin_family;
94 in_port_t sin_port;
95 in_addr sin_addr;
96 ubyte[8] sin_zero;
97 }
98
99 enum
100 {
101 IPPROTO_IP = 0,
102 IPPROTO_ICMP = 1,
103 IPPROTO_TCP = 6,
104 IPPROTO_UDP = 17
105 }
106
107 const uint INADDR_ANY = 0x00000000;
108 const uint INADDR_BROADCAST = 0xffffffff;
109 }
110 else version( freebsd )
111 {
112 private const __SOCK_SIZE__ = 16;
113
114 struct sockaddr_in
115 {
116 ubyte sin_len;
117 sa_family_t sin_family;
118 in_port_t sin_port;
119 in_addr sin_addr;
120 ubyte[8] sin_zero;
121 }
122
123 enum
124 {
125 IPPROTO_IP = 0,
126 IPPROTO_ICMP = 1,
127 IPPROTO_TCP = 6,
128 IPPROTO_UDP = 17
129 }
130
131 const uint INADDR_ANY = 0x00000000;
132 const uint INADDR_BROADCAST = 0xffffffff;
133 }
134
135
136 //
137 // IPV6 (IP6)
138 //
139 /*
140 NOTE: The following must must be defined in stdc.posix.arpa.inet to break
141 a circular import: INET6_ADDRSTRLEN.
142
143 struct in6_addr
144 {
145 uint8_t[16] s6_addr;
146 }
147
148 struct sockaddr_in6
149 {
150 sa_family_t sin6_family;
151 in_port_t sin6_port;
152 uint32_t sin6_flowinfo;
153 in6_addr sin6_addr;
154 uint32_t sin6_scope_id;
155 }
156
157 extern in6_addr in6addr_any;
158 extern in6_addr in6addr_loopback;
159
160 struct ipv6_mreq
161 {
162 in6_addr ipv6mr_multiaddr;
163 uint ipv6mr_interface;
164 }
165
166 IPPROTO_IPV6
167
168 INET6_ADDRSTRLEN
169
170 IPV6_JOIN_GROUP
171 IPV6_LEAVE_GROUP
172 IPV6_MULTICAST_HOPS
173 IPV6_MULTICAST_IF
174 IPV6_MULTICAST_LOOP
175 IPV6_UNICAST_HOPS
176 IPV6_V6ONLY
177
178 // macros
179 int IN6_IS_ADDR_UNSPECIFIED(in6_addr*)
180 int IN6_IS_ADDR_LOOPBACK(in6_addr*)
181 int IN6_IS_ADDR_MULTICAST(in6_addr*)
182 int IN6_IS_ADDR_LINKLOCAL(in6_addr*)
183 int IN6_IS_ADDR_SITELOCAL(in6_addr*)
184 int IN6_IS_ADDR_V4MAPPED(in6_addr*)
185 int IN6_IS_ADDR_V4COMPAT(in6_addr*)
186 int IN6_IS_ADDR_MC_NODELOCAL(in6_addr*)
187 int IN6_IS_ADDR_MC_LINKLOCAL(in6_addr*)
188 int IN6_IS_ADDR_MC_SITELOCAL(in6_addr*)
189 int IN6_IS_ADDR_MC_ORGLOCAL(in6_addr*)
190 int IN6_IS_ADDR_MC_GLOBAL(in6_addr*)
191 */
192
193 version ( linux )
194 {
195 struct in6_addr
196 {
197 union
198 {
199 uint8_t[16] s6_addr;
200 uint16_t[8] s6_addr16;
201 uint32_t[4] s6_addr32;
202 }
203 }
204
205 struct sockaddr_in6
206 {
207 sa_family_t sin6_family;
208 in_port_t sin6_port;
209 uint32_t sin6_flowinfo;
210 in6_addr sin6_addr;
211 uint32_t sin6_scope_id;
212 }
213
214 extern in6_addr in6addr_any;
215 extern in6_addr in6addr_loopback;
216
217 struct ipv6_mreq
218 {
219 in6_addr ipv6mr_multiaddr;
220 uint ipv6mr_interface;
221 }
222
223 enum : uint
224 {
225 IPPROTO_IPV6 = 41,
226
227 INET6_ADDRSTRLEN = 46,
228
229 IPV6_JOIN_GROUP = 20,
230 IPV6_LEAVE_GROUP = 21,
231 IPV6_MULTICAST_HOPS = 18,
232 IPV6_MULTICAST_IF = 17,
233 IPV6_MULTICAST_LOOP = 19,
234 IPV6_UNICAST_HOPS = 16,
235 IPV6_V6ONLY = 26
236 }
237
238 // macros
239 extern (D) int IN6_IS_ADDR_UNSPECIFIED( in6_addr* addr )
240 {
241 return (cast(uint32_t*) addr)[0] == 0 &&
242 (cast(uint32_t*) addr)[1] == 0 &&
243 (cast(uint32_t*) addr)[2] == 0 &&
244 (cast(uint32_t*) addr)[3] == 0;
245 }
246
247 extern (D) int IN6_IS_ADDR_LOOPBACK( in6_addr* addr )
248 {
249 return (cast(uint32_t*) addr)[0] == 0 &&
250 (cast(uint32_t*) addr)[1] == 0 &&
251 (cast(uint32_t*) addr)[2] == 0 &&
252 (cast(uint32_t*) addr)[3] == htonl( 1 );
253 }
254
255 extern (D) int IN6_IS_ADDR_MULTICAST( in6_addr* addr )
256 {
257 return (cast(uint8_t*) addr)[0] == 0xff;
258 }
259
260 extern (D) int IN6_IS_ADDR_LINKLOCAL( in6_addr* addr )
261 {
262 return ((cast(uint32_t*) addr)[0] & htonl( 0xffc00000 )) == htonl( 0xfe800000 );
263 }
264
265 extern (D) int IN6_IS_ADDR_SITELOCAL( in6_addr* addr )
266 {
267 return ((cast(uint32_t*) addr)[0] & htonl( 0xffc00000 )) == htonl( 0xfec00000 );
268 }
269
270 extern (D) int IN6_IS_ADDR_V4MAPPED( in6_addr* addr )
271 {
272 return (cast(uint32_t*) addr)[0] == 0 &&
273 (cast(uint32_t*) addr)[1] == 0 &&
274 (cast(uint32_t*) addr)[2] == htonl( 0xffff );
275 }
276
277 extern (D) int IN6_IS_ADDR_V4COMPAT( in6_addr* addr )
278 {
279 return (cast(uint32_t*) addr)[0] == 0 &&
280 (cast(uint32_t*) addr)[1] == 0 &&
281 (cast(uint32_t*) addr)[2] == 0 &&
282 ntohl( (cast(uint32_t*) addr)[3] ) > 1;
283 }
284
285 extern (D) int IN6_IS_ADDR_MC_NODELOCAL( in6_addr* addr )
286 {
287 return IN6_IS_ADDR_MULTICAST( addr ) &&
288 ((cast(uint8_t*) addr)[1] & 0xf) == 0x1;
289 }
290
291 extern (D) int IN6_IS_ADDR_MC_LINKLOCAL( in6_addr* addr )
292 {
293 return IN6_IS_ADDR_MULTICAST( addr ) &&
294 ((cast(uint8_t*) addr)[1] & 0xf) == 0x2;
295 }
296
297 extern (D) int IN6_IS_ADDR_MC_SITELOCAL( in6_addr* addr )
298 {
299 return IN6_IS_ADDR_MULTICAST(addr) &&
300 ((cast(uint8_t*) addr)[1] & 0xf) == 0x5;
301 }
302
303 extern (D) int IN6_IS_ADDR_MC_ORGLOCAL( in6_addr* addr )
304 {
305 return IN6_IS_ADDR_MULTICAST( addr) &&
306 ((cast(uint8_t*) addr)[1] & 0xf) == 0x8;
307 }
308
309 extern (D) int IN6_IS_ADDR_MC_GLOBAL( in6_addr* addr )
310 {
311 return IN6_IS_ADDR_MULTICAST( addr ) &&
312 ((cast(uint8_t*) addr)[1] & 0xf) == 0xe;
313 }
314 }
315
316
317 //
318 // Raw Sockets (RS)
319 //
320 /*
321 IPPROTO_RAW
322 */
323
324 version (linux )
325 {
326 const uint IPPROTO_RAW = 255;
327 }