-
Notifications
You must be signed in to change notification settings - Fork 0
error use of moved value cap #1
Copy link
Copy link
Open
Description
error[E0382]: use of moved value: `cap`
--> crates/sniffer/src/lib.rs:140:28
|
119 | let mut cap = cap_builder.open()?;
| ------- move occurs because `cap` has type `pcap::Capture<Active>`, which does not implement the `Copy` trait
...
131 | if let Err(e) = cap.setnonblock() {
| ------------- `cap` moved due to this method call
...
140 | std::thread::spawn(move || {
| ^^^^^^^ value used here after move
141 | Self::capture_loop(cap, tx, running, packets_captured, packets_dropped);
| --- use occurs due to use in closure
|
note: `pcap::capture::activated::active::<impl pcap::Capture<Active>>::setnonblock` takes ownership of the receiver `self`, which moves `cap`
--> /home/paladin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/pcap-1.3.0/src/capture/activated/active.rs:22:28
|
22 | pub fn setnonblock(mut self) -> Result<Capture<Active>, Error> {
| ^^^^
Compiling tonic-build v0.11.0
For more information about this error, try `rustc --explain E0382`.
error: could not compile `sniffer` (lib) due to 1 previous error
To resolve it:
sudo apt-get install protobuf-compiler libpcap-dev
@@ -117,6 +117,13 @@ impl Sniffer {
}
let mut cap = cap_builder.open()?;
+ cap = match cap.setnonblock() {
+ Ok(c) => c,
+ Err(e) => {
+ // handle the error however you like
+ return Err(e.into());
+ }
+ };
if let Some(filter) = &self.config.bpf_filter {
info!("Applying BPF filter: {}", filter);
@@ -124,14 +131,7 @@ impl Sniffer {
Ok(_) => info!("BPF filter applied successfully"),
Err(e) => warn!("Failed to apply BPF filter: {}", e),
}
- }
-
- #[cfg(target_os = "linux")]
- {
- if let Err(e) = cap.setnonblock() {
- warn!("Failed to set nonblocking mode: {}", e);
- }
- }
+ }
let running = self.running.clone();
let packets_captured = self.packets_captured.clone();
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels