-
Notifications
You must be signed in to change notification settings - Fork 49
/
libwsk.h
238 lines (201 loc) · 6.02 KB
/
libwsk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#pragma once
#include "global.h"
#include <wsk.h>
#define SOCKET ULONG_PTR
extern SOCKET ClientSocket;
NTSTATUS
StartWSKClientUDP(
_In_opt_ LPCWSTR NodeName,
_In_opt_ LPCWSTR ServiceName,
_In_ ADDRESS_FAMILY AddressFamily,
_In_ USHORT SocketType
);
VOID CloseWSKClient();
#ifndef WSK_INVALID_SOCKET
# define WSK_INVALID_SOCKET static_cast<SOCKET>(~0)
#endif
#ifndef WSK_FLAG_INVALID_SOCKET
# define WSK_FLAG_INVALID_SOCKET 0xffffffff
#endif
#ifndef WSK_FLAG_STREAM_SOCKET
# define WSK_FLAG_STREAM_SOCKET 0x00000008
#endif
typedef struct WSKOVERLAPPED
{
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
ULONG Offset;
ULONG OffsetHigh;
} DUMMYSTRUCTNAME;
PVOID Pointer;
} DUMMYUNIONNAME;
KEVENT Event;
}
WSKOVERLAPPED;
typedef VOID(*LPWSKOVERLAPPED_COMPLETION_ROUTINE)
(
_In_ NTSTATUS,
_In_ ULONG_PTR,
_In_ WSKOVERLAPPED*
);
VOID WSKAPI WSKSetLastError(
_In_ NTSTATUS Status
);
NTSTATUS WSKAPI WSKGetLastError();
typedef struct WSKDATA
{
UINT16 HighestVersion;
UINT16 LowestVersion;
}
WSKDATA;
NTSTATUS WSKAPI WSKStartup(
_In_ UINT16 Version,
_Out_ WSKDATA* WSKData
);
VOID WSKAPI WSKCleanup();
VOID WSKAPI WSKCreateEvent(
_Out_ KEVENT* Event
);
NTSTATUS WSKAPI WSKGetOverlappedResult(
_In_ SOCKET Socket,
_In_ WSKOVERLAPPED* Overlapped,
_Out_opt_ SIZE_T* TransferBytes,
_In_ BOOLEAN Wait
);
NTSTATUS WSKAPI WSKGetAddrInfo(
_In_opt_ LPCWSTR NodeName,
_In_opt_ LPCWSTR ServiceName,
_In_ UINT32 Namespace,
_In_opt_ GUID* Provider,
_In_opt_ PADDRINFOEXW Hints,
_Outptr_result_maybenull_ PADDRINFOEXW* Result,
_In_opt_ UINT32 TimeoutMilliseconds,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);
VOID WSKAPI WSKFreeAddrInfo(
_In_ PADDRINFOEXW Data
);
NTSTATUS WSKAPI WSKGetNameInfo(
_In_ const SOCKADDR* Address,
_In_ ULONG AddressLength,
_Out_writes_opt_(NodeNameSize) LPWSTR NodeName,
_In_ ULONG NodeNameSize,
_Out_writes_opt_(ServiceNameSize) LPWSTR ServiceName,
_In_ ULONG ServiceNameSize,
_In_ ULONG Flags
);
NTSTATUS WSKAPI WSKAddressToString(
_In_reads_bytes_(AddressLength) SOCKADDR* SockAddress,
_In_ UINT32 AddressLength,
_Out_writes_to_(*AddressStringLength, *AddressStringLength) LPWSTR AddressString,
_Inout_ UINT32* AddressStringLength
);
NTSTATUS WSKAPI WSKStringToAddress(
_In_ PCWSTR AddressString,
_Inout_ SOCKADDR* SockAddress, // must init Address->si_family
_Inout_ UINT32* AddressLength
);
NTSTATUS WSKAPI WSKSocket(
_Out_ SOCKET* Socket,
_In_ ADDRESS_FAMILY AddressFamily,
_In_ USHORT SocketType,
_In_ ULONG Protocol,
_In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
);
NTSTATUS WSKAPI WSKCloseSocket(
_In_ SOCKET Socket
);
NTSTATUS WSKAPI WSKIoctl(
_In_ SOCKET Socket,
_In_ ULONG ControlCode,
_In_reads_bytes_opt_(InputSize) PVOID InputBuffer,
_In_ SIZE_T InputSize,
_Out_writes_bytes_opt_(OutputSize) PVOID OutputBuffer,
_In_ SIZE_T OutputSize,
_Out_opt_ SIZE_T* OutputSizeReturned,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);
NTSTATUS WSKAPI WSKSetSocketOpt(
_In_ SOCKET Socket,
_In_ ULONG OptionLevel, // SOL_xxxx
_In_ ULONG OptionName, // SO_xxxx
_In_reads_bytes_(InputSize) PVOID InputBuffer,
_In_ SIZE_T InputSize
);
NTSTATUS WSKAPI WSKGetSocketOpt(
_In_ SOCKET Socket,
_In_ ULONG OptionLevel, // SOL_xxxx
_In_ ULONG OptionName, // SO_xxxx
_Out_writes_bytes_(*OutputSize) PVOID OutputBuffer,
_Inout_ SIZE_T* OutputSize
);
NTSTATUS WSKAPI WSKBind(
_In_ SOCKET Socket,
_In_ PSOCKADDR LocalAddress,
_In_ SIZE_T LocalAddressLength
);
NTSTATUS WSKAPI WSKAccpet(
_In_ SOCKET Socket,
_Out_ SOCKET* SocketClient,
_Out_opt_ PSOCKADDR LocalAddress,
_In_ SIZE_T LocalAddressLength,
_Out_opt_ PSOCKADDR RemoteAddress,
_In_ SIZE_T RemoteAddressLength
);
NTSTATUS WSKAPI WSKListen(
_In_ SOCKET Socket,
_In_ INT BackLog
);
NTSTATUS WSKAPI WSKConnect(
_In_ SOCKET Socket,
_In_ PSOCKADDR RemoteAddress,
_In_ SIZE_T RemoteAddressLength
);
NTSTATUS WSKAPI WSKDisconnect(
_In_ SOCKET Socket,
_In_ ULONG Flags
);
NTSTATUS WSKAPI WSKSend(
_In_ SOCKET Socket,
_In_ PVOID Buffer,
_In_ SIZE_T BufferLength,
_Out_opt_ SIZE_T* NumberOfBytesSent,
_In_ ULONG Flags,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);
NTSTATUS WSKAPI WSKSendTo(
_In_ SOCKET Socket,
_In_ PVOID Buffer,
_In_ SIZE_T BufferLength,
_Out_opt_ SIZE_T* NumberOfBytesSent,
_Reserved_ ULONG Flags,
_In_opt_ PSOCKADDR RemoteAddress,
_In_ SIZE_T RemoteAddressLength,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);
NTSTATUS WSKAPI WSKReceive(
_In_ SOCKET Socket,
_In_ PVOID Buffer,
_In_ SIZE_T BufferLength,
_Out_opt_ SIZE_T* NumberOfBytesRecvd,
_In_ ULONG Flags,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);
NTSTATUS WSKAPI WSKReceiveFrom(
_In_ SOCKET Socket,
_In_ PVOID Buffer,
_In_ SIZE_T BufferLength,
_Out_opt_ SIZE_T* NumberOfBytesRecvd,
_Reserved_ ULONG Flags,
_Out_opt_ PSOCKADDR RemoteAddress,
_In_ SIZE_T RemoteAddressLength,
_In_opt_ WSKOVERLAPPED* Overlapped,
_In_opt_ LPWSKOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
);