-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwintun.h
48 lines (43 loc) · 1.09 KB
/
wintun.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
#pragma once
extern bool reset_adapter;
extern WINTUN_SESSION_HANDLE Session;
extern GRE* gre;
// This function handles the packet sent by the client through the virtual network card
[[noreturn]] void wintun_receive_loop() {
DWORD PacketSize;
BYTE* Packet;
HANDLE evnt = WintunGetReadWaitEvent(Session);
int i = 0;
while (true) {
// The packets received here is the full ipv4 frame from the Wintun interface
if (reset_adapter) {
std::this_thread::yield();
if (Session)
evnt = WintunGetReadWaitEvent(Session);
continue;
}
Packet = WintunReceivePacket(Session, &PacketSize);
if (!Packet) {
if (i >= 15)
{
i = 0;
WaitForSingleObject(evnt, 1);
continue;
}
i += 1;
continue;
}
i = 0;
// The full frame will be encapsulated over GRE to be sent through the tunnel
gre->sender(reinterpret_cast<char*>(Packet), PacketSize);
WintunReleaseReceivePacket(Session, Packet);
}
}
// Will free Wintun adapter before exiting
BOOL WINAPI exit_handler(DWORD dwCtrlType)
{
WintunCloseAdapter(Adapter);
std::cout << "Exiting..." << std::endl;
exit(0);
return FALSE;
}