summaryrefslogtreecommitdiff
path: root/src/startup.rs
blob: 10a8441e2d5a152c108763242adeb3a503a776fe (plain)
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
// Here we iniitialize systems crucial for nsc
use std::io::Read;
use crate::sniffing::headers::sniff_raw_packets;
use crate::sniffing::headers::Protocol;
pub fn init() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    let mut config = tun::Configuration::default();
    config
        .address((10, 0, 0, 9))
        .netmask((255, 255, 255, 0))
        .destination((10, 0, 0, 1))
        .up();

    #[cfg(target_os = "linux")]
    config.platform_config(|config| {
        // requiring root privilege to acquire complete functions
        config.ensure_root_privileges(true);
    });

    let mut dev = tun::create(&config)?;
    let mut buf = [0; 4096];

    loop {
        let amount = dev.read(&mut buf)?;
        // dbg!(sniff_raw_packets(&buf[0..amount])?);
        let govno = sniff_raw_packets(&buf[0..amount])?;
        if !matches!(govno.protocol(), Protocol::Unsupported(_)) {
            // println!("1")
            // println!("{:?}", govno)
        }
        // dbg!("{:?}", &buf[0..amount]);
    }
}