2 * D header file for POSIX.
4 * Copyright: Public Domain
5 * License: Public Domain
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9 module stdc.posix.sys.socket;
11 private import stdc.posix.config;
12 public import stdc.posix.sys.types; // for ssize_t, size_t
13 public import stdc.posix.sys.uio; // for iovec
26 sa_family_t sa_family;
30 struct sockaddr_storage
32 sa_family_t ss_family;
38 socklen_t msg_namelen;
39 struct iovec* msg_iov;
42 socklen_t msg_controllen;
46 struct iovec {} // from stdc.posix.sys.uio
58 CMSG_NXTHDR(mhdr,cmsg)
108 int accept(int, sockaddr*, socklen_t*);
109 int bind(int, in sockaddr*, socklen_t);
110 int connect(int, in sockaddr*, socklen_t);
111 int getpeername(int, sockaddr*, socklen_t*);
112 int getsockname(int, sockaddr*, socklen_t*);
113 int getsockopt(int, int, int, void*, socklen_t*);
114 int listen(int, int);
115 ssize_t recv(int, void*, size_t, int);
116 ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*);
117 ssize_t recvmsg(int, msghdr*, int);
118 ssize_t send(int, in void*, size_t, int);
119 ssize_t sendmsg(int, in msghdr*, int);
120 ssize_t sendto(int, in void*, size_t, int, in sockaddr*, socklen_t);
121 int setsockopt(int, int, int, in void*, socklen_t);
122 int shutdown(int, int);
123 int socket(int, int, int);
125 int socketpair(int, int, int, int[2]);
130 alias uint socklen_t;
131 alias ushort sa_family_t;
135 sa_family_t sa_family;
139 private enum : size_t
142 _SS_PADSIZE = _SS_SIZE - (c_ulong.sizeof * 2)
145 struct sockaddr_storage
147 sa_family_t ss_family;
149 byte[_SS_PADSIZE] __ss_padding;
155 socklen_t msg_namelen;
159 size_t msg_controllen;
168 static if( false /* (!is( __STRICT_ANSI__ ) && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L */ )
170 ubyte[1] __cmsg_data;
179 static if( false /* (!is( __STRICT_ANSI__ ) && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L */ )
181 extern (D) ubyte[1] CMSG_DATA( cmsghdr* cmsg ) { return cmsg.__cmsg_data; }
185 extern (D) ubyte* CMSG_DATA( cmsghdr* cmsg ) { return cast(ubyte*)( cmsg + 1 ); }
188 private cmsghdr* __cmsg_nxthdr(msghdr*, cmsghdr*);
189 alias __cmsg_nxthdr CMSG_NXTHDR;
191 extern (D) size_t CMSG_FIRSTHDR( msghdr* mhdr )
193 return cast(size_t)( mhdr.msg_controllen >= cmsghdr.sizeof
194 ? cast(cmsghdr*) mhdr.msg_control
195 : cast(cmsghdr*) null );
244 MSG_DONTROUTE = 0x04,
266 int accept(int, sockaddr*, socklen_t*);
267 int bind(int, in sockaddr*, socklen_t);
268 int connect(int, in sockaddr*, socklen_t);
269 int getpeername(int, sockaddr*, socklen_t*);
270 int getsockname(int, sockaddr*, socklen_t*);
271 int getsockopt(int, int, int, void*, socklen_t*);
272 int listen(int, int);
273 ssize_t recv(int, void*, size_t, int);
274 ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*);
275 ssize_t recvmsg(int, msghdr*, int);
276 ssize_t send(int, in void*, size_t, int);
277 ssize_t sendmsg(int, in msghdr*, int);
278 ssize_t sendto(int, in void*, size_t, int, in sockaddr*, socklen_t);
279 int setsockopt(int, int, int, in void*, socklen_t);
280 int shutdown(int, int);
281 int socket(int, int, int);
283 int socketpair(int, int, int, int[2]);
285 else version( darwin )
287 alias uint socklen_t;
288 alias ubyte sa_family_t;
293 sa_family_t sa_family;
297 private enum : size_t
299 _SS_PAD1 = long.sizeof - ubyte.sizeof - sa_family_t.sizeof,
300 _SS_PAD2 = 128 - ubyte.sizeof - sa_family_t.sizeof - _SS_PAD1 - long.sizeof
303 struct sockaddr_storage
306 sa_family_t ss_family;
307 byte[_SS_PAD1] __ss_pad1;
309 byte[_SS_PAD2] __ss_pad2;
315 socklen_t msg_namelen;
319 socklen_t msg_controllen;
336 CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
337 ALIGN(sizeof(struct cmsghdr)))
338 CMSG_NXTHDR(mhdr, cmsg) \
339 (((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
340 ALIGN(sizeof(struct cmsghdr)) > \
341 (unsigned char *)(mhdr)->msg_control +(mhdr)->msg_controllen) ? \
342 (struct cmsghdr *)0 /* NULL */ : \
343 (struct cmsghdr *)((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len)))
344 CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
367 SO_ACCEPTCONN = 0x0002,
368 SO_BROADCAST = 0x0020,
370 SO_DONTROUTE = 0x0010,
372 SO_KEEPALIVE = 0x0008,
374 SO_OOBINLINE = 0x0100,
376 SO_RCVLOWAT = 0x1004,
377 SO_RCVTIMEO = 0x1006,
378 SO_REUSEADDR = 0x1006,
380 SO_SNDLOWAT = 0x1003,
381 SO_SNDTIMEO = 0x1005,
415 int accept(int, sockaddr*, socklen_t*);
416 int bind(int, in sockaddr*, socklen_t);
417 int connect(int, in sockaddr*, socklen_t);
418 int getpeername(int, sockaddr*, socklen_t*);
419 int getsockname(int, sockaddr*, socklen_t*);
420 int getsockopt(int, int, int, void*, socklen_t*);
421 int listen(int, int);
422 ssize_t recv(int, void*, size_t, int);
423 ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*);
424 ssize_t recvmsg(int, msghdr*, int);
425 ssize_t send(int, in void*, size_t, int);
426 ssize_t sendmsg(int, in msghdr*, int);
427 ssize_t sendto(int, in void*, size_t, int, in sockaddr*, socklen_t);
428 int setsockopt(int, int, int, in void*, socklen_t);
429 int shutdown(int, int);
430 int socket(int, int, int);
432 int socketpair(int, int, int, int[2]);
434 else version( freebsd )
436 alias uint socklen_t;
437 alias ubyte sa_family_t;
442 sa_family_t sa_family;
448 const _SS_ALIGNSIZE = long.sizeof;
449 const uint _SS_MAXSIZE = 128;
450 const _SS_PAD1SIZE = _SS_ALIGNSIZE - ubyte.sizeof - sa_family_t.sizeof;
451 const _SS_PAD2SIZE = _SS_MAXSIZE - ubyte.sizeof - sa_family_t.sizeof - _SS_PAD1SIZE - _SS_ALIGNSIZE;
454 struct sockaddr_storage
457 sa_family_t ss_family;
458 byte[_SS_PAD1SIZE] __ss_pad1;
460 byte[_SS_PAD2SIZE] __ss_pad2;
466 socklen_t msg_namelen;
470 socklen_t msg_controllen;
487 CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
488 ALIGN(sizeof(struct cmsghdr)))
489 CMSG_NXTHDR(mhdr, cmsg) \
490 (((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
491 ALIGN(sizeof(struct cmsghdr)) > \
492 (unsigned char *)(mhdr)->msg_control +(mhdr)->msg_controllen) ? \
493 (struct cmsghdr *)0 /* NULL */ : \
494 (struct cmsghdr *)((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len)))
495 CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
518 SO_ACCEPTCONN = 0x0002,
519 SO_BROADCAST = 0x0020,
521 SO_DONTROUTE = 0x0010,
523 SO_KEEPALIVE = 0x0008,
525 SO_OOBINLINE = 0x0100,
527 SO_RCVLOWAT = 0x1004,
528 SO_RCVTIMEO = 0x1006,
529 SO_REUSEADDR = 0x1006,
531 SO_SNDLOWAT = 0x1003,
532 SO_SNDTIMEO = 0x1005,
566 int accept(int, sockaddr*, socklen_t*);
567 int bind(int, in sockaddr*, socklen_t);
568 int connect(int, in sockaddr*, socklen_t);
569 int getpeername(int, sockaddr*, socklen_t*);
570 int getsockname(int, sockaddr*, socklen_t*);
571 int getsockopt(int, int, int, void*, socklen_t*);
572 int listen(int, int);
573 ssize_t recv(int, void*, size_t, int);
574 ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*);
575 ssize_t recvmsg(int, msghdr*, int);
576 ssize_t send(int, in void*, size_t, int);
577 ssize_t sendmsg(int, in msghdr*, int);
578 ssize_t sendto(int, in void*, size_t, int, in sockaddr*, socklen_t);
579 int setsockopt(int, int, int, in void*, socklen_t);
580 int shutdown(int, int);
581 int socket(int, int, int);
583 int socketpair(int, int, int, int[2]);
600 else version( darwin )
607 else version( freebsd )
629 else version( darwin )
636 else version( freebsd )