blob: b9e01915e2467bdfc2b891c33c2f25e3681b7e5f (
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
|
// Here we iniitialize systems crucial for nsc
use std::io::Read;
use sniffing::headers::sniff_raw_packets;
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)?;
sniff_raw_packets(&buf[0..amount]);
dbg!("{:?}", &buf[0..amount]);
}
}
|