1 // Copyright © 2015, Peter Atashian
2 // Licensed under the MIT License <LICENSE.md>
3 //! This file contains the core definitions for the Winsock2 specification that can be used by
4 //! both user-mode and kernel mode modules.
5 pub type ADDRESS_FAMILY = ::USHORT;
6 pub const AF_UNSPEC: ::c_int = 0;
7 pub const AF_UNIX: ::c_int = 1;
8 pub const AF_INET: ::c_int = 2;
9 pub const AF_IMPLINK: ::c_int = 3;
10 pub const AF_PUP: ::c_int = 4;
11 pub const AF_CHAOS: ::c_int = 5;
12 pub const AF_NS: ::c_int = 6;
13 pub const AF_IPX: ::c_int = AF_NS;
14 pub const AF_ISO: ::c_int = 7;
15 pub const AF_OSI: ::c_int = AF_ISO;
16 pub const AF_ECMA: ::c_int = 8;
17 pub const AF_DATAKIT: ::c_int = 9;
18 pub const AF_CCITT: ::c_int = 10;
19 pub const AF_SNA: ::c_int = 11;
20 pub const AF_DECnet: ::c_int = 12;
21 pub const AF_DLI: ::c_int = 13;
22 pub const AF_LAT: ::c_int = 14;
23 pub const AF_HYLINK: ::c_int = 15;
24 pub const AF_APPLETALK: ::c_int = 16;
25 pub const AF_NETBIOS: ::c_int = 17;
26 pub const AF_VOICEVIEW: ::c_int = 18;
27 pub const AF_FIREFOX: ::c_int = 19;
28 pub const AF_UNKNOWN1: ::c_int = 20;
29 pub const AF_BAN: ::c_int = 21;
30 pub const AF_ATM: ::c_int = 22;
31 pub const AF_INET6: ::c_int = 23;
32 pub const AF_CLUSTER: ::c_int = 24;
33 pub const AF_12844: ::c_int = 25;
34 pub const AF_IRDA: ::c_int = 26;
35 pub const AF_NETDES: ::c_int = 28;
36 pub const AF_TCNPROCESS: ::c_int = 29;
37 pub const AF_TCNMESSAGE: ::c_int = 30;
38 pub const AF_ICLFXBM: ::c_int = 31;
39 pub const AF_BTH: ::c_int = 32;
40 pub const AF_LINK: ::c_int = 33;
41 pub const AF_MAX: ::c_int = 34;
42 pub const SOCK_STREAM: ::c_int = 1;
43 pub const SOCK_DGRAM: ::c_int = 2;
44 pub const SOCK_RAW: ::c_int = 3;
45 pub const SOCK_RDM: ::c_int = 4;
46 pub const SOCK_SEQPACKET: ::c_int = 5;
47 pub const SOL_SOCKET: ::c_int = 0xffff;
48 pub const SO_DEBUG: ::c_int = 0x0001;
49 pub const SO_ACCEPTCONN: ::c_int = 0x0002;
50 pub const SO_REUSEADDR: ::c_int = 0x0004;
51 pub const SO_KEEPALIVE: ::c_int = 0x0008;
52 pub const SO_DONTROUTE: ::c_int = 0x0010;
53 pub const SO_BROADCAST: ::c_int = 0x0020;
54 pub const SO_USELOOPBACK: ::c_int = 0x0040;
55 pub const SO_LINGER: ::c_int = 0x0080;
56 pub const SO_OOBINLINE: ::c_int = 0x0100;
57 pub const SO_DONTLINGER: ::c_int = !SO_LINGER;
58 pub const SO_EXCLUSIVEADDRUSE: ::c_int = !SO_REUSEADDR;
59 pub const SO_SNDBUF: ::c_int = 0x1001;
60 pub const SO_RCVBUF: ::c_int = 0x1002;
61 pub const SO_SNDLOWAT: ::c_int = 0x1003;
62 pub const SO_RCVLOWAT: ::c_int = 0x1004;
63 pub const SO_SNDTIMEO: ::c_int = 0x1005;
64 pub const SO_RCVTIMEO: ::c_int = 0x1006;
65 pub const SO_ERROR: ::c_int = 0x1007;
66 pub const SO_TYPE: ::c_int = 0x1008;
67 pub const SO_BSP_STATE: ::c_int = 0x1009;
68 pub const SO_GROUP_ID: ::c_int = 0x2001;
69 pub const SO_GROUP_PRIORITY: ::c_int = 0x2002;
70 pub const SO_MAX_MSG_SIZE: ::c_int = 0x2003;
71 pub const SO_CONDITIONAL_ACCEPT: ::c_int = 0x3002;
72 pub const SO_PAUSE_ACCEPT: ::c_int = 0x3003;
73 pub const SO_COMPARTMENT_ID: ::c_int = 0x3004;
74 pub const SO_RANDOMIZE_PORT: ::c_int = 0x3005;
75 pub const SO_PORT_SCALABILITY: ::c_int = 0x3006;
76 pub const WSK_SO_BASE: ::c_int = 0x4000;
77 pub const TCP_NODELAY: ::c_int = 0x0001;
78 STRUCT!{struct SOCKADDR {
79     sa_family: ADDRESS_FAMILY,
80     sa_data: [::CHAR; 14],
81 }}
82 pub type PSOCKADDR = *mut SOCKADDR;
83 pub type LPSOCKADDR = *mut SOCKADDR;
84 STRUCT!{struct SOCKET_ADDRESS {
85     lpSockaddr: LPSOCKADDR,
86     iSockaddrLength: ::INT,
87 }}
88 pub type PSOCKET_ADDRESS = *mut SOCKET_ADDRESS;
89 pub type LPSOCKET_ADDRESS = *mut SOCKET_ADDRESS;
90 STRUCT!{nodebug struct SOCKET_ADDRESS_LIST {
91     iAddressCount: ::INT,
92     Address: [SOCKET_ADDRESS; 0],
93 }}
94 pub type PSOCKET_ADDRESS_LIST = *mut SOCKET_ADDRESS_LIST;
95 pub type LPSOCKET_ADDRESS_LIST = *mut SOCKET_ADDRESS_LIST;
96 STRUCT!{struct CSADDR_INFO {
97     LocalAddr: SOCKET_ADDRESS,
98     RemoteAddr: SOCKET_ADDRESS,
99     iSocketType: ::INT,
100     iProtocol: ::INT,
101 }}
102 pub type PCSADDR_INFO = *mut CSADDR_INFO;
103 pub type LPCSADDR_INFO = *mut CSADDR_INFO;
104 STRUCT!{nodebug struct SOCKADDR_STORAGE_LH {
105     ss_family: ADDRESS_FAMILY,
106     __ss_pad1: [::CHAR; 6],
107     __ss_align: ::__int64,
108     __ss_pad2: [::CHAR; 112],
109 }}
110 pub type PSOCKADDR_STORAGE_LH = *mut SOCKADDR_STORAGE_LH;
111 pub type LPSOCKADDR_STORAGE_LH = *mut SOCKADDR_STORAGE_LH;
112 STRUCT!{nodebug struct SOCKADDR_STORAGE_XP {
113     ss_family: ::c_short,
114     __ss_pad1: [::CHAR; 6],
115     __ss_align: ::__int64,
116     __ss_pad2: [::CHAR; 112],
117 }}
118 pub type PSOCKADDR_STORAGE_XP = *mut SOCKADDR_STORAGE_XP;
119 pub type LPSOCKADDR_STORAGE_XP = *mut SOCKADDR_STORAGE_XP;
120 pub type SOCKADDR_STORAGE = SOCKADDR_STORAGE_LH;
121 pub type PSOCKADDR_STORAGE = *mut SOCKADDR_STORAGE;
122 pub type LPSOCKADDR_STORAGE = *mut SOCKADDR_STORAGE;
123 STRUCT!{struct SOCKET_PROCESSOR_AFFINITY {
124     Processor: ::PROCESSOR_NUMBER,
125     NumaNodeId: ::USHORT,
126     Reserved: ::USHORT,
127 }}
128 pub type PSOCKET_PROCESSOR_AFFINITY = *mut SOCKET_PROCESSOR_AFFINITY;
129 pub const IOC_UNIX: ::DWORD = 0x00000000;
130 pub const IOC_WS2: ::DWORD = 0x08000000;
131 pub const IOC_PROTOCOL: ::DWORD = 0x10000000;
132 pub const IOC_VENDOR: ::DWORD = 0x18000000;
133 pub const IOC_WSK: ::DWORD = IOC_WS2 | 0x07000000;
134 macro_rules! _WSAIO { ($x:expr, $y:expr) => { IOC_VOID | $x | $y } }
135 macro_rules! _WSAIOR { ($x:expr, $y:expr) => { IOC_OUT | $x | $y } }
136 macro_rules! _WSAIOW { ($x:expr, $y:expr) => { IOC_IN | $x | $y } }
137 macro_rules! _WSAIORW { ($x:expr, $y:expr) => { IOC_INOUT | $x | $y } }
138 pub const SIO_ASSOCIATE_HANDLE: ::DWORD = _WSAIOW!(IOC_WS2, 1);
139 pub const SIO_ENABLE_CIRCULAR_QUEUEING: ::DWORD = _WSAIO!(IOC_WS2, 2);
140 pub const SIO_FIND_ROUTE: ::DWORD = _WSAIOR!(IOC_WS2, 3);
141 pub const SIO_FLUSH: ::DWORD = _WSAIO!(IOC_WS2, 4);
142 pub const SIO_GET_BROADCAST_ADDRESS: ::DWORD = _WSAIOR!(IOC_WS2, 5);
143 pub const SIO_GET_EXTENSION_FUNCTION_POINTER: ::DWORD = _WSAIORW!(IOC_WS2, 6);
144 pub const SIO_GET_QOS: ::DWORD = _WSAIORW!(IOC_WS2, 7);
145 pub const SIO_GET_GROUP_QOS: ::DWORD = _WSAIORW!(IOC_WS2, 8);
146 pub const SIO_MULTIPOINT_LOOPBACK: ::DWORD = _WSAIOW!(IOC_WS2, 9);
147 pub const SIO_MULTICAST_SCOPE: ::DWORD = _WSAIOW!(IOC_WS2, 10);
148 pub const SIO_SET_QOS: ::DWORD = _WSAIOW!(IOC_WS2, 11);
149 pub const SIO_SET_GROUP_QOS: ::DWORD = _WSAIOW!(IOC_WS2, 12);
150 pub const SIO_TRANSLATE_HANDLE: ::DWORD = _WSAIORW!(IOC_WS2, 13);
151 pub const SIO_ROUTING_INTERFACE_QUERY: ::DWORD = _WSAIORW!(IOC_WS2, 20);
152 pub const SIO_ROUTING_INTERFACE_CHANGE: ::DWORD = _WSAIOW!(IOC_WS2, 21);
153 pub const SIO_ADDRESS_LIST_QUERY: ::DWORD = _WSAIOR!(IOC_WS2, 22);
154 pub const SIO_ADDRESS_LIST_CHANGE: ::DWORD = _WSAIO!(IOC_WS2, 23);
155 pub const SIO_QUERY_TARGET_PNP_HANDLE: ::DWORD = _WSAIOR!(IOC_WS2, 24);
156 pub const SIO_QUERY_RSS_PROCESSOR_INFO: ::DWORD = _WSAIOR!(IOC_WS2, 37);
157 pub const SIO_ADDRESS_LIST_SORT: ::DWORD = _WSAIORW!(IOC_WS2, 25);
158 pub const SIO_RESERVED_1: ::DWORD = _WSAIOW!(IOC_WS2, 26);
159 pub const SIO_RESERVED_2: ::DWORD = _WSAIOW!(IOC_WS2, 33);
160 pub const SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER: ::DWORD = _WSAIORW!(IOC_WS2, 36);
161 pub const IPPROTO_IP: ::c_int = 0;
162 ENUM!{enum IPPROTO {
163     IPPROTO_HOPOPTS = 0,  // IPv6 Hop-by-Hop options
164     IPPROTO_ICMP = 1,
165     IPPROTO_IGMP = 2,
166     IPPROTO_GGP = 3,
167     IPPROTO_IPV4 = 4,
168     IPPROTO_ST = 5,
169     IPPROTO_TCP = 6,
170     IPPROTO_CBT = 7,
171     IPPROTO_EGP = 8,
172     IPPROTO_IGP = 9,
173     IPPROTO_PUP = 12,
174     IPPROTO_UDP = 17,
175     IPPROTO_IDP = 22,
176     IPPROTO_RDP = 27,
177     IPPROTO_IPV6 = 41, // IPv6 header
178     IPPROTO_ROUTING = 43, // IPv6 Routing header
179     IPPROTO_FRAGMENT = 44, // IPv6 fragmentation header
180     IPPROTO_ESP = 50, // encapsulating security payload
181     IPPROTO_AH = 51, // authentication header
182     IPPROTO_ICMPV6 = 58, // ICMPv6
183     IPPROTO_NONE = 59, // IPv6 no next header
184     IPPROTO_DSTOPTS = 60, // IPv6 Destination options
185     IPPROTO_ND = 77,
186     IPPROTO_ICLFXBM = 78,
187     IPPROTO_PIM = 103,
188     IPPROTO_PGM = 113,
189     IPPROTO_L2TP = 115,
190     IPPROTO_SCTP = 132,
191     IPPROTO_RAW = 255,
192     IPPROTO_MAX = 256,
193     IPPROTO_RESERVED_RAW  = 257,
194     IPPROTO_RESERVED_IPSEC = 258,
195     IPPROTO_RESERVED_IPSECOFFLOAD = 259,
196     IPPROTO_RESERVED_WNV = 260,
197     IPPROTO_RESERVED_MAX = 261,
198 }}
199 pub type PIPPROTO = *mut IPPROTO;
200 STRUCT!{struct SOCKADDR_IN {
201     sin_family: ADDRESS_FAMILY,
202     sin_port: ::USHORT,
203     sin_addr: ::IN_ADDR,
204     sin_zero: [::CHAR; 8],
205 }}
206 pub type PSOCKADDR_IN = *mut SOCKADDR_IN;
207 //645
208 pub const IOCPARM_MASK: ::DWORD = 0x7f;
209 pub const IOC_VOID: ::DWORD = 0x20000000;
210 pub const IOC_OUT: ::DWORD = 0x40000000;
211 pub const IOC_IN: ::DWORD = 0x80000000;
212 pub const IOC_INOUT: ::DWORD = IOC_IN | IOC_OUT;
213 STRUCT!{struct WSABUF {
214     len: ::ULONG,
215     buf: *mut ::CHAR,
216 }}
217 pub type LPWSABUF = *mut WSABUF;
218 STRUCT!{struct WSAMSG {
219     name: LPSOCKADDR,
220     namelen: ::INT,
221     lpBuffers: LPWSABUF,
222     dwBufferCount: ::ULONG,
223     Control: WSABUF,
224     dwFlags: ::ULONG,
225 }}
226 pub type PWSAMSG = *mut WSAMSG;
227 pub type LPWSAMSG = *mut WSAMSG;
228 STRUCT!{struct ADDRINFOA {
229     ai_flags: ::c_int,
230     ai_family: ::c_int,
231     ai_socktype: ::c_int,
232     ai_protocol: ::c_int,
233     ai_addrlen: ::size_t,
234     ai_canonname: *mut ::c_char,
235     ai_addr: *mut SOCKADDR,
236     ai_next: *mut ADDRINFOA,
237 }}
238 pub type PADDRINFOA = *mut ADDRINFOA;
239 STRUCT!{struct ADDRINFOW {
240     ai_flags: ::c_int,
241     ai_family: ::c_int,
242     ai_socktype: ::c_int,
243     ai_protocol: ::c_int,
244     ai_addrlen: ::size_t,
245     ai_canonname: ::PWSTR,
246     ai_addr: *mut SOCKADDR,
247     ai_next: *mut ADDRINFOW,
248 }}
249 pub type PADDRINFOW = *mut ADDRINFOW;
250 STRUCT!{struct ADDRINFOEXA {
251     ai_flags: ::c_int,
252     ai_family: ::c_int,
253     ai_socktype: ::c_int,
254     ai_protocol: ::c_int,
255     ai_addrlen: ::size_t,
256     ai_canonname: *mut ::c_char,
257     ai_addr: *mut SOCKADDR,
258     ai_blob: *mut ::c_void,
259     ai_bloblen: ::size_t,
260     ai_provider: ::LPGUID,
261     ai_next: *mut ADDRINFOEXW,
262 }}
263 pub type PADDRINFOEXA = *mut ADDRINFOEXA;
264 pub type LPADDRINFOEXA = *mut ADDRINFOEXA;
265 STRUCT!{struct ADDRINFOEXW {
266     ai_flags: ::c_int,
267     ai_family: ::c_int,
268     ai_socktype: ::c_int,
269     ai_protocol: ::c_int,
270     ai_addrlen: ::size_t,
271     ai_canonname: ::PWSTR,
272     ai_addr: *mut SOCKADDR,
273     ai_blob: *mut ::c_void,
274     ai_bloblen: ::size_t,
275     ai_provider: ::LPGUID,
276     ai_next: *mut ADDRINFOEXW,
277 }}
278 pub type PADDRINFOEXW = *mut ADDRINFOEXW;
279 pub type LPADDRINFOEXW = *mut ADDRINFOEXW;
280