1 // Copyright © 2015, Peter Atashian
2 // Licensed under the MIT License <LICENSE.md>
3 //! definitions to be used with the WinSock 2 DLL and WinSock 2 applications.
4 //!
5 //! This header file corresponds to version 2.2.x of the WinSock API specification.
6 pub const WINSOCK_VERSION: ::WORD = 2 | (2 << 8);
7 pub type u_char = ::c_uchar;
8 pub type u_short = ::c_ushort;
9 pub type u_int = ::c_uint;
10 pub type u_long = ::c_ulong;
11 pub type u_int64 = ::__uint64;
12 pub type SOCKET = ::UINT_PTR;
13 pub type GROUP = ::c_uint;
14 pub const FD_SETSIZE: usize = 64;
15 pub const FD_MAX_EVENTS: usize = 10;
16 STRUCT!{nodebug struct fd_set {
17     fd_count: u_int,
18     fd_array: [SOCKET; FD_SETSIZE],
19 }}
20 STRUCT!{struct timeval {
21     tv_sec: ::c_long,
22     tv_usec: ::c_long,
23 }}
24 STRUCT!{struct hostent {
25     h_name: *mut ::c_char,
26     h_aliases: *mut *mut ::c_char,
27     h_addrtype: ::c_short,
28     h_length: ::c_short,
29     h_addr_list: *mut *mut ::c_char,
30 }}
31 STRUCT!{struct netent {
32     n_name: *mut ::c_char,
33     n_aliases: *mut *mut ::c_char,
34     n_addrtype: ::c_short,
35     n_net: u_long,
36 }}
37 #[cfg(target_arch="x86")]
38 STRUCT!{struct servent {
39     s_name: *mut ::c_char,
40     s_aliases: *mut *mut ::c_char,
41     s_port: ::c_short,
42     s_proto: *mut ::c_char,
43 }}
44 #[cfg(target_arch="x86_64")]
45 STRUCT!{struct servent {
46     s_name: *mut ::c_char,
47     s_aliases: *mut *mut ::c_char,
48     s_proto: *mut ::c_char,
49     s_port: ::c_short,
50 }}
51 STRUCT!{struct protoent {
52     p_name: *mut ::c_char,
53     p_aliases: *mut *mut ::c_char,
54     p_proto: ::c_short,
55 }}
56 pub const WSADESCRIPTION_LEN: usize = 256;
57 pub const WSASYS_STATUS_LEN: usize = 128;
58 #[cfg(target_arch="x86")]
59 STRUCT!{nodebug struct WSADATA {
60     wVersion: ::WORD,
61     wHighVersion: ::WORD,
62     szDescription: [::c_char; WSADESCRIPTION_LEN + 1],
63     szSystemStatus: [::c_char; WSASYS_STATUS_LEN + 1],
64     iMaxSockets: ::c_ushort,
65     iMaxUdpDg: ::c_ushort,
66     lpVendorInfo: *mut ::c_char,
67 }}
68 #[cfg(target_arch="x86_64")]
69 STRUCT!{nodebug struct WSADATA {
70     wVersion: ::WORD,
71     wHighVersion: ::WORD,
72     iMaxSockets: ::c_ushort,
73     iMaxUdpDg: ::c_ushort,
74     lpVendorInfo: *mut ::c_char,
75     szDescription: [::c_char; WSADESCRIPTION_LEN + 1],
76     szSystemStatus: [::c_char; WSASYS_STATUS_LEN + 1],
77 }}
78 pub type LPWSADATA = *mut WSADATA;
79 //391
80 pub const INVALID_SOCKET: SOCKET = !0;
81 pub const SOCKET_ERROR: ::c_int = -1;
82 STRUCT!{struct sockproto {
83     sp_family: u_short,
84     sp_protocol: u_short,
85 }}
86 pub const PF_UNSPEC: ::c_int = ::AF_UNSPEC;
87 pub const PF_UNIX: ::c_int = ::AF_UNIX;
88 pub const PF_INET: ::c_int = ::AF_INET;
89 pub const PF_IMPLINK: ::c_int = ::AF_IMPLINK;
90 pub const PF_PUP: ::c_int = ::AF_PUP;
91 pub const PF_CHAOS: ::c_int = ::AF_CHAOS;
92 pub const PF_NS: ::c_int = ::AF_NS;
93 pub const PF_IPX: ::c_int = ::AF_IPX;
94 pub const PF_ISO: ::c_int = ::AF_ISO;
95 pub const PF_OSI: ::c_int = ::AF_OSI;
96 pub const PF_ECMA: ::c_int = ::AF_ECMA;
97 pub const PF_DATAKIT: ::c_int = ::AF_DATAKIT;
98 pub const PF_CCITT: ::c_int = ::AF_CCITT;
99 pub const PF_SNA: ::c_int = ::AF_SNA;
100 pub const PF_DECnet: ::c_int = ::AF_DECnet;
101 pub const PF_DLI: ::c_int = ::AF_DLI;
102 pub const PF_LAT: ::c_int = ::AF_LAT;
103 pub const PF_HYLINK: ::c_int = ::AF_HYLINK;
104 pub const PF_APPLETALK: ::c_int = ::AF_APPLETALK;
105 pub const PF_VOICEVIEW: ::c_int = ::AF_VOICEVIEW;
106 pub const PF_FIREFOX: ::c_int = ::AF_FIREFOX;
107 pub const PF_UNKNOWN1: ::c_int = ::AF_UNKNOWN1;
108 pub const PF_BAN: ::c_int = ::AF_BAN;
109 pub const PF_ATM: ::c_int = ::AF_ATM;
110 pub const PF_INET6: ::c_int = ::AF_INET6;
111 pub const PF_BTH: ::c_int = ::AF_BTH;
112 pub const PF_MAX: ::c_int = ::AF_MAX;
113 STRUCT!{struct linger {
114     l_onoff: u_short,
115     l_linger: u_short,
116 }}
117 pub const SOMAXCONN: ::c_int = 0x7fffffff;
118 pub type WSAEVENT = ::HANDLE;
119 pub type LPWSAEVENT = ::LPHANDLE;
120 pub type WSAOVERLAPPED = ::OVERLAPPED;
121 pub type LPWSAOVERLAPPED = *mut ::OVERLAPPED;
122 pub const WSA_IO_PENDING: ::DWORD = ::ERROR_IO_PENDING;
123 pub const WSA_IO_INCOMPLETE: ::DWORD = ::ERROR_IO_INCOMPLETE;
124 pub const WSA_INVALID_HANDLE: ::DWORD = ::ERROR_INVALID_HANDLE;
125 pub const WSA_INVALID_PARAMETER: ::DWORD = ::ERROR_INVALID_PARAMETER;
126 pub const WSA_NOT_ENOUGH_MEMORY: ::DWORD = ::ERROR_NOT_ENOUGH_MEMORY;
127 pub const WSA_OPERATION_ABORTED: ::DWORD = ::ERROR_OPERATION_ABORTED;
128 STRUCT!{struct QOS {
129     SendingFlowspec: ::FLOWSPEC,
130     FLOWSPEC: ::FLOWSPEC,
131     ProviderSpecific: ::WSABUF,
132 }}
133 pub type LPQOS = *mut QOS;
134 STRUCT!{struct WSANETWORKEVENTS {
135     lNetworkEvents: ::c_long,
136     iErrorCode: [::c_int; FD_MAX_EVENTS],
137 }}
138 pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS;
139 pub const MAX_PROTOCOL_CHAIN: usize = 7;
140 STRUCT!{struct WSAPROTOCOLCHAIN {
141     ChainLen: ::c_int,
142     ChainEntries: [::DWORD; MAX_PROTOCOL_CHAIN],
143 }}
144 pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN;
145 pub const WSAPROTOCOL_LEN: usize = 255;
146 STRUCT!{nodebug struct WSAPROTOCOL_INFOA {
147     dwServiceFlags1: ::DWORD,
148     dwServiceFlags2: ::DWORD,
149     dwServiceFlags3: ::DWORD,
150     dwServiceFlags4: ::DWORD,
151     dwServiceFlags5: ::DWORD,
152     ProviderId: ::GUID,
153     dwCatalogEntryId: ::DWORD,
154     ProtocolChain: WSAPROTOCOLCHAIN,
155     iVersion: ::c_int,
156     iAddressFamily: ::c_int,
157     iMaxSockAddr: ::c_int,
158     iMinSockAddr: ::c_int,
159     iSocketType: ::c_int,
160     iProtocol: ::c_int,
161     iProtocolMaxOffset: ::c_int,
162     iNetworkByteOrder: ::c_int,
163     iSecurityScheme: ::c_int,
164     dwMessageSize: ::DWORD,
165     dwProviderReserved: ::DWORD,
166     szProtocol: [::CHAR; WSAPROTOCOL_LEN + 1],
167 }}
168 pub type LPWSAPROTOCOL_INFOA = *mut WSAPROTOCOL_INFOA;
169 STRUCT!{nodebug struct WSAPROTOCOL_INFOW {
170     dwServiceFlags1: ::DWORD,
171     dwServiceFlags2: ::DWORD,
172     dwServiceFlags3: ::DWORD,
173     dwServiceFlags4: ::DWORD,
174     dwServiceFlags5: ::DWORD,
175     ProviderId: ::GUID,
176     dwCatalogEntryId: ::DWORD,
177     ProtocolChain: WSAPROTOCOLCHAIN,
178     iVersion: ::c_int,
179     iAddressFamily: ::c_int,
180     iMaxSockAddr: ::c_int,
181     iMinSockAddr: ::c_int,
182     iSocketType: ::c_int,
183     iProtocol: ::c_int,
184     iProtocolMaxOffset: ::c_int,
185     iNetworkByteOrder: ::c_int,
186     iSecurityScheme: ::c_int,
187     dwMessageSize: ::DWORD,
188     dwProviderReserved: ::DWORD,
189     szProtocol: [::WCHAR; WSAPROTOCOL_LEN + 1],
190 }}
191 pub type LPWSAPROTOCOL_INFOW = *mut WSAPROTOCOL_INFOW;
192 pub type LPCONDITIONPROC = Option<unsafe extern "system" fn(
193     lpCallerId: ::LPWSABUF, lpCallerData: ::LPWSABUF, lpSQOS: LPQOS, lpGQOS: LPQOS,
194     lpCalleeId: ::LPWSABUF, lpCalleeData: ::LPWSABUF, g: *mut GROUP, dwCallbackData: ::DWORD,
195 ) -> ::c_int>;
196 pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = Option<unsafe extern "system" fn(
197     dwError: ::DWORD, cbTransferred: ::DWORD, lpOverlapped: LPWSAOVERLAPPED, dwFlags: ::DWORD,
198 )>;
199 ENUM!{enum WSACOMPLETIONTYPE {
200     NSP_NOTIFY_IMMEDIATELY = 0,
201     NSP_NOTIFY_HWND,
202     NSP_NOTIFY_EVENT,
203     NSP_NOTIFY_PORT,
204     NSP_NOTIFY_APC,
205 }}
206 pub type PWSACOMPLETIONTYPE = *mut WSACOMPLETIONTYPE;
207 pub type LPWSACOMPLETIONTYPE = *mut WSACOMPLETIONTYPE;
208 STRUCT!{struct WSACOMPLETION_WindowMessage {
209     hWnd: ::HWND,
210     uMsg: ::UINT,
211     context: ::WPARAM,
212 }}
213 STRUCT!{struct WSACOMPLETION_Event {
214     lpOverlapped: LPWSAOVERLAPPED,
215 }}
216 STRUCT!{nodebug struct WSACOMPLETION_Apc {
217     lpOverlapped: LPWSAOVERLAPPED,
218     lpfnCompletionProc: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
219 }}
220 STRUCT!{struct WSACOMPLETION_Port {
221     lpOverlapped: LPWSAOVERLAPPED,
222     hPort: ::HANDLE,
223     Key: ::ULONG_PTR,
224 }}
225 #[cfg(target_arch="x86")]
226 STRUCT!{struct WSACOMPLETION {
227     Type: WSACOMPLETIONTYPE,
228     Parameters: [u8; 12],
229 }}
230 #[cfg(target_arch="x86_64")]
231 STRUCT!{struct WSACOMPLETION {
232     Type: WSACOMPLETIONTYPE,
233     Parameters: [u8; 24],
234 }}
235 UNION!(WSACOMPLETION, Parameters, WindowMessage, WindowMessage_mut, WSACOMPLETION_WindowMessage);
236 UNION!(WSACOMPLETION, Parameters, Event, Event_mut, WSACOMPLETION_Event);
237 UNION!(WSACOMPLETION, Parameters, Apc, Apc_mut, WSACOMPLETION_Apc);
238 UNION!(WSACOMPLETION, Parameters, Port, Port_mut, WSACOMPLETION_Port);
239 pub type PWSACOMPLETION = *mut WSACOMPLETION;
240 pub type LPWSACOMPLETION = *mut WSACOMPLETION;
241 STRUCT!{struct AFPROTOCOLS {
242     iAddressFamily: ::INT,
243     iProtocol: ::INT,
244 }}
245 pub type PAFPROTOCOLS = *mut AFPROTOCOLS;
246 pub type LPAFPROTOCOLS = *mut AFPROTOCOLS;
247 ENUM!{enum WSAECOMPARATOR {
248     COMP_EQUAL = 0,
249     COMP_NOTLESS,
250 }}
251 pub type PWSAECOMPARATOR = *mut WSAECOMPARATOR;
252 pub type LPWSAECOMPARATOR = *mut WSAECOMPARATOR;
253 STRUCT!{struct WSAVERSION {
254     dwVersion: ::DWORD,
255     ecHow: WSAECOMPARATOR,
256 }}
257 pub type PWSAVERSION = *mut WSAVERSION;
258 pub type LPWSAVERSION = *mut WSAVERSION;
259 STRUCT!{struct WSAQUERYSETA {
260     dwSize: ::DWORD,
261     lpszServiceInstanceName: ::LPSTR,
262     lpServiceClassId: ::LPGUID,
263     lpVersion: LPWSAVERSION,
264     lpszComment: ::LPSTR,
265     dwNameSpace: ::DWORD,
266     lpNSProviderId: ::LPGUID,
267     lpszContext: ::LPSTR,
268     dwNumberOfProtocols: ::DWORD,
269     lpafpProtocols: LPAFPROTOCOLS,
270     lpszQueryString: ::LPSTR,
271     dwNumberOfCsAddrs: ::DWORD,
272     lpcsaBuffer: ::LPCSADDR_INFO,
273     dwOutputFlags: ::DWORD,
274     lpBlob: ::LPBLOB,
275 }}
276 pub type PWSAQUERYSETA = *mut WSAQUERYSETA;
277 pub type LPWSAQUERYSETA = *mut WSAQUERYSETA;
278 STRUCT!{struct WSAQUERYSETW {
279     dwSize: ::DWORD,
280     lpszServiceInstanceName: ::LPWSTR,
281     lpServiceClassId: ::LPGUID,
282     lpVersion: LPWSAVERSION,
283     lpszComment: ::LPWSTR,
284     dwNameSpace: ::DWORD,
285     lpNSProviderId: ::LPGUID,
286     lpszContext: ::LPWSTR,
287     dwNumberOfProtocols: ::DWORD,
288     lpafpProtocols: LPAFPROTOCOLS,
289     lpszQueryString: ::LPWSTR,
290     dwNumberOfCsAddrs: ::DWORD,
291     lpcsaBuffer: ::LPCSADDR_INFO,
292     dwOutputFlags: ::DWORD,
293     lpBlob: ::LPBLOB,
294 }}
295 pub type PWSAQUERYSETW = *mut WSAQUERYSETW;
296 pub type LPWSAQUERYSETW = *mut WSAQUERYSETW;
297 STRUCT!{struct WSAQUERYSET2A {
298     dwSize: ::DWORD,
299     lpszServiceInstanceName: ::LPSTR,
300     lpVersion: LPWSAVERSION,
301     lpszComment: ::LPSTR,
302     dwNameSpace: ::DWORD,
303     lpNSProviderId: ::LPGUID,
304     lpszContext: ::LPSTR,
305     dwNumberOfProtocols: ::DWORD,
306     lpafpProtocols: LPAFPROTOCOLS,
307     lpszQueryString: ::LPSTR,
308     dwNumberOfCsAddrs: ::DWORD,
309     lpcsaBuffer: ::LPCSADDR_INFO,
310     dwOutputFlags: ::DWORD,
311     lpBlob: ::LPBLOB,
312 }}
313 pub type PWSAQUERYSET2A = *mut WSAQUERYSET2A;
314 pub type LPWSAQUERYSET2A = *mut WSAQUERYSET2A;
315 STRUCT!{struct WSAQUERYSET2W {
316     dwSize: ::DWORD,
317     lpszServiceInstanceName: ::LPWSTR,
318     lpVersion: LPWSAVERSION,
319     lpszComment: ::LPWSTR,
320     dwNameSpace: ::DWORD,
321     lpNSProviderId: ::LPGUID,
322     lpszContext: ::LPWSTR,
323     dwNumberOfProtocols: ::DWORD,
324     lpafpProtocols: LPAFPROTOCOLS,
325     lpszQueryString: ::LPWSTR,
326     dwNumberOfCsAddrs: ::DWORD,
327     lpcsaBuffer: ::LPCSADDR_INFO,
328     dwOutputFlags: ::DWORD,
329     lpBlob: ::LPBLOB,
330 }}
331 pub type PWSAQUERYSET2W = *mut WSAQUERYSET2W;
332 pub type LPWSAQUERYSET2W = *mut WSAQUERYSET2W;
333 ENUM!{enum WSAESETSERVICEOP {
334     RNRSERVICE_REGISTER = 0,
335     RNRSERVICE_DEREGISTER,
336     RNRSERVICE_DELETE,
337 }}
338 pub type PWSAESETSERVICEOP = *mut WSAESETSERVICEOP;
339 pub type LPWSAESETSERVICEOP = *mut WSAESETSERVICEOP;
340 STRUCT!{struct WSANSCLASSINFOA {
341     lpszName: ::LPSTR,
342     dwNameSpace: ::DWORD,
343     dwValueType: ::DWORD,
344     dwValueSize: ::DWORD,
345     lpValue: ::LPVOID,
346 }}
347 pub type PWSANSCLASSINFOA = *mut WSANSCLASSINFOA;
348 pub type LPWSANSCLASSINFOA = *mut WSANSCLASSINFOA;
349 STRUCT!{struct WSANSCLASSINFOW {
350     lpszName: ::LPWSTR,
351     dwNameSpace: ::DWORD,
352     dwValueType: ::DWORD,
353     dwValueSize: ::DWORD,
354     lpValue: ::LPVOID,
355 }}
356 pub type PWSANSCLASSINFOW = *mut WSANSCLASSINFOW;
357 pub type LPWSANSCLASSINFOW = *mut WSANSCLASSINFOW;
358 STRUCT!{struct WSASERVICECLASSINFOA {
359     lpServiceClassId: ::LPGUID,
360     lpszServiceClassName: ::LPSTR,
361     dwCount: ::DWORD,
362     lpClassInfos: LPWSANSCLASSINFOA,
363 }}
364 pub type PWSASERVICECLASSINFOA = *mut WSASERVICECLASSINFOA;
365 pub type LPWSASERVICECLASSINFOA = *mut WSASERVICECLASSINFOA;
366 STRUCT!{struct WSASERVICECLASSINFOW {
367     lpServiceClassId: ::LPGUID,
368     lpszServiceClassName: ::LPWSTR,
369     dwCount: ::DWORD,
370     lpClassInfos: LPWSANSCLASSINFOW,
371 }}
372 pub type PWSASERVICECLASSINFOW = *mut WSASERVICECLASSINFOW;
373 pub type LPWSASERVICECLASSINFOW = *mut WSASERVICECLASSINFOW;
374 STRUCT!{struct WSANAMESPACE_INFOA {
375     NSProviderId: ::GUID,
376     dwNameSpace: ::DWORD,
377     fActive: ::BOOL,
378     dwVersion: ::DWORD,
379     lpszIdentifier: ::LPSTR,
380 }}
381 pub type PWSANAMESPACE_INFOA = *mut WSANAMESPACE_INFOA;
382 pub type LPWSANAMESPACE_INFOA = *mut WSANAMESPACE_INFOA;
383 STRUCT!{struct WSANAMESPACE_INFOW {
384     NSProviderId: ::GUID,
385     dwNameSpace: ::DWORD,
386     fActive: ::BOOL,
387     dwVersion: ::DWORD,
388     lpszIdentifier: ::LPWSTR,
389 }}
390 pub type PWSANAMESPACE_INFOW = *mut WSANAMESPACE_INFOW;
391 pub type LPWSANAMESPACE_INFOW = *mut WSANAMESPACE_INFOW;
392 STRUCT!{struct WSANAMESPACE_INFOEXA {
393     NSProviderId: ::GUID,
394     dwNameSpace: ::DWORD,
395     fActive: ::BOOL,
396     dwVersion: ::DWORD,
397     lpszIdentifier: ::LPSTR,
398     ProviderSpecific: ::BLOB,
399 }}
400 pub type PWSANAMESPACE_INFOEXA = *mut WSANAMESPACE_INFOEXA;
401 pub type LPWSANAMESPACE_INFOEXA = *mut WSANAMESPACE_INFOEXA;
402 STRUCT!{struct WSANAMESPACE_INFOEXW {
403     NSProviderId: ::GUID,
404     dwNameSpace: ::DWORD,
405     fActive: ::BOOL,
406     dwVersion: ::DWORD,
407     lpszIdentifier: ::LPWSTR,
408     ProviderSpecific: ::BLOB,
409 }}
410 pub type PWSANAMESPACE_INFOEXW = *mut WSANAMESPACE_INFOEXW;
411 pub type LPWSANAMESPACE_INFOEXW = *mut WSANAMESPACE_INFOEXW;
412 pub const POLLRDNORM: ::SHORT = 0x0100;
413 pub const POLLRDBAND: ::SHORT = 0x0200;
414 pub const POLLIN: ::SHORT = POLLRDNORM | POLLRDBAND;
415 pub const POLLPRI: ::SHORT = 0x0400;
416 pub const POLLWRNORM: ::SHORT = 0x0010;
417 pub const POLLOUT: ::SHORT = POLLWRNORM;
418 pub const POLLWRBAND: ::SHORT = 0x0020;
419 pub const POLLERR: ::SHORT = 0x0001;
420 pub const POLLHUP: ::SHORT = 0x0002;
421 pub const POLLNVAL: ::SHORT = 0x0004;
422 STRUCT!{struct WSAPOLLFD {
423     fd: ::SOCKET,
424     events: ::SHORT,
425     revents: ::SHORT,
426 }}
427 pub type PWSAPOLLFD = *mut WSAPOLLFD;
428 pub type LPWSAPOLLFD = *mut WSAPOLLFD;
429 pub const FIONBIO: ::c_ulong = 0x8004667e;
430