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
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
pub mod address;
pub mod header;
pub mod ioctl;
mod bitfield;
pub(crate) use bitfield::BitfieldUnit;
mod error;
pub use error::*;
mod newtypes;
pub use newtypes::*;
use winapi::{
shared::{
minwindef::BOOL,
ntdef::{HANDLE, PVOID},
},
um::minwinbase::LPOVERLAPPED,
};
pub const WINDIVERT_PARAM_QUEUE_LENGTH_DEFAULT: u64 = 4096;
pub const WINDIVERT_PARAM_QUEUE_LENGTH_MIN: u64 = 32;
pub const WINDIVERT_PARAM_QUEUE_LENGTH_MAX: u64 = 16384;
pub const WINDIVERT_PARAM_QUEUE_TIME_DEFAULT: u64 = 2000;
pub const WINDIVERT_PARAM_QUEUE_TIME_MIN: u64 = 100;
pub const WINDIVERT_PARAM_QUEUE_TIME_MAX: u64 = 16000;
pub const WINDIVERT_PARAM_QUEUE_SIZE_DEFAULT: u64 = 4194304;
pub const WINDIVERT_PARAM_QUEUE_SIZE_MIN: u64 = 65535;
pub const WINDIVERT_PARAM_QUEUE_SIZE_MAX: u64 = 33554432;
extern "C" {
pub fn WinDivertOpen(
filter: *const ::std::os::raw::c_char,
layer: u32,
priority: i16,
flags: WinDivertFlags,
) -> HANDLE;
pub fn WinDivertRecv(
handle: HANDLE,
pPacket: *mut ::std::os::raw::c_void,
packetLen: u32,
pRecvLen: *mut u32,
pAddr: *mut address::WINDIVERT_ADDRESS,
) -> BOOL;
pub fn WinDivertRecvEx(
handle: HANDLE,
pPacket: *mut ::std::os::raw::c_void,
packetLen: u32,
pRecvLen: *mut u32,
flags: u64,
pAddr: *mut address::WINDIVERT_ADDRESS,
pAddrLen: *mut u32,
lpOverlapped: LPOVERLAPPED,
) -> BOOL;
pub fn WinDivertSend(
handle: HANDLE,
pPacket: *const ::std::os::raw::c_void,
packetLen: u32,
pSendLen: *mut u32,
pAddr: *const address::WINDIVERT_ADDRESS,
) -> BOOL;
pub fn WinDivertSendEx(
handle: HANDLE,
pPacket: *const ::std::os::raw::c_void,
packetLen: u32,
pSendLen: *mut u32,
flags: u64,
pAddr: *const address::WINDIVERT_ADDRESS,
addrLen: u32,
lpOverlapped: LPOVERLAPPED,
) -> BOOL;
pub fn WinDivertShutdown(handle: HANDLE, how: WinDivertShutdownMode) -> BOOL;
pub fn WinDivertClose(handle: HANDLE) -> BOOL;
pub fn WinDivertSetParam(handle: HANDLE, param: WinDivertParam, value: u64) -> BOOL;
pub fn WinDivertGetParam(handle: HANDLE, param: WinDivertParam, pValue: *mut u64) -> BOOL;
}
extern "C" {
pub fn WinDivertHelperParsePacket(
pPacket: *const ::std::os::raw::c_void,
packetLen: u32,
ppIpHdr: *mut header::PWINDIVERT_IPHDR,
ppIpv6Hdr: *mut header::PWINDIVERT_IPV6HDR,
pProtocol: *mut u8,
ppIcmpHdr: *mut header::PWINDIVERT_ICMPHDR,
ppIcmpv6Hdr: *mut header::PWINDIVERT_ICMPV6HDR,
ppTcpHdr: *mut header::PWINDIVERT_TCPHDR,
ppUdpHdr: *mut header::PWINDIVERT_UDPHDR,
ppData: *mut PVOID,
pDataLen: *mut u32,
ppNext: *mut PVOID,
pNextLen: *mut u32,
) -> BOOL;
pub fn WinDivertHelperHashPacket(
pPacket: *const ::std::os::raw::c_void,
packetLen: u32,
seed: u64,
) -> u64;
pub fn WinDivertHelperParseIPv4Address(
addrStr: *const ::std::os::raw::c_char,
pAddr: *mut u32,
) -> BOOL;
pub fn WinDivertHelperParseIPv6Address(
addrStr: *const ::std::os::raw::c_char,
pAddr: *mut u32,
) -> BOOL;
pub fn WinDivertHelperFormatIPv4Address(
addr: u32,
buffer: *mut ::std::os::raw::c_char,
bufLen: u32,
) -> BOOL;
pub fn WinDivertHelperFormatIPv6Address(
pAddr: *const u32,
buffer: *mut ::std::os::raw::c_char,
bufLen: u32,
) -> BOOL;
pub fn WinDivertHelperCalcChecksums(
pPacket: *mut ::std::os::raw::c_void,
packetLen: u32,
pAddr: *mut address::WINDIVERT_ADDRESS,
flags: ChecksumFlags,
) -> BOOL;
pub fn WinDivertHelperDecrementTTL(
pPacket: *mut ::std::os::raw::c_void,
packetLen: u32,
) -> BOOL;
pub fn WinDivertHelperCompileFilter(
filter: *const ::std::os::raw::c_char,
layer: u32,
object: *mut ::std::os::raw::c_char,
objLen: u32,
errorStr: *mut *const ::std::os::raw::c_char,
errorPos: *mut u32,
) -> BOOL;
pub fn WinDivertHelperEvalFilter(
filter: *const ::std::os::raw::c_char,
pPacket: *const ::std::os::raw::c_void,
packetLen: u32,
pAddr: *const address::WINDIVERT_ADDRESS,
) -> BOOL;
pub fn WinDivertHelperFormatFilter(
filter: *const ::std::os::raw::c_char,
layer: u32,
buffer: *mut ::std::os::raw::c_char,
bufLen: u32,
) -> BOOL;
pub fn WinDivertHelperNtohs(x: u16) -> u16;
pub fn WinDivertHelperHtons(x: u16) -> u16;
pub fn WinDivertHelperNtohl(x: u32) -> u32;
pub fn WinDivertHelperHtonl(x: u32) -> u32;
pub fn WinDivertHelperNtohll(x: u64) -> u64;
pub fn WinDivertHelperHtonll(x: u64) -> u64;
pub fn WinDivertHelperNtohIPv6Address(inAddr: *const u32, outAddr: *mut u32);
pub fn WinDivertHelperHtonIPv6Address(inAddr: *const u32, outAddr: *mut u32);
pub fn WinDivertHelperNtohIpv6Address(inAddr: *const u32, outAddr: *mut u32);
pub fn WinDivertHelperHtonIpv6Address(inAddr: *const u32, outAddr: *mut u32);
}