35 lines
723 B
Rust
35 lines
723 B
Rust
use std::thread;
|
|
use tun_tap::{Iface, Mode};
|
|
|
|
#[derive(Debug)]
|
|
struct Packet {
|
|
data: [u8; 1504],
|
|
}
|
|
|
|
fn main() {
|
|
let (mut tx, rx) = spmc::channel();
|
|
|
|
let iface = Iface::new("nc%d", Mode::Tun).expect("failed to create TUN device");
|
|
|
|
let mut buffer = vec![0; 1504];
|
|
|
|
for i in 0..10 {
|
|
let rx = rx.clone();
|
|
thread::spawn(move || {
|
|
let packet: Packet = rx.recv().unwrap();
|
|
println!("Thread {}: {:?}", i, packet);
|
|
});
|
|
}
|
|
|
|
for _ in 0..500 {
|
|
iface.recv(&mut buffer).unwrap();
|
|
let mut packet = Packet{ data: [0; 1504] };
|
|
|
|
for i in 0..1504 {
|
|
packet.data[i] = buffer[i];
|
|
}
|
|
|
|
tx.send(packet).unwrap();
|
|
}
|
|
}
|