graniet / graniet/netquery

error use of moved value cap

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

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`, 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::>::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, 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();

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.