From bdaad8dd5b08efcba303e71729d3d0b1d5ccdb25 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Sat, 31 Dec 2022 14:49:47 +0800 Subject: [PATCH] opt: prevent panic from failure on creating channel --- src/gateway/unix.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gateway/unix.rs b/src/gateway/unix.rs index e852e0c..925b430 100644 --- a/src/gateway/unix.rs +++ b/src/gateway/unix.rs @@ -16,10 +16,14 @@ pub fn get_default_gateway(interface_name: String) -> Result { bpf_fd_attempts: 1000, promiscuous: false, }; - let (mut _tx, mut rx) = match socket::channel(interface_name, config) { - Ok(socket::Channel::Ethernet(tx, rx)) => (tx, rx), - Err(e) => panic!("Failed to create channel {}", e), - }; + let (mut _tx, mut rx); + match socket::channel(interface_name, config) { + Ok(socket::Channel::Ethernet(etx, erx)) => { + _tx = etx; + rx = erx; + }, + Err(e) => return Err(format!("Failed to create channel {}", e)), + } match super::send_udp_packet() { Ok(_) => (), Err(e) => return Err(format!("Failed to send UDP packet {}", e)),