mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 22:29:01 -05:00
avoid panic in CaptureContext::consume
This commit is contained in:
@@ -49,7 +49,9 @@ pub fn parse_packets(
|
||||
let (mut freeze_rx, mut freeze_rx_2) = freeze_rxs;
|
||||
|
||||
let my_link_type = capture_context.my_link_type();
|
||||
let (cap, mut savefile) = capture_context.consume();
|
||||
let (Some(cap), mut savefile) = capture_context.consume() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut info_traffic_msg = InfoTraffic::default();
|
||||
let resolutions_state = Arc::new(Mutex::new(AddressesResolutionState::default()));
|
||||
|
||||
@@ -74,7 +74,9 @@ fn handle_devices_and_previews(
|
||||
name: dev_name,
|
||||
my_link_type,
|
||||
};
|
||||
let (cap, _) = capture_context.consume();
|
||||
let (Some(cap), _) = capture_context.consume() else {
|
||||
continue;
|
||||
};
|
||||
let _ = thread::Builder::new()
|
||||
.name("thread_device_traffic_preview".to_string())
|
||||
.spawn(move || {
|
||||
|
||||
@@ -69,12 +69,14 @@ pub fn error(&self) -> Option<&str> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume(self) -> (CaptureType, Option<Savefile>) {
|
||||
pub fn consume(self) -> (Option<CaptureType>, Option<Savefile>) {
|
||||
match self {
|
||||
Self::Live(on) => (CaptureType::Live(on.cap), None),
|
||||
Self::LiveWithSavefile(onws) => (CaptureType::Live(onws.live.cap), Some(onws.savefile)),
|
||||
Self::Offline(off) => (CaptureType::Offline(off.cap), None),
|
||||
Self::Error(_) => panic!(),
|
||||
Self::Live(on) => (Some(CaptureType::Live(on.cap)), None),
|
||||
Self::LiveWithSavefile(onws) => {
|
||||
(Some(CaptureType::Live(onws.live.cap)), Some(onws.savefile))
|
||||
}
|
||||
Self::Offline(off) => (Some(CaptureType::Offline(off.cap)), None),
|
||||
Self::Error(_) => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user