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
//! # Submodule: High-level NDISAPI Types
//!
//! This submodule provides high-level NDISAPI definitions of constants, structures, and enumerations
//!

// Required imports for the submodule
use std::fmt::{Display, Formatter, Result};
use windows::Win32::Foundation::HANDLE;

/// Represents the version information for the NDIS filter driver.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Version {
    pub major: u32,
    pub minor: u32,
    pub revision: u32,
}

impl Display for Version {
    /// Formats the version information for display purposes.
    ///
    /// # Arguments
    ///
    /// * `f`: A mutable reference to a `Formatter` object.
    ///
    /// # Returns
    ///
    /// * `Result` - A formatting Result.
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{}.{}.{}", self.major, self.minor, self.revision)
    }
}

/// Represents information about a network adapter.
#[derive(Debug)]
pub struct NetworkAdapterInfo {
    name: String,
    handle: HANDLE,
    medium: u32,
    hw_address: [u8; 6],
    mtu: u16,
}

impl NetworkAdapterInfo {
    /// Creates a new `NetworkAdapterInfo` object with the specified properties.
    ///
    /// # Arguments
    ///
    /// * `name`: A `String` representing the name of the network adapter.
    /// * `handle`: A `HANDLE` to the network adapter.
    /// * `medium`: A `u32` value representing the network adapter medium.
    /// * `hw_address`: A `[u8; 6]` array representing the hardware address of the network adapter.
    /// * `mtu`: A `u16` value representing the maximum transmission unit (MTU) of the network adapter.
    ///
    /// # Returns
    ///
    /// * `NetworkAdapterInfo` - A new instance of `NetworkAdapterInfo`.
    pub fn new(name: String, handle: HANDLE, medium: u32, hw_address: [u8; 6], mtu: u16) -> Self {
        Self {
            name,
            handle,
            medium,
            hw_address,
            mtu,
        }
    }

    /// Returns the name of the network adapter.
    ///
    /// # Returns
    ///
    /// * `&str` - A reference to the name of the network adapter.
    pub fn get_name(&self) -> &str {
        &self.name
    }

    /// Returns the handle of the network adapter.
    ///
    /// # Returns
    ///
    /// * `HANDLE` - The handle of the network adapter.
    pub fn get_handle(&self) -> HANDLE {
        self.handle
    }

    /// Returns the medium of the network adapter.
    ///
    /// # Returns
    ///
    /// * `u32` - The medium of the network adapter.
    pub fn get_medium(&self) -> u32 {
        self.medium
    }

    /// Returns the hardware address of the network adapter.
    ///
    /// # Returns
    ///
    /// * `&[u8; 6]` - A reference to the hardware address of the network adapter.
    pub fn get_hw_address(&self) -> &[u8; 6] {
        &self.hw_address
    }

    /// Returns the maximum transmission unit (MTU) of the network adapter.
    ///
    /// # Returns
    ///
    /// * `u16` - The MTU of the network adapter.
    pub fn get_mtu(&self) -> u16 {
        self.mtu
    }
}