tun_sync/platform/
mod.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15//! Platform specific modules.
16
17#[cfg(unix)]
18pub mod posix;
19
20#[cfg(target_os = "linux")]
21pub mod linux;
22#[cfg(target_os = "linux")]
23pub use self::linux::{create, Configuration, Device, Queue};
24
25#[cfg(target_os = "macos")]
26pub mod macos;
27#[cfg(target_os = "macos")]
28pub use self::macos::{create, Configuration, Device, Queue};
29
30#[cfg(target_os = "ios")]
31pub mod ios;
32#[cfg(target_os = "ios")]
33pub use self::ios::{create, Configuration, Device, Queue};
34
35#[cfg(target_os = "android")]
36pub mod android;
37#[cfg(target_os = "android")]
38pub use self::android::{create, Configuration, Device, Queue};
39
40#[cfg(test)]
41mod test {
42    use crate::configuration::Configuration;
43    use crate::device::Device;
44    use std::net::Ipv4Addr;
45
46    #[test]
47    fn create() {
48        let dev = super::create(
49            Configuration::default()
50                .address("10.0.0.2")
51                .netmask("255.255.0.0")
52                .mtu(1400)
53                .up(),
54        )
55        .unwrap();
56
57        assert_eq!(
58            "10.0.0.2".parse::<Ipv4Addr>().unwrap(),
59            dev.address().unwrap()
60        );
61
62        assert_eq!(
63            "255.255.0.0".parse::<Ipv4Addr>().unwrap(),
64            dev.netmask().unwrap()
65        );
66
67        assert_eq!(1400, dev.mtu().unwrap());
68    }
69}