tappers/wintun/
dll.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//
3// Copyright (c) 2024 Nathaniel Bennett <me[at]nathanielbennett[dotcom]>
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11#[cfg(feature = "wintun-runtime")]
12mod dlopen;
13#[cfg(not(feature = "wintun-runtime"))]
14mod link;
15
16use std::ptr::NonNull;
17
18#[cfg(feature = "wintun-runtime")]
19pub use dlopen::Wintun;
20#[cfg(not(feature = "wintun-runtime"))]
21pub use link::Wintun;
22
23use windows_sys::core::PCWSTR;
24
25/*
26/// The minimum ring capacity of a Wintun interface.
27pub const WINTUN_MIN_RING_CAPACITY: u32 = 0x20000; // 128kiB
28/// The maximum ring capacity of a Wintun interface.
29pub const WINTUN_MAX_RING_CAPACITY: u32 = 0x4000000; // 64MiB
30/// The maximum IP packet size that can be moved through a Wintun interface.
31const WINTUN_MAX_IP_PACKET_SIZE: u32 = 0xFFFF;
32*/
33
34/// An opaque Wintun adapter type that WINTUN_ADAPTER_HANDLE would point to.
35pub type WintunAdapter = libc::c_void;
36
37/// An opaque Wintun session type that WINTUN_SESSION_HANDLE would point to.
38pub type WintunSession = libc::c_void;
39
40pub type WintunPacket = NonNull<u8>;
41
42/// Called by internal logger to report diagnostic messages.
43///
44/// #Arguments
45/// * `level` The log level of the message
46/// * `timestamp` The time at which the message was logged, measured in 100ns intervals since
47/// 1601-01-01 UTC
48/// * `message` The text of the log message
49pub type WintunLoggerCallback =
50    unsafe extern "C" fn(level: WintunLoggerLevel, timestamp: u64, message: PCWSTR);
51
52#[repr(C)]
53pub enum WintunLoggerLevel {
54    /// Informational logs
55    Info,
56    /// Warning logs
57    Warn,
58    /// Error logs
59    Err,
60}