1use ctypes::{
8 __uint32, __uint64, c_char, c_double, c_float, c_int, c_long, c_short, c_uchar, c_uint,
9 c_ulong, c_ushort,
10};
11use shared::basetsd::{DWORD_PTR, UINT_PTR, ULONG_PTR};
12use shared::guiddef::{GUID, LPGUID};
13use shared::inaddr::in_addr;
14use shared::minwindef::{
15 BOOL, DWORD, FARPROC, HIWORD, INT, LOWORD, LPDWORD, LPHANDLE, LPINT, LPVOID, MAKELONG, UINT,
16 ULONG, WORD, WPARAM,
17};
18use shared::qos::FLOWSPEC;
19use shared::windef::HWND;
20use shared::winerror::{
21 ERROR_INVALID_HANDLE, ERROR_INVALID_PARAMETER, ERROR_IO_INCOMPLETE, ERROR_IO_PENDING,
22 ERROR_NOT_ENOUGH_MEMORY, ERROR_OPERATION_ABORTED, WAIT_TIMEOUT,
23};
24use shared::ws2def::{
25 AF_APPLETALK, AF_ATM, AF_BAN, AF_BTH, AF_CCITT, AF_CHAOS, AF_DATAKIT, AF_DECnet, AF_DLI,
26 AF_ECMA, AF_FIREFOX, AF_HYLINK, AF_IMPLINK, AF_INET, AF_INET6, AF_IPX, AF_ISO, AF_LAT,
27 AF_MAX, AF_NS, AF_OSI, AF_PUP, AF_SNA, AF_UNIX, AF_UNKNOWN1, AF_UNSPEC, AF_VOICEVIEW,
28 INADDR_ANY, LPCSADDR_INFO, LPSOCKADDR, LPWSABUF, LPWSAMSG, PSOCKET_ADDRESS_LIST, SOCKADDR,
29 SOCKADDR_IN, WSABUF,
30};
31use shared::wtypesbase::{BLOB, LPBLOB};
32use um::minwinbase::OVERLAPPED;
33use um::winbase::{INFINITE, WAIT_FAILED, WAIT_IO_COMPLETION, WAIT_OBJECT_0};
34use um::winnt::{
35 CHAR, HANDLE, LONG, LPCSTR, LPSTR, LPWSTR, MAXIMUM_WAIT_OBJECTS, PWSTR, SHORT, WCHAR,
36};
37pub const WINSOCK_VERSION: WORD = 2 | (2 << 8);
38pub type u_char = c_uchar;
39pub type u_short = c_ushort;
40pub type u_int = c_uint;
41pub type u_long = c_ulong;
42pub type u_int64 = __uint64;
43pub type SOCKET = UINT_PTR;
44pub const FD_SETSIZE: usize = 64;
45STRUCT!{struct fd_set {
46 fd_count: u_int,
47 fd_array: [SOCKET; FD_SETSIZE],
48}}
49extern "system" {
50 pub fn __WSAFDIsSet(
51 fd: SOCKET,
52 _: *mut fd_set,
53 ) -> c_int;
54}
55STRUCT!{struct timeval {
56 tv_sec: c_long,
57 tv_usec: c_long,
58}}
59pub const IOCPARM_MASK: c_long = 0x7f;
60pub const IOC_VOID: c_long = 0x20000000;
61pub const IOC_OUT: c_long = 0x40000000;
62pub const IOC_IN: c_long = 0x80000000;
63pub const IOC_INOUT: c_long = IOC_IN | IOC_OUT;
64pub const FIONREAD: c_long = IOC_OUT | ((4 & IOCPARM_MASK) << 16) | (0x66 << 8) | 127;
65pub const FIONBIO: c_long = IOC_IN | ((4 & IOCPARM_MASK) << 16) | (0x66 << 8) | 126;
66pub const FIOASYNC: c_long = IOC_IN | ((4 & IOCPARM_MASK) << 16) | (0x66 << 8) | 125;
67pub const SIOCSHIWAT: c_long = IOC_IN | ((4 & IOCPARM_MASK) << 16) | (0x73 << 8) | 0;
68pub const SIOCGHIWAT: c_long = IOC_OUT | ((4 & IOCPARM_MASK) << 16) | (0x73 << 8) | 1;
69pub const SIOCSLOWAT: c_long = IOC_IN | ((4 & IOCPARM_MASK) << 16) | (0x73 << 8) | 2;
70pub const SIOCGLOWAT: c_long = IOC_OUT | ((4 & IOCPARM_MASK) << 16) | (0x73 << 8) | 3;
71pub const SIOCATMARK: c_long = IOC_OUT | ((4 & IOCPARM_MASK) << 16) | (0x73 << 8) | 7;
72STRUCT!{struct hostent {
73 h_name: *mut c_char,
74 h_aliases: *mut *mut c_char,
75 h_addrtype: c_short,
76 h_length: c_short,
77 h_addr_list: *mut *mut c_char,
78}}
79STRUCT!{struct netent {
80 n_name: *mut c_char,
81 n_aliases: *mut *mut c_char,
82 n_addrtype: c_short,
83 n_net: u_long,
84}}
85#[cfg(target_pointer_width = "32")]
86STRUCT!{struct servent {
87 s_name: *mut c_char,
88 s_aliases: *mut *mut c_char,
89 s_port: c_short,
90 s_proto: *mut c_char,
91}}
92#[cfg(target_pointer_width = "64")]
93STRUCT!{struct servent {
94 s_name: *mut c_char,
95 s_aliases: *mut *mut c_char,
96 s_proto: *mut c_char,
97 s_port: c_short,
98}}
99STRUCT!{struct protoent {
100 p_name: *mut c_char,
101 p_aliases: *mut *mut c_char,
102 p_proto: c_short,
103}}
104pub const IPPORT_ECHO: c_short = 7;
105pub const IPPORT_DISCARD: c_short = 9;
106pub const IPPORT_SYSTAT: c_short = 11;
107pub const IPPORT_DAYTIME: c_short = 13;
108pub const IPPORT_NETSTAT: c_short = 15;
109pub const IPPORT_FTP: c_short = 21;
110pub const IPPORT_TELNET: c_short = 23;
111pub const IPPORT_SMTP: c_short = 25;
112pub const IPPORT_TIMESERVER: c_short = 37;
113pub const IPPORT_NAMESERVER: c_short = 42;
114pub const IPPORT_WHOIS: c_short = 43;
115pub const IPPORT_MTP: c_short = 57;
116pub const IPPORT_TFTP: c_short = 69;
117pub const IPPORT_RJE: c_short = 77;
118pub const IPPORT_FINGER: c_short = 79;
119pub const IPPORT_TTYLINK: c_short = 87;
120pub const IPPORT_SUPDUP: c_short = 95;
121pub const IPPORT_EXECSERVER: c_short = 512;
122pub const IPPORT_LOGINSERVER: c_short = 513;
123pub const IPPORT_CMDSERVER: c_short = 514;
124pub const IPPORT_EFSSERVER: c_short = 520;
125pub const IPPORT_BIFFUDP: c_short = 512;
126pub const IPPORT_WHOSERVER: c_short = 513;
127pub const IPPORT_ROUTESERVER: c_short = 520;
128pub const IPPORT_RESERVED: c_short = 1024;
129pub const IMPLINK_IP: c_short = 155;
130pub const IMPLINK_LOWEXPER: c_short = 156;
131pub const IMPLINK_HIGHEXPER: c_short = 158;
132pub const ADDR_ANY: ULONG = INADDR_ANY;
133pub const WSADESCRIPTION_LEN: usize = 256;
134pub const WSASYS_STATUS_LEN: usize = 128;
135#[cfg(target_pointer_width = "32")]
136STRUCT!{struct WSADATA {
137 wVersion: WORD,
138 wHighVersion: WORD,
139 szDescription: [c_char; WSADESCRIPTION_LEN + 1],
140 szSystemStatus: [c_char; WSASYS_STATUS_LEN + 1],
141 iMaxSockets: c_ushort,
142 iMaxUdpDg: c_ushort,
143 lpVendorInfo: *mut c_char,
144}}
145#[cfg(target_pointer_width = "64")]
146STRUCT!{struct WSADATA {
147 wVersion: WORD,
148 wHighVersion: WORD,
149 iMaxSockets: c_ushort,
150 iMaxUdpDg: c_ushort,
151 lpVendorInfo: *mut c_char,
152 szDescription: [c_char; WSADESCRIPTION_LEN + 1],
153 szSystemStatus: [c_char; WSASYS_STATUS_LEN + 1],
154}}
155pub type LPWSADATA = *mut WSADATA;
156pub const INVALID_SOCKET: SOCKET = !0;
157pub const SOCKET_ERROR: c_int = -1;
158pub const FROM_PROTOCOL_INFO: c_int = -1;
159pub const SOCK_STREAM: c_int = 1;
160pub const SOCK_DGRAM: c_int = 2;
161pub const SOCK_RAW: c_int = 3;
162pub const SOCK_RDM: c_int = 4;
163pub const SOCK_SEQPACKET: c_int = 5;
164pub const SO_DEBUG: c_int = 0x0001;
165pub const SO_ACCEPTCONN: c_int = 0x0002;
166pub const SO_REUSEADDR: c_int = 0x0004;
167pub const SO_KEEPALIVE: c_int = 0x0008;
168pub const SO_DONTROUTE: c_int = 0x0010;
169pub const SO_BROADCAST: c_int = 0x0020;
170pub const SO_USELOOPBACK: c_int = 0x0040;
171pub const SO_LINGER: c_int = 0x0080;
172pub const SO_OOBINLINE: c_int = 0x0100;
173pub const SO_DONTLINGER: c_int = !SO_LINGER;
174pub const SO_EXCLUSIVEADDRUSE: c_int = !SO_REUSEADDR;
175pub const SO_SNDBUF: c_int = 0x1001;
176pub const SO_RCVBUF: c_int = 0x1002;
177pub const SO_SNDLOWAT: c_int = 0x1003;
178pub const SO_RCVLOWAT: c_int = 0x1004;
179pub const SO_SNDTIMEO: c_int = 0x1005;
180pub const SO_RCVTIMEO: c_int = 0x1006;
181pub const SO_ERROR: c_int = 0x1007;
182pub const SO_TYPE: c_int = 0x1008;
183pub const SO_GROUP_ID: c_int = 0x2001;
184pub const SO_GROUP_PRIORITY: c_int = 0x2002;
185pub const SO_MAX_MSG_SIZE: c_int = 0x2003;
186pub const SO_PROTOCOL_INFOA: c_int = 0x2004;
187pub const SO_PROTOCOL_INFOW: c_int = 0x2005;
188pub const PVD_CONFIG: c_int = 0x3001;
189pub const SO_CONDITIONAL_ACCEPT: c_int = 0x3002;
190STRUCT!{struct sockproto {
191 sp_family: u_short,
192 sp_protocol: u_short,
193}}
194pub const PF_UNSPEC: c_int = AF_UNSPEC;
195pub const PF_UNIX: c_int = AF_UNIX;
196pub const PF_INET: c_int = AF_INET;
197pub const PF_IMPLINK: c_int = AF_IMPLINK;
198pub const PF_PUP: c_int = AF_PUP;
199pub const PF_CHAOS: c_int = AF_CHAOS;
200pub const PF_NS: c_int = AF_NS;
201pub const PF_IPX: c_int = AF_IPX;
202pub const PF_ISO: c_int = AF_ISO;
203pub const PF_OSI: c_int = AF_OSI;
204pub const PF_ECMA: c_int = AF_ECMA;
205pub const PF_DATAKIT: c_int = AF_DATAKIT;
206pub const PF_CCITT: c_int = AF_CCITT;
207pub const PF_SNA: c_int = AF_SNA;
208pub const PF_DECnet: c_int = AF_DECnet;
209pub const PF_DLI: c_int = AF_DLI;
210pub const PF_LAT: c_int = AF_LAT;
211pub const PF_HYLINK: c_int = AF_HYLINK;
212pub const PF_APPLETALK: c_int = AF_APPLETALK;
213pub const PF_VOICEVIEW: c_int = AF_VOICEVIEW;
214pub const PF_FIREFOX: c_int = AF_FIREFOX;
215pub const PF_UNKNOWN1: c_int = AF_UNKNOWN1;
216pub const PF_BAN: c_int = AF_BAN;
217pub const PF_ATM: c_int = AF_ATM;
218pub const PF_INET6: c_int = AF_INET6;
219pub const PF_BTH: c_int = AF_BTH;
220pub const PF_MAX: c_int = AF_MAX;
221STRUCT!{struct linger {
222 l_onoff: u_short,
223 l_linger: u_short,
224}}
225pub const SOL_SOCKET: c_int = 0xffff;
226pub const SOMAXCONN: c_int = 0x7fffffff;
227#[inline]
228pub fn SOMAXCONN_HINT(b: c_int) -> c_int {
229 -b
230}
231pub const MSG_OOB: c_int = 0x1;
232pub const MSG_PEEK: c_int = 0x2;
233pub const MSG_DONTROUTE: c_int = 0x4;
234pub const MSG_WAITALL: c_int = 0x8;
235pub const MSG_PUSH_IMMEDIATE: c_int = 0x20;
236pub const MSG_PARTIAL: c_int = 0x8000;
237pub const MSG_INTERRUPT: c_int = 0x10;
238pub const MSG_MAXIOVLEN: c_int = 16;
239pub const MAXGETHOSTSTRUCT: usize = 1024;
240pub const FD_READ_BIT: c_long = 0;
241pub const FD_READ: c_long = 1 << FD_READ_BIT;
242pub const FD_WRITE_BIT: c_long = 1;
243pub const FD_WRITE: c_long = 1 << FD_WRITE_BIT;
244pub const FD_OOB_BIT: c_long = 2;
245pub const FD_OOB: c_long = 1 << FD_OOB_BIT;
246pub const FD_ACCEPT_BIT: c_long = 3;
247pub const FD_ACCEPT: c_long = 1 << FD_ACCEPT_BIT;
248pub const FD_CONNECT_BIT: c_long = 4;
249pub const FD_CONNECT: c_long = 1 << FD_CONNECT_BIT;
250pub const FD_CLOSE_BIT: c_long = 5;
251pub const FD_CLOSE: c_long = 1 << FD_CLOSE_BIT;
252pub const FD_QOS_BIT: c_long = 6;
253pub const FD_QOS: c_long = 1 << FD_QOS_BIT;
254pub const FD_GROUP_QOS_BIT: c_long = 7;
255pub const FD_GROUP_QOS: c_long = 1 << FD_GROUP_QOS_BIT;
256pub const FD_ROUTING_INTERFACE_CHANGE_BIT: c_long = 8;
257pub const FD_ROUTING_INTERFACE_CHANGE: c_long = 1 << FD_ROUTING_INTERFACE_CHANGE_BIT;
258pub const FD_ADDRESS_LIST_CHANGE_BIT: c_long = 9;
259pub const FD_ADDRESS_LIST_CHANGE: c_long = 1 << FD_ADDRESS_LIST_CHANGE_BIT;
260pub const FD_MAX_EVENTS: usize = 10;
261pub const FD_ALL_EVENTS: c_long = (1 << FD_MAX_EVENTS) - 1;
262pub const WSABASEERR: c_int = 10000;
263pub const WSAEINTR: c_int = WSABASEERR+4;
264pub const WSAEBADF: c_int = WSABASEERR+9;
265pub const WSAEACCES: c_int = WSABASEERR+13;
266pub const WSAEFAULT: c_int = WSABASEERR+14;
267pub const WSAEINVAL: c_int = WSABASEERR+22;
268pub const WSAEMFILE: c_int = WSABASEERR+24;
269pub const WSAEWOULDBLOCK: c_int = WSABASEERR+35;
270pub const WSAEINPROGRESS: c_int = WSABASEERR+36;
271pub const WSAEALREADY: c_int = WSABASEERR+37;
272pub const WSAENOTSOCK: c_int = WSABASEERR+38;
273pub const WSAEDESTADDRREQ: c_int = WSABASEERR+39;
274pub const WSAEMSGSIZE: c_int = WSABASEERR+40;
275pub const WSAEPROTOTYPE: c_int = WSABASEERR+41;
276pub const WSAENOPROTOOPT: c_int = WSABASEERR+42;
277pub const WSAEPROTONOSUPPORT: c_int = WSABASEERR+43;
278pub const WSAESOCKTNOSUPPORT: c_int = WSABASEERR+44;
279pub const WSAEOPNOTSUPP: c_int = WSABASEERR+45;
280pub const WSAEPFNOSUPPORT: c_int = WSABASEERR+46;
281pub const WSAEAFNOSUPPORT: c_int = WSABASEERR+47;
282pub const WSAEADDRINUSE: c_int = WSABASEERR+48;
283pub const WSAEADDRNOTAVAIL: c_int = WSABASEERR+49;
284pub const WSAENETDOWN: c_int = WSABASEERR+50;
285pub const WSAENETUNREACH: c_int = WSABASEERR+51;
286pub const WSAENETRESET: c_int = WSABASEERR+52;
287pub const WSAECONNABORTED: c_int = WSABASEERR+53;
288pub const WSAECONNRESET: c_int = WSABASEERR+54;
289pub const WSAENOBUFS: c_int = WSABASEERR+55;
290pub const WSAEISCONN: c_int = WSABASEERR+56;
291pub const WSAENOTCONN: c_int = WSABASEERR+57;
292pub const WSAESHUTDOWN: c_int = WSABASEERR+58;
293pub const WSAETOOMANYREFS: c_int = WSABASEERR+59;
294pub const WSAETIMEDOUT: c_int = WSABASEERR+60;
295pub const WSAECONNREFUSED: c_int = WSABASEERR+61;
296pub const WSAELOOP: c_int = WSABASEERR+62;
297pub const WSAENAMETOOLONG: c_int = WSABASEERR+63;
298pub const WSAEHOSTDOWN: c_int = WSABASEERR+64;
299pub const WSAEHOSTUNREACH: c_int = WSABASEERR+65;
300pub const WSAENOTEMPTY: c_int = WSABASEERR+66;
301pub const WSAEPROCLIM: c_int = WSABASEERR+67;
302pub const WSAEUSERS: c_int = WSABASEERR+68;
303pub const WSAEDQUOT: c_int = WSABASEERR+69;
304pub const WSAESTALE: c_int = WSABASEERR+70;
305pub const WSAEREMOTE: c_int = WSABASEERR+71;
306pub const WSASYSNOTREADY: c_int = WSABASEERR+91;
307pub const WSAVERNOTSUPPORTED: c_int = WSABASEERR+92;
308pub const WSANOTINITIALISED: c_int = WSABASEERR+93;
309pub const WSAEDISCON: c_int = WSABASEERR+101;
310pub const WSAENOMORE: c_int = WSABASEERR+102;
311pub const WSAECANCELLED: c_int = WSABASEERR+103;
312pub const WSAEINVALIDPROCTABLE: c_int = WSABASEERR+104;
313pub const WSAEINVALIDPROVIDER: c_int = WSABASEERR+105;
314pub const WSAEPROVIDERFAILEDINIT: c_int = WSABASEERR+106;
315pub const WSASYSCALLFAILURE: c_int = WSABASEERR+107;
316pub const WSASERVICE_NOT_FOUND: c_int = WSABASEERR+108;
317pub const WSATYPE_NOT_FOUND: c_int = WSABASEERR+109;
318pub const WSA_E_NO_MORE: c_int = WSABASEERR+110;
319pub const WSA_E_CANCELLED: c_int = WSABASEERR+111;
320pub const WSAEREFUSED: c_int = WSABASEERR+112;
321pub const WSAHOST_NOT_FOUND: c_int = WSABASEERR+1001;
322pub const WSATRY_AGAIN: c_int = WSABASEERR+1002;
323pub const WSANO_RECOVERY: c_int = WSABASEERR+1003;
324pub const WSANO_DATA: c_int = WSABASEERR+1004;
325pub const WSA_QOS_RECEIVERS: c_int = WSABASEERR + 1005;
326pub const WSA_QOS_SENDERS: c_int = WSABASEERR + 1006;
327pub const WSA_QOS_NO_SENDERS: c_int = WSABASEERR + 1007;
328pub const WSA_QOS_NO_RECEIVERS: c_int = WSABASEERR + 1008;
329pub const WSA_QOS_REQUEST_CONFIRMED: c_int = WSABASEERR + 1009;
330pub const WSA_QOS_ADMISSION_FAILURE: c_int = WSABASEERR + 1010;
331pub const WSA_QOS_POLICY_FAILURE: c_int = WSABASEERR + 1011;
332pub const WSA_QOS_BAD_STYLE: c_int = WSABASEERR + 1012;
333pub const WSA_QOS_BAD_OBJECT: c_int = WSABASEERR + 1013;
334pub const WSA_QOS_TRAFFIC_CTRL_ERROR: c_int = WSABASEERR + 1014;
335pub const WSA_QOS_GENERIC_ERROR: c_int = WSABASEERR + 1015;
336pub const WSA_QOS_ESERVICETYPE: c_int = WSABASEERR + 1016;
337pub const WSA_QOS_EFLOWSPEC: c_int = WSABASEERR + 1017;
338pub const WSA_QOS_EPROVSPECBUF: c_int = WSABASEERR + 1018;
339pub const WSA_QOS_EFILTERSTYLE: c_int = WSABASEERR + 1019;
340pub const WSA_QOS_EFILTERTYPE: c_int = WSABASEERR + 1020;
341pub const WSA_QOS_EFILTERCOUNT: c_int = WSABASEERR + 1021;
342pub const WSA_QOS_EOBJLENGTH: c_int = WSABASEERR + 1022;
343pub const WSA_QOS_EFLOWCOUNT: c_int = WSABASEERR + 1023;
344pub const WSA_QOS_EUNKOWNPSOBJ: c_int = WSABASEERR + 1024;
345pub const WSA_QOS_EPOLICYOBJ: c_int = WSABASEERR + 1025;
346pub const WSA_QOS_EFLOWDESC: c_int = WSABASEERR + 1026;
347pub const WSA_QOS_EPSFLOWSPEC: c_int = WSABASEERR + 1027;
348pub const WSA_QOS_EPSFILTERSPEC: c_int = WSABASEERR + 1028;
349pub const WSA_QOS_ESDMODEOBJ: c_int = WSABASEERR + 1029;
350pub const WSA_QOS_ESHAPERATEOBJ: c_int = WSABASEERR + 1030;
351pub const WSA_QOS_RESERVED_PETYPE: c_int = WSABASEERR + 1031;
352#[inline]
353pub unsafe fn h_errno() -> c_int {
354 WSAGetLastError()
355}
356pub const HOST_NOT_FOUND: c_int = WSAHOST_NOT_FOUND;
357pub const TRY_AGAIN: c_int = WSATRY_AGAIN;
358pub const NO_RECOVERY: c_int = WSANO_RECOVERY;
359pub const NO_DATA: c_int = WSANO_DATA;
360pub const WSANO_ADDRESS: c_int = WSANO_DATA;
361pub const NO_ADDRESS: c_int = WSANO_ADDRESS;
362pub type WSAEVENT = HANDLE;
363pub type LPWSAEVENT = LPHANDLE;
364pub type WSAOVERLAPPED = OVERLAPPED;
365pub type LPWSAOVERLAPPED = *mut OVERLAPPED;
366pub const WSA_IO_PENDING: c_int = ERROR_IO_PENDING as i32;
367pub const WSA_IO_INCOMPLETE: c_int = ERROR_IO_INCOMPLETE as i32;
368pub const WSA_INVALID_HANDLE: c_int = ERROR_INVALID_HANDLE as i32;
369pub const WSA_INVALID_PARAMETER: c_int = ERROR_INVALID_PARAMETER as i32;
370pub const WSA_NOT_ENOUGH_MEMORY: c_int = ERROR_NOT_ENOUGH_MEMORY as i32;
371pub const WSA_OPERATION_ABORTED: c_int = ERROR_OPERATION_ABORTED as i32;
372pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT;
373pub const WSA_MAXIMUM_WAIT_EVENTS: DWORD = MAXIMUM_WAIT_OBJECTS;
374pub const WSA_WAIT_FAILED: DWORD = WAIT_FAILED;
375pub const WSA_WAIT_EVENT_0: DWORD = WAIT_OBJECT_0;
376pub const WSA_WAIT_IO_COMPLETION: DWORD = WAIT_IO_COMPLETION;
377pub const WSA_WAIT_TIMEOUT: DWORD = WAIT_TIMEOUT;
378pub const WSA_INFINITE: DWORD = INFINITE;
379STRUCT!{struct QOS {
380 SendingFlowspec: FLOWSPEC,
381 FLOWSPEC: FLOWSPEC,
382 ProviderSpecific: WSABUF,
383}}
384pub type LPQOS = *mut QOS;
385pub const CF_ACCEPT: c_int = 0x0000;
386pub const CF_REJECT: c_int = 0x0001;
387pub const CF_DEFER: c_int = 0x0002;
388pub const SD_RECEIVE: c_int = 0x00;
389pub const SD_SEND: c_int = 0x01;
390pub const SD_BOTH: c_int = 0x02;
391pub type GROUP = c_uint;
392pub const SG_UNCONSTRAINED_GROUP: GROUP = 0x01;
393pub const SG_CONSTRAINED_GROUP: GROUP = 0x02;
394STRUCT!{struct WSANETWORKEVENTS {
395 lNetworkEvents: c_long,
396 iErrorCode: [c_int; FD_MAX_EVENTS],
397}}
398pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS;
399pub const MAX_PROTOCOL_CHAIN: usize = 7;
400pub const BASE_PROTOCOL: c_int = 1;
401pub const LAYERED_PROTOCOL: c_int = 0;
402STRUCT!{struct WSAPROTOCOLCHAIN {
403 ChainLen: c_int,
404 ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN],
405}}
406pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN;
407pub const WSAPROTOCOL_LEN: usize = 255;
408STRUCT!{struct WSAPROTOCOL_INFOA {
409 dwServiceFlags1: DWORD,
410 dwServiceFlags2: DWORD,
411 dwServiceFlags3: DWORD,
412 dwServiceFlags4: DWORD,
413 dwServiceFlags5: DWORD,
414 ProviderId: GUID,
415 dwCatalogEntryId: DWORD,
416 ProtocolChain: WSAPROTOCOLCHAIN,
417 iVersion: c_int,
418 iAddressFamily: c_int,
419 iMaxSockAddr: c_int,
420 iMinSockAddr: c_int,
421 iSocketType: c_int,
422 iProtocol: c_int,
423 iProtocolMaxOffset: c_int,
424 iNetworkByteOrder: c_int,
425 iSecurityScheme: c_int,
426 dwMessageSize: DWORD,
427 dwProviderReserved: DWORD,
428 szProtocol: [CHAR; WSAPROTOCOL_LEN + 1],
429}}
430pub type LPWSAPROTOCOL_INFOA = *mut WSAPROTOCOL_INFOA;
431STRUCT!{struct WSAPROTOCOL_INFOW {
432 dwServiceFlags1: DWORD,
433 dwServiceFlags2: DWORD,
434 dwServiceFlags3: DWORD,
435 dwServiceFlags4: DWORD,
436 dwServiceFlags5: DWORD,
437 ProviderId: GUID,
438 dwCatalogEntryId: DWORD,
439 ProtocolChain: WSAPROTOCOLCHAIN,
440 iVersion: c_int,
441 iAddressFamily: c_int,
442 iMaxSockAddr: c_int,
443 iMinSockAddr: c_int,
444 iSocketType: c_int,
445 iProtocol: c_int,
446 iProtocolMaxOffset: c_int,
447 iNetworkByteOrder: c_int,
448 iSecurityScheme: c_int,
449 dwMessageSize: DWORD,
450 dwProviderReserved: DWORD,
451 szProtocol: [WCHAR; WSAPROTOCOL_LEN + 1],
452}}
453pub type LPWSAPROTOCOL_INFOW = *mut WSAPROTOCOL_INFOW;
454pub const PFL_MULTIPLE_PROTO_ENTRIES: DWORD = 0x00000001;
455pub const PFL_RECOMMENDED_PROTO_ENTRY: DWORD = 0x00000002;
456pub const PFL_HIDDEN: DWORD = 0x00000004;
457pub const PFL_MATCHES_PROTOCOL_ZERO: DWORD = 0x00000008;
458pub const PFL_NETWORKDIRECT_PROVIDER: DWORD = 0x00000010;
459pub const XP1_CONNECTIONLESS: DWORD = 0x00000001;
460pub const XP1_GUARANTEED_DELIVERY: DWORD = 0x00000002;
461pub const XP1_GUARANTEED_ORDER: DWORD = 0x00000004;
462pub const XP1_MESSAGE_ORIENTED: DWORD = 0x00000008;
463pub const XP1_PSEUDO_STREAM: DWORD = 0x00000010;
464pub const XP1_GRACEFUL_CLOSE: DWORD = 0x00000020;
465pub const XP1_EXPEDITED_DATA: DWORD = 0x00000040;
466pub const XP1_CONNECT_DATA: DWORD = 0x00000080;
467pub const XP1_DISCONNECT_DATA: DWORD = 0x00000100;
468pub const XP1_SUPPORT_BROADCAST: DWORD = 0x00000200;
469pub const XP1_SUPPORT_MULTIPOINT: DWORD = 0x00000400;
470pub const XP1_MULTIPOINT_CONTROL_PLANE: DWORD = 0x00000800;
471pub const XP1_MULTIPOINT_DATA_PLANE: DWORD = 0x00001000;
472pub const XP1_QOS_SUPPORTED: DWORD = 0x00002000;
473pub const XP1_INTERRUPT: DWORD = 0x00004000;
474pub const XP1_UNI_SEND: DWORD = 0x00008000;
475pub const XP1_UNI_RECV: DWORD = 0x00010000;
476pub const XP1_IFS_HANDLES: DWORD = 0x00020000;
477pub const XP1_PARTIAL_MESSAGE: DWORD = 0x00040000;
478pub const XP1_SAN_SUPPORT_SDP: DWORD = 0x00080000;
479pub const BIGENDIAN: DWORD = 0x0000;
480pub const LITTLEENDIAN: DWORD = 0x0001;
481pub const SECURITY_PROTOCOL_NONE: DWORD = 0x0000;
482pub const JL_SENDER_ONLY: DWORD = 0x01;
483pub const JL_RECEIVER_ONLY: DWORD = 0x02;
484pub const JL_BOTH: DWORD = 0x04;
485pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
486pub const WSA_FLAG_MULTIPOINT_C_ROOT: DWORD = 0x02;
487pub const WSA_FLAG_MULTIPOINT_C_LEAF: DWORD = 0x04;
488pub const WSA_FLAG_MULTIPOINT_D_ROOT: DWORD = 0x08;
489pub const WSA_FLAG_MULTIPOINT_D_LEAF: DWORD = 0x10;
490pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY: DWORD = 0x40;
491pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80;
492pub const WSA_FLAG_REGISTERED_IO: DWORD = 0x100;
493FN!{stdcall LPCONDITIONPROC(
494 lpCallerId: LPWSABUF,
495 lpCallerData: LPWSABUF,
496 lpSQOS: LPQOS,
497 lpGQOS: LPQOS,
498 lpCalleeId: LPWSABUF,
499 lpCalleeData: LPWSABUF,
500 g: *mut GROUP,
501 dwCallbackData: DWORD,
502) -> c_int}
503FN!{stdcall LPWSAOVERLAPPED_COMPLETION_ROUTINE(
504 dwError: DWORD,
505 cbTransferred: DWORD,
506 lpOverlapped: LPWSAOVERLAPPED,
507 dwFlags: DWORD,
508) -> ()}
509ENUM!{enum WSACOMPLETIONTYPE {
510 NSP_NOTIFY_IMMEDIATELY = 0,
511 NSP_NOTIFY_HWND,
512 NSP_NOTIFY_EVENT,
513 NSP_NOTIFY_PORT,
514 NSP_NOTIFY_APC,
515}}
516pub type PWSACOMPLETIONTYPE = *mut WSACOMPLETIONTYPE;
517pub type LPWSACOMPLETIONTYPE = *mut WSACOMPLETIONTYPE;
518STRUCT!{struct WSACOMPLETION_WindowMessage {
519 hWnd: HWND,
520 uMsg: UINT,
521 context: WPARAM,
522}}
523STRUCT!{struct WSACOMPLETION_Event {
524 lpOverlapped: LPWSAOVERLAPPED,
525}}
526STRUCT!{struct WSACOMPLETION_Apc {
527 lpOverlapped: LPWSAOVERLAPPED,
528 lpfnCompletionProc: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
529}}
530STRUCT!{struct WSACOMPLETION_Port {
531 lpOverlapped: LPWSAOVERLAPPED,
532 hPort: HANDLE,
533 Key: ULONG_PTR,
534}}
535UNION!{union WSACOMPLETION_Parameter {
536 [usize; 3],
537 WindowMessage WindowMessage_mut: WSACOMPLETION_WindowMessage,
538 Event Event_mut: WSACOMPLETION_Event,
539 Apc Apc_mut: WSACOMPLETION_Apc,
540 Port Port_mut: WSACOMPLETION_Port,
541}}
542STRUCT!{struct WSACOMPLETION {
543 Type: WSACOMPLETIONTYPE,
544 Parameters: WSACOMPLETION_Parameter,
545}}
546pub type PWSACOMPLETION = *mut WSACOMPLETION;
547pub type LPWSACOMPLETION = *mut WSACOMPLETION;
548pub const TH_NETDEV: DWORD = 0x00000001;
549pub const TH_TAPI: DWORD = 0x00000002;
550pub const SERVICE_MULTIPLE: DWORD = 0x00000001;
551pub const NS_ALL: DWORD = 0;
552pub const NS_SAP: DWORD = 1;
553pub const NS_NDS: DWORD = 2;
554pub const NS_PEER_BROWSE: DWORD = 3;
555pub const NS_SLP: DWORD = 5;
556pub const NS_DHCP: DWORD = 6;
557pub const NS_TCPIP_LOCAL: DWORD = 10;
558pub const NS_TCPIP_HOSTS: DWORD = 11;
559pub const NS_DNS: DWORD = 12;
560pub const NS_NETBT: DWORD = 13;
561pub const NS_WINS: DWORD = 14;
562pub const NS_NLA: DWORD = 15;
563pub const NS_BTH: DWORD = 16;
564pub const NS_LOCALNAME: DWORD = 19;
565pub const NS_NBP: DWORD = 20;
566pub const NS_MS: DWORD = 30;
567pub const NS_STDA: DWORD = 31;
568pub const NS_NTDS: DWORD = 32;
569pub const NS_EMAIL: DWORD = 37;
570pub const NS_PNRPNAME: DWORD = 38;
571pub const NS_PNRPCLOUD: DWORD = 39;
572pub const NS_X500: DWORD = 40;
573pub const NS_NIS: DWORD = 41;
574pub const NS_NISPLUS: DWORD = 42;
575pub const NS_WRQ: DWORD = 50;
576pub const NS_NETDES: DWORD = 60;
577pub const RES_UNUSED_1: DWORD = 0x00000001;
578pub const RES_FLUSH_CACHE: DWORD = 0x00000002;
579pub const RES_SERVICE: DWORD = 0x00000004;
580pub const SERVICE_TYPE_VALUE_IPXPORT: &'static str = "IpxSocket";
581pub const SERVICE_TYPE_VALUE_SAPID: &'static str = "SapId";
582pub const SERVICE_TYPE_VALUE_TCPPORT: &'static str = "TcpPort";
583pub const SERVICE_TYPE_VALUE_UDPPORT: &'static str = "UdpPort";
584pub const SERVICE_TYPE_VALUE_OBJECTID: &'static str = "ObjectId";
585STRUCT!{struct AFPROTOCOLS {
586 iAddressFamily: INT,
587 iProtocol: INT,
588}}
589pub type PAFPROTOCOLS = *mut AFPROTOCOLS;
590pub type LPAFPROTOCOLS = *mut AFPROTOCOLS;
591ENUM!{enum WSAECOMPARATOR {
592 COMP_EQUAL = 0,
593 COMP_NOTLESS,
594}}
595pub type PWSAECOMPARATOR = *mut WSAECOMPARATOR;
596pub type LPWSAECOMPARATOR = *mut WSAECOMPARATOR;
597STRUCT!{struct WSAVERSION {
598 dwVersion: DWORD,
599 ecHow: WSAECOMPARATOR,
600}}
601pub type PWSAVERSION = *mut WSAVERSION;
602pub type LPWSAVERSION = *mut WSAVERSION;
603STRUCT!{struct WSAQUERYSETA {
604 dwSize: DWORD,
605 lpszServiceInstanceName: LPSTR,
606 lpServiceClassId: LPGUID,
607 lpVersion: LPWSAVERSION,
608 lpszComment: LPSTR,
609 dwNameSpace: DWORD,
610 lpNSProviderId: LPGUID,
611 lpszContext: LPSTR,
612 dwNumberOfProtocols: DWORD,
613 lpafpProtocols: LPAFPROTOCOLS,
614 lpszQueryString: LPSTR,
615 dwNumberOfCsAddrs: DWORD,
616 lpcsaBuffer: LPCSADDR_INFO,
617 dwOutputFlags: DWORD,
618 lpBlob: LPBLOB,
619}}
620pub type PWSAQUERYSETA = *mut WSAQUERYSETA;
621pub type LPWSAQUERYSETA = *mut WSAQUERYSETA;
622STRUCT!{struct WSAQUERYSETW {
623 dwSize: DWORD,
624 lpszServiceInstanceName: LPWSTR,
625 lpServiceClassId: LPGUID,
626 lpVersion: LPWSAVERSION,
627 lpszComment: LPWSTR,
628 dwNameSpace: DWORD,
629 lpNSProviderId: LPGUID,
630 lpszContext: LPWSTR,
631 dwNumberOfProtocols: DWORD,
632 lpafpProtocols: LPAFPROTOCOLS,
633 lpszQueryString: LPWSTR,
634 dwNumberOfCsAddrs: DWORD,
635 lpcsaBuffer: LPCSADDR_INFO,
636 dwOutputFlags: DWORD,
637 lpBlob: LPBLOB,
638}}
639pub type PWSAQUERYSETW = *mut WSAQUERYSETW;
640pub type LPWSAQUERYSETW = *mut WSAQUERYSETW;
641STRUCT!{struct WSAQUERYSET2A {
642 dwSize: DWORD,
643 lpszServiceInstanceName: LPSTR,
644 lpVersion: LPWSAVERSION,
645 lpszComment: LPSTR,
646 dwNameSpace: DWORD,
647 lpNSProviderId: LPGUID,
648 lpszContext: LPSTR,
649 dwNumberOfProtocols: DWORD,
650 lpafpProtocols: LPAFPROTOCOLS,
651 lpszQueryString: LPSTR,
652 dwNumberOfCsAddrs: DWORD,
653 lpcsaBuffer: LPCSADDR_INFO,
654 dwOutputFlags: DWORD,
655 lpBlob: LPBLOB,
656}}
657pub type PWSAQUERYSET2A = *mut WSAQUERYSET2A;
658pub type LPWSAQUERYSET2A = *mut WSAQUERYSET2A;
659STRUCT!{struct WSAQUERYSET2W {
660 dwSize: DWORD,
661 lpszServiceInstanceName: LPWSTR,
662 lpVersion: LPWSAVERSION,
663 lpszComment: LPWSTR,
664 dwNameSpace: DWORD,
665 lpNSProviderId: LPGUID,
666 lpszContext: LPWSTR,
667 dwNumberOfProtocols: DWORD,
668 lpafpProtocols: LPAFPROTOCOLS,
669 lpszQueryString: LPWSTR,
670 dwNumberOfCsAddrs: DWORD,
671 lpcsaBuffer: LPCSADDR_INFO,
672 dwOutputFlags: DWORD,
673 lpBlob: LPBLOB,
674}}
675pub type PWSAQUERYSET2W = *mut WSAQUERYSET2W;
676pub type LPWSAQUERYSET2W = *mut WSAQUERYSET2W;
677pub const LUP_DEEP: DWORD = 0x0001;
678pub const LUP_CONTAINERS: DWORD = 0x0002;
679pub const LUP_NOCONTAINERS: DWORD = 0x0004;
680pub const LUP_NEAREST: DWORD = 0x0008;
681pub const LUP_RETURN_NAME: DWORD = 0x0010;
682pub const LUP_RETURN_TYPE: DWORD = 0x0020;
683pub const LUP_RETURN_VERSION: DWORD = 0x0040;
684pub const LUP_RETURN_COMMENT: DWORD = 0x0080;
685pub const LUP_RETURN_ADDR: DWORD = 0x0100;
686pub const LUP_RETURN_BLOB: DWORD = 0x0200;
687pub const LUP_RETURN_ALIASES: DWORD = 0x0400;
688pub const LUP_RETURN_QUERY_STRING: DWORD = 0x0800;
689pub const LUP_RETURN_ALL: DWORD = 0x0FF0;
690pub const LUP_RES_SERVICE: DWORD = 0x8000;
691pub const LUP_FLUSHCACHE: DWORD = 0x1000;
692pub const LUP_FLUSHPREVIOUS: DWORD = 0x2000;
693pub const LUP_NON_AUTHORITATIVE: DWORD = 0x4000;
694pub const LUP_SECURE: DWORD = 0x8000;
695pub const LUP_RETURN_PREFERRED_NAMES: DWORD = 0x10000;
696pub const LUP_DNS_ONLY: DWORD = 0x20000;
697pub const LUP_ADDRCONFIG: DWORD = 0x00100000;
698pub const LUP_DUAL_ADDR: DWORD = 0x00200000;
699pub const LUP_FILESERVER: DWORD = 0x00400000;
700pub const LUP_DISABLE_IDN_ENCODING: DWORD = 0x00800000;
701pub const LUP_API_ANSI: DWORD = 0x01000000;
702pub const LUP_RESOLUTION_HANDLE: DWORD = 0x80000000;
703pub const RESULT_IS_ALIAS: DWORD = 0x0001;
704pub const RESULT_IS_ADDED: DWORD = 0x0010;
705pub const RESULT_IS_CHANGED: DWORD = 0x0020;
706pub const RESULT_IS_DELETED: DWORD = 0x0040;
707ENUM!{enum WSAESETSERVICEOP {
708 RNRSERVICE_REGISTER = 0,
709 RNRSERVICE_DEREGISTER,
710 RNRSERVICE_DELETE,
711}}
712pub type PWSAESETSERVICEOP = *mut WSAESETSERVICEOP;
713pub type LPWSAESETSERVICEOP = *mut WSAESETSERVICEOP;
714STRUCT!{struct WSANSCLASSINFOA {
715 lpszName: LPSTR,
716 dwNameSpace: DWORD,
717 dwValueType: DWORD,
718 dwValueSize: DWORD,
719 lpValue: LPVOID,
720}}
721pub type PWSANSCLASSINFOA = *mut WSANSCLASSINFOA;
722pub type LPWSANSCLASSINFOA = *mut WSANSCLASSINFOA;
723STRUCT!{struct WSANSCLASSINFOW {
724 lpszName: LPWSTR,
725 dwNameSpace: DWORD,
726 dwValueType: DWORD,
727 dwValueSize: DWORD,
728 lpValue: LPVOID,
729}}
730pub type PWSANSCLASSINFOW = *mut WSANSCLASSINFOW;
731pub type LPWSANSCLASSINFOW = *mut WSANSCLASSINFOW;
732STRUCT!{struct WSASERVICECLASSINFOA {
733 lpServiceClassId: LPGUID,
734 lpszServiceClassName: LPSTR,
735 dwCount: DWORD,
736 lpClassInfos: LPWSANSCLASSINFOA,
737}}
738pub type PWSASERVICECLASSINFOA = *mut WSASERVICECLASSINFOA;
739pub type LPWSASERVICECLASSINFOA = *mut WSASERVICECLASSINFOA;
740STRUCT!{struct WSASERVICECLASSINFOW {
741 lpServiceClassId: LPGUID,
742 lpszServiceClassName: LPWSTR,
743 dwCount: DWORD,
744 lpClassInfos: LPWSANSCLASSINFOW,
745}}
746pub type PWSASERVICECLASSINFOW = *mut WSASERVICECLASSINFOW;
747pub type LPWSASERVICECLASSINFOW = *mut WSASERVICECLASSINFOW;
748STRUCT!{struct WSANAMESPACE_INFOA {
749 NSProviderId: GUID,
750 dwNameSpace: DWORD,
751 fActive: BOOL,
752 dwVersion: DWORD,
753 lpszIdentifier: LPSTR,
754}}
755pub type PWSANAMESPACE_INFOA = *mut WSANAMESPACE_INFOA;
756pub type LPWSANAMESPACE_INFOA = *mut WSANAMESPACE_INFOA;
757STRUCT!{struct WSANAMESPACE_INFOW {
758 NSProviderId: GUID,
759 dwNameSpace: DWORD,
760 fActive: BOOL,
761 dwVersion: DWORD,
762 lpszIdentifier: LPWSTR,
763}}
764pub type PWSANAMESPACE_INFOW = *mut WSANAMESPACE_INFOW;
765pub type LPWSANAMESPACE_INFOW = *mut WSANAMESPACE_INFOW;
766STRUCT!{struct WSANAMESPACE_INFOEXA {
767 NSProviderId: GUID,
768 dwNameSpace: DWORD,
769 fActive: BOOL,
770 dwVersion: DWORD,
771 lpszIdentifier: LPSTR,
772 ProviderSpecific: BLOB,
773}}
774pub type PWSANAMESPACE_INFOEXA = *mut WSANAMESPACE_INFOEXA;
775pub type LPWSANAMESPACE_INFOEXA = *mut WSANAMESPACE_INFOEXA;
776STRUCT!{struct WSANAMESPACE_INFOEXW {
777 NSProviderId: GUID,
778 dwNameSpace: DWORD,
779 fActive: BOOL,
780 dwVersion: DWORD,
781 lpszIdentifier: LPWSTR,
782 ProviderSpecific: BLOB,
783}}
784pub type PWSANAMESPACE_INFOEXW = *mut WSANAMESPACE_INFOEXW;
785pub type LPWSANAMESPACE_INFOEXW = *mut WSANAMESPACE_INFOEXW;
786pub const POLLRDNORM: SHORT = 0x0100;
787pub const POLLRDBAND: SHORT = 0x0200;
788pub const POLLIN: SHORT = POLLRDNORM | POLLRDBAND;
789pub const POLLPRI: SHORT = 0x0400;
790pub const POLLWRNORM: SHORT = 0x0010;
791pub const POLLOUT: SHORT = POLLWRNORM;
792pub const POLLWRBAND: SHORT = 0x0020;
793pub const POLLERR: SHORT = 0x0001;
794pub const POLLHUP: SHORT = 0x0002;
795pub const POLLNVAL: SHORT = 0x0004;
796STRUCT!{struct WSAPOLLFD {
797 fd: SOCKET,
798 events: SHORT,
799 revents: SHORT,
800}}
801pub type PWSAPOLLFD = *mut WSAPOLLFD;
802pub type LPWSAPOLLFD = *mut WSAPOLLFD;
803extern "system" {
804 pub fn accept(
805 s: SOCKET,
806 addr: *mut SOCKADDR,
807 addrlen: *mut c_int,
808 ) -> SOCKET;
809 pub fn bind(s: SOCKET,
810 name: *const SOCKADDR,
811 namelen: c_int,
812 ) -> c_int;
813 pub fn closesocket(
814 s: SOCKET,
815 ) -> c_int;
816 pub fn connect(
817 s: SOCKET,
818 name: *const SOCKADDR,
819 namelen: c_int,
820 ) -> c_int;
821 pub fn ioctlsocket(
822 s: SOCKET,
823 cmd: c_long,
824 argp: *mut u_long,
825 ) -> c_int;
826 pub fn getpeername(
827 s: SOCKET,
828 name: *mut SOCKADDR,
829 namelen: *mut c_int,
830 ) -> c_int;
831 pub fn getsockname(
832 s: SOCKET,
833 name: *mut SOCKADDR,
834 namelen: *mut c_int,
835 ) -> c_int;
836 pub fn getsockopt(
837 s: SOCKET,
838 level: c_int,
839 optname: c_int,
840 optval: *mut c_char,
841 optlen: *mut c_int,
842 ) -> c_int;
843 pub fn htonl(
844 hostlong: u_long,
845 ) -> u_long;
846 pub fn htons(
847 hostshort: u_short,
848 ) -> u_short;
849 pub fn inet_addr(
850 cp: *const c_char,
851 ) -> c_ulong;
852 pub fn inet_ntoa(
853 _in: in_addr,
854 ) -> *mut c_char;
855}
856#[inline]
857pub fn _WS2_32_WINSOCK_SWAP_LONG(l: __uint32) -> __uint32 {
858 ((l >> 24) & 0x000000FF) | ((l >> 8) & 0x0000FF00) | ((l << 8) & 0x00FF0000)
859 | ((l << 24) & 0xFF000000)
860}
861#[inline]
862pub fn _WS2_32_WINSOCK_SWAP_LONGLONG(l: __uint64) -> __uint64 {
863 ((l >> 56) & 0x00000000000000FF) | ((l >> 40) & 0x000000000000FF00)
864 | ((l >> 24) & 0x0000000000FF0000) | ((l >> 8) & 0x00000000FF000000)
865 | ((l << 8) & 0x000000FF00000000) | ((l << 24) & 0x0000FF0000000000)
866 | ((l << 40) & 0x00FF000000000000) | ((l << 56) & 0xFF00000000000000)
867}
868#[inline]
869pub fn htonll(Value: __uint64) -> __uint64 {
870 _WS2_32_WINSOCK_SWAP_LONGLONG(Value)
871}
872#[inline]
873pub fn ntohll(Value: __uint64) -> __uint64 {
874 _WS2_32_WINSOCK_SWAP_LONGLONG(Value)
875}
876#[inline]
877pub fn htonf(Value: c_float) -> __uint32 {
878 let Tempval: __uint32 = unsafe { ::core::mem::transmute(Value) };
879 _WS2_32_WINSOCK_SWAP_LONG(Tempval)
880}
881#[inline]
882pub fn ntohf(Value: __uint32) -> c_float {
883 let Tempval = _WS2_32_WINSOCK_SWAP_LONG(Value);
884 unsafe { ::core::mem::transmute(Tempval) }
885}
886#[inline]
887pub fn htond(Value: c_double) -> __uint64 {
888 let Tempval: __uint64 = unsafe { ::core::mem::transmute(Value) };
889 _WS2_32_WINSOCK_SWAP_LONGLONG(Tempval)
890}
891#[inline]
892pub fn ntohd(Value: __uint64) -> c_double {
893 let Tempval = _WS2_32_WINSOCK_SWAP_LONGLONG(Value);
894 unsafe { ::core::mem::transmute(Tempval) }
895}
896extern "system" {
897 pub fn listen(
898 s: SOCKET,
899 backlog: c_int,
900 ) -> c_int;
901 pub fn ntohl(
902 netlong: u_long,
903 ) -> u_long;
904 pub fn ntohs(
905 netshort: u_short,
906 ) -> u_short;
907 pub fn recv(
908 s: SOCKET,
909 buf: *mut c_char,
910 len: c_int,
911 flags: c_int,
912 ) -> c_int;
913 pub fn recvfrom(
914 s: SOCKET,
915 buf: *mut c_char,
916 len: c_int,
917 flags: c_int,
918 from: *mut SOCKADDR,
919 fromlen: *mut c_int,
920 ) -> c_int;
921 pub fn select(
922 nfds: c_int,
923 readfds: *mut fd_set,
924 writefds: *mut fd_set,
925 exceptfds: *mut fd_set,
926 timeout: *const timeval,
927 ) -> c_int;
928 pub fn send(
929 s: SOCKET,
930 buf: *const c_char,
931 len: c_int,
932 flags: c_int,
933 ) -> c_int;
934 pub fn sendto(
935 s: SOCKET,
936 buf: *const c_char,
937 len: c_int,
938 flags: c_int,
939 to: *const SOCKADDR,
940 tolen: c_int,
941 ) -> c_int;
942 pub fn setsockopt(
943 s: SOCKET,
944 level: c_int,
945 optname: c_int,
946 optval: *const c_char,
947 optlen: c_int,
948 ) -> c_int;
949 pub fn shutdown(
950 s: SOCKET,
951 how: c_int,
952 ) -> c_int;
953 pub fn socket(
954 af: c_int,
955 _type: c_int,
956 protocol: c_int,
957 ) -> SOCKET;
958 pub fn gethostbyaddr(
959 addr: *const c_char,
960 len: c_int,
961 _type: c_int,
962 ) -> *mut hostent;
963 pub fn gethostbyname(
964 name: *const c_char,
965 ) -> *mut hostent;
966 pub fn gethostname(
967 name: *mut c_char,
968 namelen: c_int,
969 ) -> c_int;
970 pub fn GetHostNameW(
971 name: PWSTR,
972 namelen: c_int,
973 ) -> c_int;
974 pub fn getservbyport(
975 port: c_int,
976 proto: *const c_char,
977 ) -> *mut servent;
978 pub fn getservbyname(
979 name: *const c_char,
980 proto: *const c_char,
981 ) -> *mut servent;
982 pub fn getprotobynumber(
983 number: c_int,
984 ) -> *mut protoent;
985 pub fn getprotobyname(
986 name: *const c_char,
987 ) -> *mut protoent;
988 pub fn WSAStartup(
989 wVersionRequested: WORD,
990 lpWSAData: LPWSADATA,
991 ) -> c_int;
992 pub fn WSACleanup() -> c_int;
993 pub fn WSASetLastError(
994 iError: c_int,
995 );
996 pub fn WSAGetLastError() -> c_int;
997 pub fn WSAIsBlocking() -> BOOL;
998 pub fn WSAUnhookBlockingHook() -> c_int;
999 pub fn WSASetBlockingHook(
1000 lpBlockFunc: FARPROC,
1001 ) -> FARPROC;
1002 pub fn WSACancelBlockingCall() -> c_int;
1003 pub fn WSAAsyncGetServByName(
1004 hWnd: HWND,
1005 wMsg: u_int,
1006 name: *const c_char,
1007 proto: *const c_char,
1008 buf: *mut c_char,
1009 buflen: c_int,
1010 ) -> HANDLE;
1011 pub fn WSAAsyncGetServByPort(
1012 hWnd: HWND,
1013 wMsg: u_int,
1014 port: c_int,
1015 proto: *const c_char,
1016 buf: *mut c_char,
1017 buflen: c_int,
1018 ) -> HANDLE;
1019 pub fn WSAAsyncGetProtoByName(
1020 hWnd: HWND,
1021 wMsg: u_int,
1022 name: *const c_char,
1023 buf: *mut c_char,
1024 buflen: c_int,
1025 ) -> HANDLE;
1026 pub fn WSAAsyncGetProtoByNumber(
1027 hWnd: HWND,
1028 wMsg: u_int,
1029 number: c_int,
1030 buf: *mut c_char,
1031 buflen: c_int,
1032 ) -> HANDLE;
1033 pub fn WSAAsyncGetHostByName(
1034 hWnd: HWND,
1035 wMsg: u_int,
1036 name: *const c_char,
1037 buf: *mut c_char,
1038 buflen: c_int,
1039 ) -> HANDLE;
1040 pub fn WSAAsyncGetHostByAddr(
1041 hWnd: HWND,
1042 wMsg: u_int,
1043 addr: *const c_char,
1044 len: c_int,
1045 _type: c_int,
1046 buf: *mut c_char,
1047 buflen: c_int,
1048 ) -> HANDLE;
1049 pub fn WSACancelAsyncRequest(
1050 hAsyncTaskHandle: HANDLE,
1051 ) -> c_int;
1052 pub fn WSAAsyncSelect(
1053 s: SOCKET,
1054 hWnd: HWND,
1055 wMsg: u_int,
1056 lEvent: c_long,
1057 ) -> c_int;
1058 pub fn WSAAccept(
1059 s: SOCKET,
1060 addr: *mut SOCKADDR,
1061 addrlen: LPINT,
1062 lpfnCondition: LPCONDITIONPROC,
1063 dwCallbackData: DWORD_PTR,
1064 ) -> SOCKET;
1065 pub fn WSACloseEvent(
1066 hEvent: WSAEVENT,
1067 ) -> BOOL;
1068 pub fn WSAConnect(
1069 s: SOCKET,
1070 name: *const SOCKADDR,
1071 namelen: c_int,
1072 lpCallerData: LPWSABUF,
1073 lpCalleeData: LPWSABUF,
1074 lpSQOS: LPQOS,
1075 lpGQOS: LPQOS,
1076 ) -> c_int;
1077 pub fn WSAConnectByNameW(
1078 s: SOCKET,
1079 nodename: LPWSTR,
1080 servicename: LPWSTR,
1081 LocalAddressLength: LPDWORD,
1082 LocalAddress: LPSOCKADDR,
1083 RemoteAddressLength: LPDWORD,
1084 RemoteAddress: LPSOCKADDR,
1085 timeout: *const timeval,
1086 Reserved: LPWSAOVERLAPPED,
1087 ) -> BOOL;
1088 pub fn WSAConnectByNameA(
1089 s: SOCKET,
1090 nodename: LPCSTR,
1091 servicename: LPCSTR,
1092 LocalAddressLength: LPDWORD,
1093 LocalAddress: LPSOCKADDR,
1094 RemoteAddressLength: LPDWORD,
1095 RemoteAddress: LPSOCKADDR,
1096 timeout: *const timeval,
1097 Reserved: LPWSAOVERLAPPED,
1098 ) -> BOOL;
1099 pub fn WSAConnectByList(
1100 s: SOCKET,
1101 SocketAddress: PSOCKET_ADDRESS_LIST,
1102 LocalAddressLength: LPDWORD,
1103 LocalAddress: LPSOCKADDR,
1104 RemoteAddressLength: LPDWORD,
1105 RemoteAddress: LPSOCKADDR,
1106 timeout: *const timeval,
1107 Reserved: LPWSAOVERLAPPED,
1108 ) -> BOOL;
1109 pub fn WSACreateEvent() -> WSAEVENT;
1110 pub fn WSADuplicateSocketA(
1111 s: SOCKET,
1112 dwProcessId: DWORD,
1113 lpProtocolInfo: LPWSAPROTOCOL_INFOA,
1114 ) -> c_int;
1115 pub fn WSADuplicateSocketW(
1116 s: SOCKET,
1117 dwProcessId: DWORD,
1118 lpProtocolInfo: LPWSAPROTOCOL_INFOW,
1119 ) -> c_int;
1120 pub fn WSAEnumNetworkEvents(
1121 s: SOCKET,
1122 hEventObject: WSAEVENT,
1123 lpNetworkEvents: LPWSANETWORKEVENTS,
1124 ) -> c_int;
1125 pub fn WSAEnumProtocolsA(
1126 lpiProtocols: LPINT,
1127 lpProtocolBuffer: LPWSAPROTOCOL_INFOA,
1128 lpdwBufferLength: LPDWORD,
1129 ) -> c_int;
1130 pub fn WSAEnumProtocolsW(
1131 lpiProtocols: LPINT,
1132 lpProtocolBuffer: LPWSAPROTOCOL_INFOW,
1133 lpdwBufferLength: LPDWORD,
1134 ) -> c_int;
1135 pub fn WSAEventSelect(
1136 s: SOCKET,
1137 hEventObject: WSAEVENT,
1138 lNetworkEvents: c_long,
1139 ) -> c_int;
1140 pub fn WSAGetOverlappedResult(
1141 s: SOCKET,
1142 lpOverlapped: LPWSAOVERLAPPED,
1143 lpcbTransfer: LPDWORD,
1144 fWait: BOOL,
1145 lpdwFlags: LPDWORD,
1146 ) -> BOOL;
1147 pub fn WSAGetQOSByName(
1148 s: SOCKET,
1149 lpQOSName: LPWSABUF,
1150 lpQOS: LPQOS,
1151 ) -> BOOL;
1152 pub fn WSAHtonl(
1153 s: SOCKET,
1154 hostlong: u_long,
1155 lpnetlong: *mut u_long,
1156 ) -> c_int;
1157 pub fn WSAHtons(s: SOCKET,
1158 hostshort: u_short,
1159 lpnetshort: *mut u_short,
1160 ) -> c_int;
1161 pub fn WSAIoctl(
1162 s: SOCKET,
1163 dwIoControlCode: DWORD,
1164 lpvInBuffer: LPVOID,
1165 cbInBuffer: DWORD,
1166 lpvOutBuffer: LPVOID,
1167 cbOutBuffer: DWORD,
1168 lpcbBytesReturned: LPDWORD,
1169 lpOverlapped: LPWSAOVERLAPPED,
1170 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1171 ) -> c_int;
1172 pub fn WSAJoinLeaf(
1173 s: SOCKET,
1174 name: *const SOCKADDR,
1175 namelen: c_int,
1176 lpCallerData: LPWSABUF,
1177 lpCalleeData: LPWSABUF,
1178 lpSQOS: LPQOS,
1179 lpGQOS: LPQOS,
1180 dwFlags: DWORD,
1181 ) -> SOCKET;
1182 pub fn WSANtohl(
1183 s: SOCKET,
1184 netlong: u_long,
1185 lphostlong: *mut c_long,
1186 ) -> c_int;
1187 pub fn WSANtohs(
1188 s: SOCKET,
1189 netshort: u_short,
1190 lphostshort: *mut c_short,
1191 ) -> c_int;
1192 pub fn WSARecv(
1193 s: SOCKET,
1194 lpBuffers: LPWSABUF,
1195 dwBufferCount: DWORD,
1196 lpNumberOfBytesRecvd: LPDWORD,
1197 lpFlags: LPDWORD,
1198 lpOverlapped: LPWSAOVERLAPPED,
1199 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1200 ) -> c_int;
1201 pub fn WSARecvDisconnect(
1202 s: SOCKET,
1203 lpInboundDisconnectData: LPWSABUF,
1204 ) -> c_int;
1205 pub fn WSARecvFrom(
1206 s: SOCKET,
1207 lpBuffers: LPWSABUF,
1208 dwBufferCount: DWORD,
1209 lpNumberOfBytesRecvd: LPDWORD,
1210 lpFlags: LPDWORD,
1211 lpFrom: *mut SOCKADDR,
1212 lpFromlen: LPINT,
1213 lpOverlapped: LPWSAOVERLAPPED,
1214 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1215 ) -> c_int;
1216 pub fn WSAResetEvent(
1217 hEvent: WSAEVENT,
1218 ) -> BOOL;
1219 pub fn WSASend(
1220 s: SOCKET,
1221 lpBuffers: LPWSABUF,
1222 dwBufferCount: DWORD,
1223 lpNumberOfBytesSent: LPDWORD,
1224 dwFlags: DWORD,
1225 lpOverlapped: LPWSAOVERLAPPED,
1226 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1227 ) -> c_int;
1228 pub fn WSASendMsg(
1229 Handle: SOCKET,
1230 lpMsg: LPWSAMSG,
1231 dwFlags: DWORD,
1232 lpNumberOfBytesSent: LPDWORD,
1233 lpOverlapped: LPWSAOVERLAPPED,
1234 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1235 ) -> c_int;
1236 pub fn WSASendDisconnect(
1237 s: SOCKET,
1238 lpOutboundDisconnectData: LPWSABUF,
1239 ) -> c_int;
1240 pub fn WSASendTo(
1241 s: SOCKET,
1242 lpBuffers: LPWSABUF,
1243 dwBufferCount: DWORD,
1244 lpNumberOfBytesSent: LPDWORD,
1245 dwFlags: DWORD,
1246 lpTo: *const SOCKADDR,
1247 iToLen: c_int,
1248 lpOverlapped: LPWSAOVERLAPPED,
1249 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1250 ) -> c_int;
1251 pub fn WSASetEvent(
1252 hEvent: WSAEVENT,
1253 ) -> BOOL;
1254 pub fn WSASocketA(
1255 af: c_int,
1256 _type: c_int,
1257 protocol: c_int,
1258 lpProtocolInfo: LPWSAPROTOCOL_INFOA,
1259 g: GROUP,
1260 dwFlags: DWORD,
1261 ) -> SOCKET;
1262 pub fn WSASocketW(
1263 af: c_int,
1264 _type: c_int,
1265 protocol: c_int,
1266 lpProtocolInfo: LPWSAPROTOCOL_INFOW,
1267 g: GROUP,
1268 dwFlags: DWORD,
1269 ) -> SOCKET;
1270 pub fn WSAWaitForMultipleEvents(
1271 cEvents: DWORD,
1272 lphEvents: *const WSAEVENT,
1273 fWaitAll: BOOL,
1274 dwTimeout: DWORD,
1275 fAlertable: BOOL,
1276 ) -> DWORD;
1277 pub fn WSAAddressToStringA(
1278 lpsaAddress: LPSOCKADDR,
1279 dwAddressLength: DWORD,
1280 lpProtocolInfo: LPWSAPROTOCOL_INFOA,
1281 lpszAddressString: LPSTR,
1282 lpdwAddressStringLength: LPDWORD,
1283 ) -> INT;
1284 pub fn WSAAddressToStringW(
1285 lpsaAddress: LPSOCKADDR,
1286 dwAddressLength: DWORD,
1287 lpProtocolInfo: LPWSAPROTOCOL_INFOW,
1288 lpszAddressString: LPWSTR,
1289 lpdwAddressStringLength: LPDWORD,
1290 ) -> INT;
1291 pub fn WSAStringToAddressA(
1292 AddressString: LPSTR,
1293 AddressFamily: INT,
1294 lpProtocolInfo: LPWSAPROTOCOL_INFOA,
1295 lpAddress: LPSOCKADDR,
1296 lpAddressLength: LPINT,
1297 ) -> INT;
1298 pub fn WSAStringToAddressW(
1299 AddressString: LPWSTR,
1300 AddressFamily: INT,
1301 lpProtocolInfo: LPWSAPROTOCOL_INFOW,
1302 lpAddress: LPSOCKADDR,
1303 lpAddressLength: LPINT,
1304 ) -> INT;
1305 pub fn WSALookupServiceBeginA(
1306 lpqsRestrictions: LPWSAQUERYSETA,
1307 dwControlFlags: DWORD,
1308 lphLookup: LPHANDLE,
1309 ) -> INT;
1310 pub fn WSALookupServiceBeginW(
1311 lpqsRestrictions: LPWSAQUERYSETW,
1312 dwControlFlags: DWORD,
1313 lphLookup: LPHANDLE,
1314 ) -> INT;
1315 pub fn WSALookupServiceNextA(
1316 hLookup: HANDLE,
1317 dwControlFlags: DWORD,
1318 lpdwBufferLength: LPDWORD,
1319 lpqsResults: LPWSAQUERYSETA,
1320 ) -> INT;
1321 pub fn WSALookupServiceNextW(
1322 hLookup: HANDLE,
1323 dwControlFlags: DWORD,
1324 lpdwBufferLength: LPDWORD,
1325 lpqsResults: LPWSAQUERYSETW,
1326 ) -> INT;
1327 pub fn WSANSPIoctl(
1328 hLookup: HANDLE,
1329 dwControlFlags: DWORD,
1330 lpvInBuffer: LPVOID,
1331 cbInBuffer: DWORD,
1332 lpvOutBuffer: LPVOID,
1333 cbOutBuffer: DWORD,
1334 lpcbBytesReturned: LPDWORD,
1335 lpCompletion: LPWSACOMPLETION,
1336 ) -> INT;
1337 pub fn WSALookupServiceEnd(
1338 hLookup: HANDLE,
1339 ) -> INT;
1340 pub fn WSAInstallServiceClassA(
1341 lpServiceClassInfo: LPWSASERVICECLASSINFOA,
1342 ) -> INT;
1343 pub fn WSAInstallServiceClassW(
1344 lpServiceClassInfo: LPWSASERVICECLASSINFOW,
1345 ) -> INT;
1346 pub fn WSARemoveServiceClass(
1347 lpServiceClassId: LPGUID,
1348 ) -> INT;
1349 pub fn WSAGetServiceClassInfoA(
1350 lpProviderId: LPGUID,
1351 lpServiceClassId: LPGUID,
1352 lpdwBufSize: LPDWORD,
1353 lpServiceClassInfo: LPWSASERVICECLASSINFOA,
1354 ) -> INT;
1355 pub fn WSAGetServiceClassInfoW(
1356 lpProviderId: LPGUID,
1357 lpServiceClassId: LPGUID,
1358 lpdwBufSize: LPDWORD,
1359 lpServiceClassInfo: LPWSASERVICECLASSINFOW,
1360 ) -> INT;
1361 pub fn WSAEnumNameSpaceProvidersA(
1362 lpdwBufferLength: LPDWORD,
1363 lpnspBuffer: LPWSANAMESPACE_INFOA,
1364 ) -> INT;
1365 pub fn WSAEnumNameSpaceProvidersW(
1366 lpdwBufferLength: LPDWORD,
1367 lpnspBuffer: LPWSANAMESPACE_INFOW,
1368 ) -> INT;
1369 pub fn WSAEnumNameSpaceProvidersExA(
1370 lpdwBufferLength: LPDWORD,
1371 lpnspBuffer: LPWSANAMESPACE_INFOEXA,
1372 ) -> INT;
1373 pub fn WSAEnumNameSpaceProvidersExW(
1374 lpdwBufferLength: LPDWORD,
1375 lpnspBuffer: LPWSANAMESPACE_INFOEXW,
1376 ) -> INT;
1377 pub fn WSAGetServiceClassNameByClassIdA(
1378 lpServiceClassId: LPGUID,
1379 lpszServiceClassName: LPSTR,
1380 lpdwBufferLength: LPDWORD,
1381 ) -> INT;
1382 pub fn WSAGetServiceClassNameByClassIdW(
1383 lpServiceClassId: LPGUID,
1384 lpszServiceClassName: LPWSTR,
1385 lpdwBufferLength: LPDWORD,
1386 ) -> INT;
1387 pub fn WSASetServiceA(
1388 lpqsRegInfo: LPWSAQUERYSETA,
1389 essoperation: WSAESETSERVICEOP,
1390 dwControlFlags: DWORD,
1391 ) -> INT;
1392 pub fn WSASetServiceW(
1393 lpqsRegInfo: LPWSAQUERYSETW,
1394 essoperation: WSAESETSERVICEOP,
1395 dwControlFlags: DWORD,
1396 ) -> INT;
1397 pub fn WSAProviderConfigChange(
1398 lpNotificationHandle: LPHANDLE,
1399 lpOverlapped: LPWSAOVERLAPPED,
1400 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1401 ) -> INT;
1402 pub fn WSAPoll(
1403 fdArray: LPWSAPOLLFD,
1404 fds: ULONG,
1405 timeout: INT,
1406 ) -> c_int;
1407}
1408pub type LPSOCKADDR_IN = *mut SOCKADDR_IN;
1409pub type LINGER = linger;
1410pub type PLINGER = *mut linger;
1411pub type LPLINGER = *mut linger;
1412pub type FD_SET = fd_set;
1413pub type PFD_SET = *mut fd_set;
1414pub type LPFD_SET = *mut fd_set;
1415pub type HOSTENT = hostent;
1416pub type PHOSTENT = *mut hostent;
1417pub type LPHOSTENT = *mut hostent;
1418pub type SERVENT = servent;
1419pub type PSERVENT = *mut servent;
1420pub type LPSERVENT = *mut servent;
1421pub type PROTOENT = protoent;
1422pub type PPROTOENT = *mut protoent;
1423pub type LPPROTOENT = *mut protoent;
1424pub type TIMEVAL = timeval;
1425pub type PTIMEVAL = *mut timeval;
1426pub type LPTIMEVAL = *mut timeval;
1427#[inline]
1428pub fn WSAMAKEASYNCREPLY(buflen: WORD, error: WORD) -> LONG {
1429 MAKELONG(buflen, error)
1430}
1431#[inline]
1432pub fn WSAMAKESELECTREPLY(event: WORD, error: WORD) -> LONG {
1433 MAKELONG(event, error)
1434}
1435#[inline]
1436pub fn WSAGETASYNCBUFLEN(lParam: DWORD) -> WORD {
1437 LOWORD(lParam)
1438}
1439#[inline]
1440pub fn WSAGETASYNCERROR(lParam: DWORD) -> WORD {
1441 HIWORD(lParam)
1442}
1443#[inline]
1444pub fn WSAGETSELECTEVENT(lParam: DWORD) -> WORD {
1445 LOWORD(lParam)
1446}
1447#[inline]
1448pub fn WSAGETSELECTERROR(lParam: DWORD) -> WORD {
1449 HIWORD(lParam)
1450}