-
Notifications
You must be signed in to change notification settings - Fork 14
/
lspcommon.h
350 lines (283 loc) · 8.24 KB
/
lspcommon.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 2004 Microsoft Corporation. All Rights Reserved.
//
// Module Name: provider.h
//
// Description:
//
// This sample illustrates how to develop a layered service provider that is
// capable of counting all bytes transmitted through a TCP/IP socket.
//
// This file contains all datatypes and function prototypes used
// throughout this project.
//
#ifndef _INSTALL_H_
#define _INSTALL_H_
#include <winsock2.h>
#include <ws2spi.h>
// Name of the Winsock DDL which is needed by the installer to determine if
// WSCUpdateProvider is available.
#define WINSOCK_DLL "\\ws2_32.dll"
////////////////////////////////////////////////////////////////////////////////
//
// External defines from lspguid.cpp and provider.cpp
//
////////////////////////////////////////////////////////////////////////////////
// Private heap used for all allocations in LSP as well as install time
extern HANDLE gLspHeap;
// Global GUID under which the LSP dummy entry is installed under
extern GUID gProviderGuid;
// Critical section for printing debug info (to prevent intermingling of messages)
extern CRITICAL_SECTION gDebugCritSec;
// Function definition for the GetLspGuid export which returns an LSPs dummy provider GUID
typedef
void (WSPAPI *LPFN_GETLSPGUID) (GUID *lpGuid);
// For 64-bit systems, we need to know which catalog to operate on
typedef enum
{
LspCatalogBoth = 0,
LspCatalog32Only,
LspCatalog64Only
} WINSOCK_CATALOG;
//
// Extended proc table containing all the Microsoft specific Winsock functions
//
typedef struct _EXT_WSPPROC_TABLE
{
LPFN_ACCEPTEX lpfnAcceptEx;
LPFN_TRANSMITFILE lpfnTransmitFile;
LPFN_GETACCEPTEXSOCKADDRS lpfnGetAcceptExSockaddrs;
LPFN_TRANSMITPACKETS lpfnTransmitPackets;
LPFN_CONNECTEX lpfnConnectEx;
LPFN_DISCONNECTEX lpfnDisconnectEx;
LPFN_WSARECVMSG lpfnWSARecvMsg;
} EXT_WSPPROC_TABLE;
//
// Describes a single catalog entry over which this LSP is layered on. It keeps track
// of the lower provider's dispatch table as well as a list of all the sockets
// created from our provider
//
typedef struct _PROVIDER
{
WSAPROTOCOL_INFOW NextProvider, // Next provider in chain
LayerProvider; // This layered provider
WSPPROC_TABLE NextProcTable; // Proc table of next provider
EXT_WSPPROC_TABLE NextProcTableExt; // Proc table of next provider's extension
DWORD LspDummyId;
WCHAR ProviderPathW[MAX_PATH],
LibraryPathW[MAX_PATH];
INT ProviderPathLen;
LPWSPSTARTUP fnWSPStartup;
WSPDATA WinsockVersion;
HMODULE Module;
INT StartupCount;
LIST_ENTRY SocketList; // List of socket objects belonging to LSP
CRITICAL_SECTION ProviderCritSec;
} PROVIDER, * LPPROVIDER;
////////////////////////////////////////////////////////////////////////////////
//
// Provider.cpp prototypes
//
////////////////////////////////////////////////////////////////////////////////
BOOL
FindLspEntries(
PROVIDER **lspProviders,
int *lspProviderCount,
int *lpErrno
);
PROVIDER *
FindMatchingLspEntryForProtocolInfo(
WSAPROTOCOL_INFOW *inInfo,
PROVIDER *lspProviders,
int lspCount,
BOOL fromStartup = FALSE
);
// Initialize the given provider by calling its WSPStartup
int
InitializeProvider(
PROVIDER *provider,
WORD wVersion,
WSAPROTOCOL_INFOW *lpProtocolInfo,
WSPUPCALLTABLE UpCallTable,
int *Error
);
BOOL
LoadProviderPath(
PROVIDER *loadProvider,
int *lpErrno
);
// Verifies all the function pointers in the proc table are non-NULL
int
VerifyProcTable(
LPWSPPROC_TABLE lpProcTable
);
// Returns an array of protocol entries from the given Winsock catalog
LPWSAPROTOCOL_INFOW
EnumerateProviders(
WINSOCK_CATALOG Catalog,
LPINT TotalProtocols
);
// Enumerates the given Winsock catalog into the already allocated buffer
int
EnumerateProvidersExisting(
WINSOCK_CATALOG Catalog,
WSAPROTOCOL_INFOW *ProtocolInfo,
LPDWORD ProtocolInfoSize
);
// Free the array of protocol entries returned from EnumerateProviders
void
FreeProviders(
LPWSAPROTOCOL_INFOW ProtocolInfo
);
// Prints a protocol entry to the console in a readable, formatted form
void
PrintProtocolInfo(
WSAPROTOCOL_INFOW *ProtocolInfo
);
// Allocates a buffer from the LSP private heap
void *
LspAlloc(
SIZE_T size,
int *lpErrno
);
// Frees a buffer previously allocated by LspAlloc
void
LspFree(
LPVOID buf
);
// Creates the private heap used by the LSP and installer
int
LspCreateHeap(
int *lpErrno
);
// Destroys the private heap
void
LspDestroyHeap(
);
/*++
LINK list:
Definitions for a double link list.
--*/
//
// Calculate the address of the base of the structure given its type, and an
// address of a field within the structure.
//
#ifndef CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field) \
((type *)((PCHAR)(address) - (ULONG_PTR)(&((type *)0)->field)))
#endif
#ifndef InitializeListHead
//
// VOID
// InitializeListHead(
// PLIST_ENTRY ListHead
// );
//
#define InitializeListHead(ListHead) (\
(ListHead)->Flink = (ListHead)->Blink = (ListHead))
//
// BOOLEAN
// IsListEmpty(
// PLIST_ENTRY ListHead
// );
//
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
//
// PLIST_ENTRY
// RemoveHeadList(
// PLIST_ENTRY ListHead
// );
//
#define RemoveHeadList(ListHead) \
(ListHead)->Flink;\
{RemoveEntryList((ListHead)->Flink)}
//
// PLIST_ENTRY
// RemoveTailList(
// PLIST_ENTRY ListHead
// );
//
#define RemoveTailList(ListHead) \
(ListHead)->Blink;\
{RemoveEntryList((ListHead)->Blink)}
//
// VOID
// RemoveEntryList(
// PLIST_ENTRY Entry
// );
//
#define RemoveEntryList(Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_Flink;\
_EX_Flink = (Entry)->Flink;\
_EX_Blink = (Entry)->Blink;\
_EX_Blink->Flink = _EX_Flink;\
_EX_Flink->Blink = _EX_Blink;\
}
//
// VOID
// InsertTailList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertTailList(ListHead,Entry) {\
PLIST_ENTRY _EX_Blink;\
PLIST_ENTRY _EX_ListHead;\
_EX_ListHead = (ListHead);\
_EX_Blink = _EX_ListHead->Blink;\
(Entry)->Flink = _EX_ListHead;\
(Entry)->Blink = _EX_Blink;\
_EX_Blink->Flink = (Entry);\
_EX_ListHead->Blink = (Entry);\
}
//
// VOID
// InsertHeadList(
// PLIST_ENTRY ListHead,
// PLIST_ENTRY Entry
// );
//
#define InsertHeadList(ListHead,Entry) {\
PLIST_ENTRY _EX_Flink;\
PLIST_ENTRY _EX_ListHead;\
_EX_ListHead = (ListHead);\
_EX_Flink = _EX_ListHead->Flink;\
(Entry)->Flink = _EX_Flink;\
(Entry)->Blink = _EX_ListHead;\
_EX_Flink->Blink = (Entry);\
_EX_ListHead->Flink = (Entry);\
}
BOOL IsNodeOnList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry);
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Macro definitions
//
////////////////////////////////////////////////////////////////////////////////
#ifdef ASSERT
#undef ASSERT
#endif
#ifdef _DEBUG
// Prints a message to the debugger
void
dbgprint(
char *format,
...
);
#define ASSERT(exp) \
if ( !(exp) ) \
dbgprint("\n*** Assertion failed: %s\n" \
"*** Source file: %s, line: %d\n\n", \
#exp,__FILE__,__LINE__), DebugBreak()
#else
// On free builds, define these to be empty
#define ASSERT(exp)
#define dbgprint
#endif
#endif