2 * Copyright 2020 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 typedef struct _WSK_CLIENT WSK_CLIENT
, *PWSK_CLIENT
;
33 typedef struct _WSK_SOCKET
36 } WSK_SOCKET
, *PWSK_SOCKET
;
38 #define MAKE_WSK_VERSION(major, minor) ((USHORT)((major) << 8) | (USHORT)((minor) & 0xff))
40 #define WSK_INFINITE_WAIT 0xffffffff
42 #define WSK_FLAG_BASIC_SOCKET 0x00000000
43 #define WSK_FLAG_LISTEN_SOCKET 0x00000001
44 #define WSK_FLAG_CONNECTION_SOCKET 0x00000002
45 #define WSK_FLAG_DATAGRAM_SOCKET 0x00000004
46 #define WSK_FLAG_STREAM_SOCKET 0x00000008
48 typedef enum _WSK_CONTROL_SOCKET_TYPE
53 } WSK_CONTROL_SOCKET_TYPE
;
55 typedef enum _WSK_INSPECT_ACTION
61 typedef struct _WSK_CLIENT_CONNECTION_DISPATCH WSK_CLIENT_CONNECTION_DISPATCH
, *PWSK_CLIENT_CONNECTION_DISPATCH
;
63 typedef struct _WSK_BUF
70 typedef struct _WSK_BUF_LIST
72 struct _WSK_BUF_LIST
*Next
;
74 } WSK_BUF_LIST
, *PWSK_BUF_LIST
;
76 typedef struct _WSK_DATA_INDICATION
78 struct _WSK_DATA_INDICATION
*Next
;
80 } WSK_DATA_INDICATION
, *PWSK_DATA_INDICATION
;
82 typedef struct _WSK_INSPECT_ID
86 } WSK_INSPECT_ID
, *PWSK_INSPECT_ID
;
88 typedef struct _WSK_DATAGRAM_INDICATION
90 struct _WSK_DATAGRAM_INDICATION
*Next
;
93 ULONG ControlInfoLength
;
94 PSOCKADDR RemoteAddress
;
95 } WSK_DATAGRAM_INDICATION
, *PWSK_DATAGRAM_INDICATION
;
97 typedef NTSTATUS (WINAPI
*PFN_WSK_CLIENT_EVENT
)(void *context
, ULONG event
, void *info
, SIZE_T length
);
98 typedef NTSTATUS (WINAPI
*PFN_WSK_DISCONNECT_EVENT
)(void *context
, ULONG flags
);
99 typedef NTSTATUS (WINAPI
*PFN_WSK_SEND_BACKLOG_EVENT
)(void *socket_context
, SIZE_T ideal_backlog_size
);
100 typedef NTSTATUS (WINAPI
*PFN_WSK_SOCKET
)(WSK_CLIENT
*client
, ADDRESS_FAMILY family
,
101 USHORT type
, ULONG protocol
, ULONG flags
, void *context
, const void *dispatch
,
102 PEPROCESS process
, PETHREAD thread
, SECURITY_DESCRIPTOR
*security
, IRP
*irp
);
103 typedef NTSTATUS (WINAPI
*PFN_WSK_SOCKET_CONNECT
)(WSK_CLIENT
*client
, USHORT type
,
104 ULONG protocol
, SOCKADDR
*local
, SOCKADDR
*remote
, ULONG flags
, void *context
,
105 const WSK_CLIENT_CONNECTION_DISPATCH
*dispatch
, PEPROCESS process
, PETHREAD owning
,
106 SECURITY_DESCRIPTOR
*descriptor
, IRP
*irp
);
107 typedef NTSTATUS (WINAPI
*PFN_WSK_CONTROL_CLIENT
)(WSK_CLIENT
*client
, ULONG control
,
108 SIZE_T input_size
, void *input
, SIZE_T output_size
, void *output
, SIZE_T
*returned
,
110 typedef NTSTATUS (WINAPI
*PFN_WSK_GET_ADDRESS_INFO
)(WSK_CLIENT
*client
, UNICODE_STRING
*node_name
,
111 UNICODE_STRING
*service_name
, ULONG name_space
, GUID
*provider
, ADDRINFOEXW
*hints
,
112 ADDRINFOEXW
**result
, PEPROCESS process
, PETHREAD thread
, IRP
*irp
);
113 typedef void (WINAPI
*PFN_WSK_FREE_ADDRESS_INFO
)(WSK_CLIENT
*client
, ADDRINFOEXW
*addrinfo
);
114 typedef NTSTATUS (WINAPI
*PFN_WSK_GET_NAME_INFO
)(WSK_CLIENT
*client
, SOCKADDR
*addr
,
115 ULONG length
, UNICODE_STRING
*node_name
, UNICODE_STRING
*service_name
,
116 ULONG flags
, PEPROCESS process
, PETHREAD thread
, IRP
*irp
);
117 typedef NTSTATUS (WINAPI
* PFN_WSK_RECEIVE_EVENT
)(void *context
, ULONG flags
,
118 WSK_DATA_INDICATION
*indication
, SIZE_T size
, SIZE_T
*accepted
);
120 typedef struct _WSK_PROVIDER_DISPATCH
124 PFN_WSK_SOCKET WskSocket
;
125 PFN_WSK_SOCKET_CONNECT WskSocketConnect
;
126 PFN_WSK_CONTROL_CLIENT WskControlClient
;
127 PFN_WSK_GET_ADDRESS_INFO WskGetAddressInfo
;
128 PFN_WSK_FREE_ADDRESS_INFO WskFreeAddressInfo
;
129 PFN_WSK_GET_NAME_INFO WskGetNameInfo
;
130 } WSK_PROVIDER_DISPATCH
, *PWSK_PROVIDER_DISPATCH
;
132 typedef struct _WSK_CLIENT_CONNECTION_DISPATCH
134 PFN_WSK_RECEIVE_EVENT WskReceiveEvent
;
135 PFN_WSK_DISCONNECT_EVENT WskDisconnectEvent
;
136 PFN_WSK_SEND_BACKLOG_EVENT WskSendBacklogEvent
;
137 } WSK_CLIENT_CONNECTION_DISPATCH
, *PWSK_CLIENT_CONNECTION_DISPATCH
;
139 typedef NTSTATUS (WINAPI
*PFN_WSK_ACCEPT_EVENT
)(void *socket_context
, ULONG flags
, SOCKADDR
*local_address
,
140 SOCKADDR
*remote_address
, WSK_SOCKET
*accept_socket
, void *accept_socket_context
,
141 const WSK_CLIENT_CONNECTION_DISPATCH
**accept_socket_dispatch
);
142 typedef WSK_INSPECT_ACTION (WINAPI
*PFN_WSK_INSPECT_EVENT
)(void *socket_context
, SOCKADDR
*local_address
,
143 SOCKADDR
*remote_address
, WSK_INSPECT_ID
*inspect_id
);
144 typedef NTSTATUS (WINAPI
*PFN_WSK_ABORT_EVENT
)(void *socket_context
, WSK_INSPECT_ID
*inspect_id
);
146 typedef struct _WSK_CLIENT_LISTEN_DISPATCH
148 PFN_WSK_ACCEPT_EVENT WskAcceptEvent
;
149 PFN_WSK_INSPECT_EVENT WskInspectEvent
;
150 PFN_WSK_ABORT_EVENT WskAbortEvent
;
151 } WSK_CLIENT_LISTEN_DISPATCH
, *PWSK_CLIENT_LISTEN_DISPATCH
;
153 typedef struct _WSK_CLIENT_DISPATCH
157 PFN_WSK_CLIENT_EVENT WskClientEvent
;
158 } WSK_CLIENT_DISPATCH
, *PWSK_CLIENT_DISPATCH
;
160 typedef struct _WSK_CLIENT_NPI
163 const WSK_CLIENT_DISPATCH
*Dispatch
;
164 } WSK_CLIENT_NPI
, *PWSK_CLIENT_NPI
;
166 typedef struct _WSK_REGISTRATION
168 ULONGLONG ReservedRegistrationState
;
169 void *ReservedRegistrationContext
;
170 KSPIN_LOCK ReservedRegistrationLock
;
171 } WSK_REGISTRATION
, *PWSK_REGISTRATION
;
173 typedef struct _WSK_PROVIDER_NPI
176 const WSK_PROVIDER_DISPATCH
*Dispatch
;
177 } WSK_PROVIDER_NPI
, *PWSK_PROVIDER_NPI
;
179 typedef NTSTATUS (WINAPI
*PFN_WSK_CONTROL_SOCKET
)(WSK_SOCKET
*socket
, WSK_CONTROL_SOCKET_TYPE request_type
,
180 ULONG control_code
, ULONG level
, SIZE_T input_size
, void *input_buffer
, SIZE_T output_size
,
181 void *output_buffer
, SIZE_T
*output_size_returned
, IRP
*irp
);
182 typedef NTSTATUS (WINAPI
*PFN_WSK_CLOSE_SOCKET
)(WSK_SOCKET
*socket
, IRP
*irp
);
183 typedef NTSTATUS (WINAPI
*PFN_WSK_BIND
)(WSK_SOCKET
*socket
, SOCKADDR
*local_address
, ULONG flags
, IRP
*irp
);
184 typedef NTSTATUS (WINAPI
*PFN_WSK_ACCEPT
)(WSK_SOCKET
*listen_socket
, ULONG flags
, void *accept_socket_context
,
185 const WSK_CLIENT_CONNECTION_DISPATCH
*accept_socket_dispatch
, SOCKADDR
*local_address
,
186 SOCKADDR
*remote_address
, IRP
*irp
);
187 typedef NTSTATUS (WINAPI
*PFN_WSK_CONNECT
)(WSK_SOCKET
*socket
, SOCKADDR
*remote_address
, ULONG flags
, IRP
*irp
);
188 typedef NTSTATUS (WINAPI
*PFN_WSK_LISTEN
)(WSK_SOCKET
*socket
, IRP
*irp
);
189 typedef NTSTATUS (WINAPI
*PFN_WSK_SEND
)(WSK_SOCKET
*socket
, WSK_BUF
*buffer
, ULONG flags
, IRP
*irp
);
190 typedef NTSTATUS (WINAPI
*PFN_WSK_RECEIVE
)(WSK_SOCKET
*socket
, WSK_BUF
*buffer
, ULONG flags
, IRP
*irp
);
191 typedef NTSTATUS (WINAPI
*PFN_WSK_DISCONNECT
)(WSK_SOCKET
*socket
, WSK_BUF
*buffer
, ULONG flags
, IRP
*irp
);
192 typedef NTSTATUS (WINAPI
*PFN_WSK_GET_LOCAL_ADDRESS
)(WSK_SOCKET
*socket
, SOCKADDR
*local_address
, IRP
*irp
);
193 typedef NTSTATUS (WINAPI
*PFN_WSK_GET_REMOTE_ADDRESS
)(WSK_SOCKET
*socket
, SOCKADDR
*remote_address
, IRP
*irp
);
194 typedef NTSTATUS (WINAPI
*PFN_WSK_CONNECT_EX
)(WSK_SOCKET
*socket
, SOCKADDR
*remote_address
, WSK_BUF
*buffer
,
195 ULONG flags
, IRP
*irp
);
196 typedef NTSTATUS (WINAPI
*PFN_WSK_RELEASE_DATA_INDICATION_LIST
)(WSK_SOCKET
*socket
,
197 WSK_DATA_INDICATION
*data_indication
);
198 typedef NTSTATUS (WINAPI
*PFN_WSK_SEND_MESSAGES
) (WSK_SOCKET
*socket
, WSK_BUF_LIST
*buffer_list
, ULONG flags
,
199 SOCKADDR
*remote_address
, ULONG control_info_length
, CMSGHDR
*control_info
, IRP
*irp
);
200 typedef NTSTATUS (WINAPI
*PFN_WSK_SEND_TO
)(WSK_SOCKET
*socket
, WSK_BUF
*buffer
, ULONG flags
, SOCKADDR
*remote_address
,
201 ULONG control_info_length
, CMSGHDR
*control_info
, IRP
*irp
);
202 typedef NTSTATUS (WINAPI
*PFN_WSK_RECEIVE_FROM
)(WSK_SOCKET
*socket
, WSK_BUF
*buffer
, ULONG flags
,
203 SOCKADDR
*remote_address
, ULONG
*control_length
, CMSGHDR
*control_info
, ULONG
*control_flags
, IRP
*irp
);
204 typedef NTSTATUS (WINAPI
*PFN_WSK_RELEASE_DATAGRAM_INDICATION_LIST
)(WSK_SOCKET
*socket
,
205 WSK_DATAGRAM_INDICATION
*datagram_indication
);
206 typedef NTSTATUS (WINAPI
*PFN_WSK_INSPECT_COMPLETE
)(WSK_SOCKET
*listen_socket
, WSK_INSPECT_ID
*inspect_id
,
207 WSK_INSPECT_ACTION action
, IRP
*irp
);
209 /* PFN_WSK_SEND_EX, PFN_WSK_RECEIVE_EX functions are undocumented and reserved for system use. */
210 typedef void *PFN_WSK_SEND_EX
;
211 typedef void *PFN_WSK_RECEIVE_EX
;
213 typedef struct _WSK_PROVIDER_BASIC_DISPATCH
215 PFN_WSK_CONTROL_SOCKET WskControlSocket
;
216 PFN_WSK_CLOSE_SOCKET WskCloseSocket
;
217 } WSK_PROVIDER_BASIC_DISPATCH
, *PWSK_PROVIDER_BASIC_DISPATCH
;
219 typedef struct _WSK_PROVIDER_STREAM_DISPATCH
221 WSK_PROVIDER_BASIC_DISPATCH Basic
;
222 PFN_WSK_BIND WskBind
;
223 PFN_WSK_ACCEPT WskAccept
;
224 PFN_WSK_CONNECT WskConnect
;
225 PFN_WSK_LISTEN WskListen
;
226 PFN_WSK_SEND WskSend
;
227 PFN_WSK_RECEIVE WskReceive
;
228 PFN_WSK_DISCONNECT WskDisconnect
;
229 PFN_WSK_RELEASE_DATA_INDICATION_LIST WskRelease
;
230 PFN_WSK_GET_LOCAL_ADDRESS WskGetLocalAddress
;
231 PFN_WSK_GET_REMOTE_ADDRESS WskGetRemoteAddress
;
232 PFN_WSK_CONNECT_EX WskConnectEx
;
233 PFN_WSK_SEND_EX WskSendEx
;
234 PFN_WSK_RECEIVE_EX WskReceiveEx
;
235 } WSK_PROVIDER_STREAM_DISPATCH
, *PWSK_PROVIDER_STREAM_DISPATCH
;
237 typedef struct _WSK_PROVIDER_CONNECTION_DISPATCH
239 WSK_PROVIDER_BASIC_DISPATCH Basic
;
240 PFN_WSK_BIND WskBind
;
241 PFN_WSK_CONNECT WskConnect
;
242 PFN_WSK_GET_LOCAL_ADDRESS WskGetLocalAddress
;
243 PFN_WSK_GET_REMOTE_ADDRESS WskGetRemoteAddress
;
244 PFN_WSK_SEND WskSend
;
245 PFN_WSK_RECEIVE WskReceive
;
246 PFN_WSK_DISCONNECT WskDisconnect
;
247 PFN_WSK_RELEASE_DATA_INDICATION_LIST WskRelease
;
248 PFN_WSK_CONNECT_EX WskConnectEx
;
249 PFN_WSK_SEND_EX WskSendEx
;
250 PFN_WSK_RECEIVE_EX WskReceiveEx
;
251 } WSK_PROVIDER_CONNECTION_DISPATCH
, *PWSK_PROVIDER_CONNECTION_DISPATCH
;
253 typedef struct _WSK_PROVIDER_DATAGRAM_DISPATCH
255 WSK_PROVIDER_BASIC_DISPATCH Basic
;
256 PFN_WSK_BIND WskBind
;
257 PFN_WSK_SEND_TO WskSendTo
;
258 PFN_WSK_RECEIVE_FROM WskReceiveFrom
;
259 PFN_WSK_RELEASE_DATAGRAM_INDICATION_LIST WskRelease
;
260 PFN_WSK_GET_LOCAL_ADDRESS WskGetLocalAddress
;
261 PFN_WSK_SEND_MESSAGES WskSendMessages
;
262 } WSK_PROVIDER_DATAGRAM_DISPATCH
, *PWSK_PROVIDER_DATAGRAM_DISPATCH
;
264 typedef struct _WSK_PROVIDER_LISTEN_DISPATCH
266 WSK_PROVIDER_BASIC_DISPATCH Basic
;
267 PFN_WSK_BIND WskBind
;
268 PFN_WSK_ACCEPT WskAccept
;
269 PFN_WSK_INSPECT_COMPLETE WskInspectComplete
;
270 PFN_WSK_GET_LOCAL_ADDRESS WskGetLocalAddress
;
271 } WSK_PROVIDER_LISTEN_DISPATCH
, *PWSK_PROVIDER_LISTEN_DISPATCH
;
273 NTSTATUS WINAPI
WskRegister(WSK_CLIENT_NPI
*wsk_client_npi
, WSK_REGISTRATION
*wsk_registration
);
274 void WINAPI
WskDeregister(WSK_REGISTRATION
*wsk_registration
);
275 NTSTATUS WINAPI
WskCaptureProviderNPI(WSK_REGISTRATION
*wsk_registration
, ULONG wait_timeout
,
276 WSK_PROVIDER_NPI
*wsk_provider_npi
);
277 void WINAPI
WskReleaseProviderNPI(WSK_REGISTRATION
*wsk_registration
);