1 /***********************************************************************\
2 *                               mswsock.d                               *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                 Translated from MinGW Windows headers                 *
7 *                             by Daniel Keep                            *
8 *                                                                       *
9 *                       Placed into public domain                       *
10 \***********************************************************************/
11 module windows.mswsock;
12 
13 import windows.winbase, windows.windef;
14 private import windows.basetyps, windows.w32api;
15 nothrow:
16 // FIXME: clean up Windows version support
17 
18 version (Win32_Winsock2) pragma(msg,
19  "Version Win32_Winsock2 is deprecated; Winsock2 is now imported by default");
20 
21 // Pull in Winsock1 if the user has put "Win32_Winsock1" on the compile
22 // line; otherwise, default to Winsock2.
23 version (Win32_Winsock1) {
24 	import windows.winsock;
25 } else {
26 	import windows.winsock2;
27 }
28 
29 static if (_WIN32_WINNT >= 0x500) {
30 	enum {
31 		/* WinNT5+:
32 		   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
33 		SO_MAXDG             = 0x7009,
34 		SO_MAXPATHDG         = 0x700A,
35 	}
36 }
37 
38 enum {
39 	/* WinNT4+:
40 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options_for_windows_nt_4_0_2.htm */
41 	SO_CONNDATA              = 0x7000,
42 	SO_CONNOPT               = 0x7001,
43 	SO_DISCDATA              = 0x7002,
44 	SO_DISCOPT               = 0x7003,
45 	SO_CONNDATALEN           = 0x7004,
46 	SO_CONNOPTLEN            = 0x7005,
47 	SO_DISCDATALEN           = 0x7006,
48 	SO_DISCOPTLEN            = 0x7007,
49 
50 	/* WinNT4:
51 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
52 	SO_UPDATE_ACCEPT_CONTENT = 0x700B,
53 }
54 
55 enum {
56 	/* Win95+, WinNT4+ but apparently shouldn't used: mark as deprecated?
57 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
58 	SO_OPENTYPE                  = 0x7008,
59 
60 	/* Win95+; these two are passed to the SO_OPENTYPE option as arguments,
61 	   so would they be deprecated as well?
62 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
63 	SO_SYNCHRONOUS_ALERT         = 0x0010,
64 	SO_SYNCHRONOUS_NONALERT      = 0x0020,
65 
66 	/* Win95:
67 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/socket_options.htm */
68 	SO_CONNECT_TIME              = 0x700C,
69 }
70 
71 
72 enum {
73 	TCP_BSDURGENT = 0x7000,
74 }
75 
76 /* These *appear* to be constants for passing to the TransmitFile /
77    TransmitPackets functions, which are available in WinNT3.51+
78    ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmitfile_2.htm */
79 enum {
80 	TF_DISCONNECT         = 1,
81 	TF_REUSE_SOCKET       = 2,
82 	TF_WRITE_BEHIND       = 4,
83 	TF_USE_DEFAULT_WORKER = 0,
84 	TF_USE_SYSTEM_THREAD  = 16,
85 	TF_USE_KERNEL_APC     = 32
86 }
87 
88 /* Win95+, WinNT3.51+
89    ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmit_file_buffers_2.htm */
90 struct TRANSMIT_FILE_BUFFERS {
91 	PVOID Head;
92 	DWORD HeadLength;
93 	PVOID Tail;
94 	DWORD TailLength;
95 }
96 alias TRANSMIT_FILE_BUFFERS* PTRANSMIT_FILE_BUFFERS, LPTRANSMIT_FILE_BUFFERS;
97 
98 extern(Windows) {
99 	/* Win95+, WinNT3.51+
100 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsarecvex_2.htm */
101 	int WSARecvEx(SOCKET, char*, int, int*);
102 
103 	/* Win95+, WinNT3.51+
104 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/getacceptexSOCKADDRs_2.htm */
105 	VOID GetAcceptExSockaddrs(PVOID, DWORD, DWORD, DWORD, SOCKADDR**, LPINT, SOCKADDR**, LPINT);
106 
107 	/* WinNT3.51+
108 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmitfile_2.htm */
109 	BOOL TransmitFile(SOCKET, HANDLE, DWORD, DWORD, LPOVERLAPPED, LPTRANSMIT_FILE_BUFFERS, DWORD);
110 
111 	/* WinNT3.51+
112 	   ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/acceptex_2.htm */
113 	alias BOOL function(SOCKET, SOCKET, PVOID, DWORD, DWORD, DWORD, LPDWORD, LPOVERLAPPED) LPFN_ACCEPTEX;
114 	const GUID WSAID_ACCEPTEX = {0xb5367df1,0xcbac,0x11cf,[0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92]};
115 
116 	alias BOOL function(SOCKET, SOCKADDR*, int, PVOID, DWORD, LPDWORD, LPOVERLAPPED) LPFN_CONNECTEX;
117 	const GUID WSAID_CONNECTEX = {0x25a207b9,0xddf3,0x4660,[0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e]};
118 }
119 
120 version(Win32_Winsock1) {
121 } else {
122 	static if (_WIN32_WINNT > 0x501) {
123 		/*	These appear to be constants for the TRANSMIT_PACKETS_ELEMENT
124 		 *	structure below, so I've given them the same minimum version
125 		 */
126 		enum {
127 			TP_ELEMENT_FILE   = 1,
128 			TP_ELEMENT_MEMORY = 2,
129 			TP_ELEMENT_EOP    = 4
130 		}
131 
132 		/*	WinXP+, Srv2k3+
133 		 *	ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/transmit_packets_element_2.htm
134 		 */
135 		struct TRANSMIT_PACKETS_ELEMENT {
136 			ULONG dwElFlags;
137 			ULONG cLength;
138 			union {
139 				struct {
140 					LARGE_INTEGER nFileOffset;
141 					HANDLE        hFile;
142 				}
143 				PVOID pBuffer;
144 			}
145 		}
146 
147 		/*	WinXP+, Server2003+:
148 		 *	ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsamsg_2.htm
149 		 */
150 		struct WSAMSG {
151 			LPSOCKADDR name;
152 			INT        namelen;
153 			LPWSABUF   lpBuffers;
154 			DWORD      dwBufferCount;
155 			WSABUF     Control;
156 			DWORD      dwFlags;
157 		}
158 
159 		alias WSAMSG* PWSAMSG, LPWSAMSG;
160 
161 		/* According to MSDN docs, the WSAMSG.Control buffer starts with a
162 		   cmsghdr header of the following form.  See also RFC 2292. */
163 		/* DK: Confirmed.  So I suppose these should get the same version as
164 		   WSAMSG... */
165 		struct WSACMSGHDR {
166 			UINT cmsg_len;
167 			INT  cmsg_level;
168 			INT  cmsg_type;
169 			// followed by UCHAR cmsg_data[];
170 		}
171 
172 		/* TODO: Standard Posix.1g macros as per RFC 2292, with WSA_uglification. */
173 		/* DK: MinGW doesn't define these, and neither does the MSDN docs.  Might have
174 		   to actually look up RFC 2292... */
175 		/+
176 		#if 0
177 		#define WSA_CMSG_FIRSTHDR(mhdr)
178 		#define WSA_CMSG_NXTHDR(mhdr, cmsg)
179 		#define WSA_CMSG_SPACE(length)
180 		#define WSA_CMSG_LEN(length)
181 		#endif
182 		+/
183 
184 		extern(Windows)
185 		{
186 			/*	WinXP+, Srv2k3+
187 			 *	ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/disconnectex_2.htm
188 			 */
189 			BOOL DisconnectEx(SOCKET, LPOVERLAPPED, DWORD, DWORD);
190 
191 			/*	WinXP+, Srv2k3+
192 			 *	ms-help://MS.MSDNQTR.2003FEB.1033/winsock/winsock/wsarecvmsg_2.htm
193 			 */
194 			int WSARecvMsg(SOCKET, LPWSAMSG, LPDWORD, LPWSAOVERLAPPED, LPWSAOVERLAPPED_COMPLETION_ROUTINE);
195 		}
196 	}
197 }