Skip to content

Commit

Permalink
named threads
Browse files Browse the repository at this point in the history
  • Loading branch information
mrak committed Aug 15, 2024
1 parent e04fd37 commit cabbea8
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/bin/nx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,32 @@ fn capture_packets(settings: &Settings, sender: Sender<(u32, Vec<u8>)>) {

for interface in interfaces {
let child_snd = sender.clone();
thread::spawn(move || {
let (_, mut rx) = match datalink::channel(&interface, Default::default()) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("nx: unhandled channel type"),
Err(e) => match e.kind() {
ErrorKind::PermissionDenied => {
eprintln!(
"nx: Permission Denied - Unable to open interface {}",
interface.name
);
process::exit(1)
}
_ => panic!("nx: unable to create channel: {}", e),
},
};
loop {
match rx.next() {
Ok(packet) => child_snd
.send((interface.index, packet.to_owned()))
.unwrap(),
Err(e) => panic!("nx: Unable to receive packet: {}", e),
let _ = thread::Builder::new()
.name(interface.name.clone())
.spawn(move || {
let mut rx = match datalink::channel(&interface, Default::default()) {
Ok(Ethernet(_, rx)) => rx,
Ok(_) => panic!("nx: unhandled channel type"),
Err(e) => match e.kind() {
ErrorKind::PermissionDenied => {
eprintln!(
"nx: Permission Denied - Unable to open interface {}",
interface.name
);
process::exit(1)
}
_ => panic!("nx: unable to create channel: {}", e),
},
};
}
});
loop {
match rx.next() {
Ok(packet) => child_snd
.send((interface.index, packet.to_owned()))
.unwrap(),
Err(e) => panic!("nx: Unable to receive packet: {}", e),
};
}
});
}
}

Expand Down

0 comments on commit cabbea8

Please sign in to comment.