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