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
#[allow(unused_imports)]
use crate::error::Result;
#[allow(unused_imports)]
use crate::IntoAddress;
#[allow(unused_imports)]
use std::net::IpAddr;

#[allow(dead_code)]
pub(crate) const ETHER_ADDR_LEN: u8 = 6;
/// A TUN abstract device interface.
pub trait AbstractDevice {
    /// Get the device tun name.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd"
    ))]
    fn name(&self) -> Result<String>;

    /// Set the device tun name.
    #[cfg(any(target_os = "windows", target_os = "linux", target_os = "freebsd"))]
    fn set_name(&self, name: &str) -> Result<()>;

    /// Turn on or off the interface.
    #[cfg(any(
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd",
        target_os = "windows"
    ))]
    fn enabled(&self, value: bool) -> Result<()>;

    /// Get the address.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd"
    ))]
    fn address(&self) -> Result<IpAddr>;

    /// Get the destination address.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd"
    ))]
    fn destination(&self) -> Result<IpAddr>;

    /// Get the broadcast address.
    #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
    fn broadcast(&self) -> Result<IpAddr>;

    /// Set the broadcast address.
    #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
    fn set_broadcast<A: IntoAddress>(&self, value: A) -> Result<()>;

    /// Get the netmask.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd"
    ))]
    fn netmask(&self) -> Result<IpAddr>;

    /// Sets the network addresses of this adapter, including network address, subnet mask, and gateway
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd"
    ))]
    fn set_network_address<A: IntoAddress>(
        &self,
        address: A,
        netmask: A,
        destination: Option<A>,
    ) -> Result<()>;

    /// Get the MTU.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd",
    ))]
    fn mtu(&self) -> Result<u16>;

    /// Set the MTU.
    #[cfg(any(
        target_os = "windows",
        target_os = "linux",
        target_os = "macos",
        target_os = "freebsd",
    ))]
    fn set_mtu(&self, value: u16) -> Result<()>;

    /// Ignore packet-information during reading and writing
    #[cfg(any(target_os = "macos", target_os = "ios"))]
    fn ignore_packet_info(&self) -> bool;

    /// Ignore packet-information during reading and writing
    #[cfg(any(target_os = "macos", target_os = "ios"))]
    fn set_ignore_packet_info(&self, ign: bool);

    /// Set mac address
    #[cfg(any(target_os = "windows", target_os = "linux", target_os = "freebsd",))]
    fn set_mac_address(&self, eth_addr: [u8; ETHER_ADDR_LEN as usize]) -> Result<()>;
    /// Get mac address
    #[cfg(any(target_os = "windows", target_os = "linux", target_os = "freebsd",))]
    fn get_mac_address(&self) -> Result<[u8; ETHER_ADDR_LEN as usize]>;
}