windivert_sys/bindings/
mod.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5pub mod address;
6pub mod header;
7pub mod ioctl;
8
9mod bitfield;
10use std::ffi::c_void;
11
12pub(crate) use bitfield::BitfieldUnit;
13mod error;
14pub use error::*;
15mod newtypes;
16pub use newtypes::*;
17
18use windows::Win32::{
19    Foundation::{BOOL, HANDLE},
20    System::IO::OVERLAPPED,
21};
22/// Default value for queue length parameter.
23pub const WINDIVERT_PARAM_QUEUE_LENGTH_DEFAULT: u64 = 4096;
24/// Minimum valid value for queue length parameter.
25pub const WINDIVERT_PARAM_QUEUE_LENGTH_MIN: u64 = 32;
26/// Maximum valid value for queue length parameter.
27pub const WINDIVERT_PARAM_QUEUE_LENGTH_MAX: u64 = 16384;
28/// Default value for queue time parameter.
29pub const WINDIVERT_PARAM_QUEUE_TIME_DEFAULT: u64 = 2000; /* 2s */
30/// Minimum valid value for queue time parameter.
31pub const WINDIVERT_PARAM_QUEUE_TIME_MIN: u64 = 100; /* 100ms */
32/// Maximum valid value for queue time parameter.
33pub const WINDIVERT_PARAM_QUEUE_TIME_MAX: u64 = 16000; /* 16s */
34/// Default value for queue size parameter.
35pub const WINDIVERT_PARAM_QUEUE_SIZE_DEFAULT: u64 = 4194304; /* 4MB */
36/// Minimum valid value for queue size parameter.
37pub const WINDIVERT_PARAM_QUEUE_SIZE_MIN: u64 = 65535; /* 64KB */
38/// Maximum valid value for queue size parameter.
39pub const WINDIVERT_PARAM_QUEUE_SIZE_MAX: u64 = 33554432; /* 32MB */
40/// Maximum valid value for priority parameter.
41pub const WINDIVERT_PRIORITY_MAX: u32 = 30000;
42/// Minimum valid value for priority parameter.
43pub const WINDIVERT_PRIORITY_MIN: i32 = -30000;
44/// Maximum valid batch length.
45pub const WINDIVERT_BATCH_MAX: u32 = 255;
46/// Maximum valid mtu size.
47pub const WINDIVERT_MTU_MAX: u32 = 65575;
48
49extern "C" {
50    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_open)
51    pub fn WinDivertOpen(
52        filter: *const ::std::os::raw::c_char,
53        layer: WinDivertLayer,
54        priority: i16,
55        flags: WinDivertFlags,
56    ) -> HANDLE;
57
58    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_recv)
59    pub fn WinDivertRecv(
60        handle: HANDLE,
61        pPacket: *mut ::std::os::raw::c_void,
62        packetLen: u32,
63        pRecvLen: *mut u32,
64        pAddr: *mut address::WINDIVERT_ADDRESS,
65    ) -> BOOL;
66
67    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_recv_ex)
68    pub fn WinDivertRecvEx(
69        handle: HANDLE,
70        pPacket: *mut ::std::os::raw::c_void,
71        packetLen: u32,
72        pRecvLen: *mut u32,
73        flags: u64,
74        pAddr: *mut address::WINDIVERT_ADDRESS,
75        pAddrLen: *mut u32,
76        lpOverlapped: *mut OVERLAPPED,
77    ) -> BOOL;
78
79    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_send)
80    pub fn WinDivertSend(
81        handle: HANDLE,
82        pPacket: *const ::std::os::raw::c_void,
83        packetLen: u32,
84        pSendLen: *mut u32,
85        pAddr: *const address::WINDIVERT_ADDRESS,
86    ) -> BOOL;
87
88    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_send_ex)
89    pub fn WinDivertSendEx(
90        handle: HANDLE,
91        pPacket: *const ::std::os::raw::c_void,
92        packetLen: u32,
93        pSendLen: *mut u32,
94        flags: u64,
95        pAddr: *const address::WINDIVERT_ADDRESS,
96        addrLen: u32,
97        lpOverlapped: *mut OVERLAPPED,
98    ) -> BOOL;
99
100    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_shutdown)
101    pub fn WinDivertShutdown(handle: HANDLE, how: WinDivertShutdownMode) -> BOOL;
102
103    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_close)
104    pub fn WinDivertClose(handle: HANDLE) -> BOOL;
105
106    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_set_param)
107    pub fn WinDivertSetParam(handle: HANDLE, param: WinDivertParam, value: u64) -> BOOL;
108
109    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_get_param)
110    pub fn WinDivertGetParam(handle: HANDLE, param: WinDivertParam, pValue: *mut u64) -> BOOL;
111}
112
113extern "C" {
114    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_packet)
115    pub fn WinDivertHelperParsePacket(
116        pPacket: *const ::std::os::raw::c_void,
117        packetLen: u32,
118        ppIpHdr: *mut header::PWINDIVERT_IPHDR,
119        ppIpv6Hdr: *mut header::PWINDIVERT_IPV6HDR,
120        pProtocol: *mut u8,
121        ppIcmpHdr: *mut header::PWINDIVERT_ICMPHDR,
122        ppIcmpv6Hdr: *mut header::PWINDIVERT_ICMPV6HDR,
123        ppTcpHdr: *mut header::PWINDIVERT_TCPHDR,
124        ppUdpHdr: *mut header::PWINDIVERT_UDPHDR,
125        ppData: *mut c_void,
126        pDataLen: *mut u32,
127        ppNext: *mut c_void,
128        pNextLen: *mut u32,
129    ) -> BOOL;
130
131    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hash_packet)
132    pub fn WinDivertHelperHashPacket(
133        pPacket: *const ::std::os::raw::c_void,
134        packetLen: u32,
135        seed: u64,
136    ) -> u64;
137
138    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_ipv4_address)
139    pub fn WinDivertHelperParseIPv4Address(
140        addrStr: *const ::std::os::raw::c_char,
141        pAddr: *mut u32,
142    ) -> BOOL;
143
144    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_ipv6_address)
145    pub fn WinDivertHelperParseIPv6Address(
146        addrStr: *const ::std::os::raw::c_char,
147        pAddr: *mut u32,
148    ) -> BOOL;
149
150    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_ipv4_address)
151    pub fn WinDivertHelperFormatIPv4Address(
152        addr: u32,
153        buffer: *mut ::std::os::raw::c_char,
154        bufLen: u32,
155    ) -> BOOL;
156
157    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_ipv6_address)
158    pub fn WinDivertHelperFormatIPv6Address(
159        pAddr: *const u32,
160        buffer: *mut ::std::os::raw::c_char,
161        bufLen: u32,
162    ) -> BOOL;
163
164    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_calc_checksums)
165    pub fn WinDivertHelperCalcChecksums(
166        pPacket: *mut ::std::os::raw::c_void,
167        packetLen: u32,
168        pAddr: *mut address::WINDIVERT_ADDRESS,
169        flags: ChecksumFlags,
170    ) -> BOOL;
171
172    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_dec_ttl)
173    pub fn WinDivertHelperDecrementTTL(
174        pPacket: *mut ::std::os::raw::c_void,
175        packetLen: u32,
176    ) -> BOOL;
177
178    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_compile_filter)
179    pub fn WinDivertHelperCompileFilter(
180        filter: *const ::std::os::raw::c_char,
181        layer: WinDivertLayer,
182        object: *mut ::std::os::raw::c_char,
183        objLen: u32,
184        errorStr: *mut *const ::std::os::raw::c_char,
185        errorPos: *mut u32,
186    ) -> BOOL;
187
188    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_eval_filter)
189    pub fn WinDivertHelperEvalFilter(
190        filter: *const ::std::os::raw::c_char,
191        pPacket: *const ::std::os::raw::c_void,
192        packetLen: u32,
193        pAddr: *const address::WINDIVERT_ADDRESS,
194    ) -> BOOL;
195
196    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_filter)
197    pub fn WinDivertHelperFormatFilter(
198        filter: *const ::std::os::raw::c_char,
199        layer: WinDivertLayer,
200        buffer: *mut ::std::os::raw::c_char,
201        bufLen: u32,
202    ) -> BOOL;
203
204    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
205    pub fn WinDivertHelperNtohs(x: u16) -> u16;
206
207    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hton)
208    pub fn WinDivertHelperHtons(x: u16) -> u16;
209
210    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
211    pub fn WinDivertHelperNtohl(x: u32) -> u32;
212
213    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hton)
214    pub fn WinDivertHelperHtonl(x: u32) -> u32;
215
216    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
217    pub fn WinDivertHelperNtohll(x: u64) -> u64;
218
219    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hton)
220    pub fn WinDivertHelperHtonll(x: u64) -> u64;
221
222    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
223    pub fn WinDivertHelperNtohIPv6Address(inAddr: *const u32, outAddr: *mut u32);
224
225    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hton)
226    pub fn WinDivertHelperHtonIPv6Address(inAddr: *const u32, outAddr: *mut u32);
227
228    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
229    pub fn WinDivertHelperNtohIpv6Address(inAddr: *const u32, outAddr: *mut u32);
230
231    /// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hton)
232    pub fn WinDivertHelperHtonIpv6Address(inAddr: *const u32, outAddr: *mut u32);
233}