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
|
/*++
Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved
Module Name:
notify.h
Abstract:
--*/
#ifndef __TESTAPP_H
#define __TESTAPP_H
#pragma warning(disable:4214 4201 4115 4100)
#define UNICODE 1
#define INITGUID
#include <windows.h> // for using Windows data types and functions
#include <winsock2.h> // for using winsock utility inet_addr/ntohs functions.
#include <setupapi.h> // for using SetupDi functions
#include <dbt.h> // for PNP device notification interfaces
#include <winioctl.h> // for defining ioctls
#include <ntddndis.h> // for NDIS OIDs
#include <strsafe.h> // for safe string functions
#include <devguid.h> // for GUID_DEVCLASS_NET
#include <cfgmgr32.h> // for MAX_GUID_STRING_LEN
#include <OBJBASE.H> // for CLSIDFromString. Link to ole32.lib
#include "public.h"
#include "resource.h"
#include <dontuse.h>
//
// Registry path where the IP addresses are saved
//
#define REG_PATH L"Software\\Microsoft\\PCIDRV\\MyPing"
#define DEF_SOURCE_IP L"192.168.0.2"
#define DEF_DEST_IP L"192.168.0.1"
#define PING_SLEEP_TIME 100
#define MAC_ADDR_LEN 6
#define MAX_LEN 64
#define MAX_PAYLOAD_SIZE 1428
#define MIN_PAYLOAD_SIZE 32
#define MAX_PING_RETRY 10
extern BOOLEAN Verbose;
typedef struct _DEVICE_INFO
{
LIST_ENTRY ListEntry;
HANDLE hDevice; // file handle
HDEVNOTIFY hHandleNotification; // notification handle
TCHAR DeviceName[MAX_PATH];// friendly name of device description
TCHAR DevicePath[MAX_PATH];//
ULONG DeviceIndex; // Serial number of the device.
CHAR SourceIp[MAX_LEN];
CHAR DestIp[MAX_LEN];
WCHAR UnicodeSourceIp[MAX_LEN];
WCHAR UnicodeDestIp[MAX_LEN];
ULONG PacketSize;
UCHAR SrcMacAddr[MAC_ADDR_LEN];
UCHAR TargetMacAddr[MAC_ADDR_LEN];
HANDLE PingEvent;
ULONG NumberOfRequestSent;
BOOL Sleep;
ULONG TimeOut;
BOOL IsANetworkMiniport;
BOOLEAN ExitThread;
HANDLE ThreadHandle;
} DEVICE_INFO, *PDEVICE_INFO;
typedef struct _DIALOG_RESULT
{
ULONG DeviceIndex;
WCHAR SourceIp[MAX_LEN];
WCHAR DestIp[MAX_LEN];
ULONG PacketSize;
} DIALOG_RESULT, *PDIALOG_RESULT;
//
// Copied Macros from ntddk.h. Used to using the kernel-mode
// style of linked list.
//
#define CONTAINING_RECORD(address, type, field) ((type *)( \
(PCHAR)(address) - \
(ULONG_PTR)(&((type *)0)->field)))
#define InitializeListHead(ListHead) (\
(ListHead)->Flink = (ListHead)->Blink = (ListHead))
#define RemoveHeadList(ListHead) \
(ListHead)->Flink;\
{RemoveEntryList((ListHead)->Flink)}
#define IsListEmpty(ListHead) \
((ListHead)->Flink == (ListHead))
#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;\
}
#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);\
}
#ifndef min
#define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
#endif
#ifndef max
#define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
#endif
#define DisplayV(pstrFormat, ...) if (Verbose) {Display(pstrFormat, __VA_ARGS__);}
LRESULT FAR PASCAL
WndProc (
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
);
BOOLEAN EnumExistingDevices(
HWND hWnd
);
BOOL HandleDeviceInterfaceChange(
HWND hwnd,
DWORD evtype,
PDEV_BROADCAST_DEVICEINTERFACE dip
);
BOOL HandleDeviceChange(
HWND hwnd,
DWORD evtype,
PDEV_BROADCAST_HANDLE dhp
);
LRESULT
HandleCommands(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
BOOL
HandlePowerBroadcast(
HWND hWnd,
WPARAM wParam,
LPARAM lParam);
BOOLEAN Cleanup(
HWND hWnd
);
_Success_(return != FALSE)
BOOL
GetDeviceDescription(
_In_ LPTSTR DevPath,
_Out_writes_bytes_all_(OutBufferLen) LPTSTR OutBuffer,
_In_ ULONG OutBufferLen,
BOOL *NetClassDevice
);
BOOLEAN
OpenDevice(
_In_ HWND HWnd,
_In_ PDEVICE_INFO DeviceInfo
);
INT_PTR CALLBACK
DlgProc(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam);
DWORD
PingThread (
PDEVICE_INFO DeviceInfo
);
VOID Display(
_In_ LPWSTR pstrFormat,
...
) ;
BOOL
CreatePingThread(
PDEVICE_INFO DeviceInfo
);
PDEVICE_INFO
FindDeviceInfo(
PDIALOG_RESULT InputInfo
);
VOID
FreeDeviceInfo(
_In_ PDEVICE_INFO DeviceInfo
);
PDEVICE_INFO
CreateDeviceInfo(
_In_ LPWSTR DevicePath
);
VOID
TerminatePingThread(
PDEVICE_INFO DeviceInfo
);
_Success_(return)
BOOL
GetRegistryInfo(
_Out_writes_bytes_(* SourceIPLen) PWSTR SourceIP,
_Inout_ LPDWORD SourceIPLen,
_Out_writes_bytes_(* DestinationIPLen) PWSTR DestinationIP,
_Inout_ LPDWORD DestinationIPLen
);
BOOL
SetRegistryInfo(
_In_reads_bytes_(SourceIPLen) LPWSTR SourceIP,
_In_ DWORD SourceIPLen,
_In_reads_bytes_(DestinationIPLen) LPWSTR DestinationIP,
_In_ DWORD DestinationIPLen
);
#endif
|