消除代码警告

This commit is contained in:
lbl8603
2024-05-09 21:25:55 +08:00
parent 4215488cb6
commit 1338bcbbc5
13 changed files with 33 additions and 29 deletions
+5 -5
View File
@@ -14,7 +14,7 @@ impl Device {
}
}
impl Device {
pub fn as_tun_fd(&self) ->&Fd{
pub fn as_tun_fd(&self) -> &Fd {
&self.fd
}
}
@@ -31,7 +31,7 @@ impl IFace for Device {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
fn set_ip(&self, address: Ipv4Addr, mask: Ipv4Addr) -> io::Result<()> {
fn set_ip(&self, _address: Ipv4Addr, _mask: Ipv4Addr) -> io::Result<()> {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
@@ -39,15 +39,15 @@ impl IFace for Device {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
fn set_mtu(&self, value: u32) -> io::Result<()> {
fn set_mtu(&self, _value: u32) -> io::Result<()> {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
fn add_route(&self, dest: Ipv4Addr, netmask: Ipv4Addr, metric: u16) -> io::Result<()> {
fn add_route(&self, _dest: Ipv4Addr, _netmask: Ipv4Addr, _metric: u16) -> io::Result<()> {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
fn delete_route(&self, dest: Ipv4Addr, netmask: Ipv4Addr) -> io::Result<()> {
fn delete_route(&self, _dest: Ipv4Addr, _netmask: Ipv4Addr) -> io::Result<()> {
Err(io::Error::from(io::ErrorKind::Unsupported))
}
+3 -1
View File
@@ -3,7 +3,6 @@
/// https://github.com/Tazdevil971/tap-windows
/// https://github.com/nulldotblack/wintun
pub mod device;
mod packet;
#[cfg(target_os = "linux")]
mod linux;
@@ -29,3 +28,6 @@ mod windows;
#[cfg(windows)]
pub use windows::Device;
#[cfg(windows)]
mod packet;
+5 -10
View File
@@ -1,18 +1,17 @@
#![allow(dead_code)]
use std::ffi::{CStr, CString};
use std::net::Ipv4Addr;
use std::os::fd::AsRawFd;
use std::process::Command;
use std::{io, mem, ptr};
use libc::{
c_char, c_short, ifreq, AF_INET, IFF_MULTI_QUEUE, IFF_NO_PI, IFF_RUNNING, IFF_TAP, IFF_TUN,
c_char, c_short, ifreq, AF_INET, IFF_MULTI_QUEUE, IFF_NO_PI, IFF_RUNNING, IFF_TUN,
IFF_UP, IFNAMSIZ, O_RDWR, SOCK_DGRAM,
};
use crate::device::IFace;
use crate::linux::route;
use crate::linux::sys::*;
use crate::packet;
use crate::unix::{exe_cmd, Fd, SockAddr};
pub struct Device {
@@ -49,7 +48,7 @@ impl Device {
);
}
let device_type: c_short = IFF_TUN as c_short;//if tap { IFF_TAP } else { IFF_TUN } as c_short;
let device_type: c_short = IFF_TUN as c_short; //if tap { IFF_TAP } else { IFF_TUN } as c_short;
let queues_num = 1;
@@ -74,13 +73,9 @@ impl Device {
.to_string();
let set_txqueuelen = format!("ifconfig {} txqueuelen 1000", name);
if let Err(e) = exe_cmd(&set_txqueuelen) {
log::warn!("{:?}",e);
}
Device {
name,
tun,
ctl,
log::warn!("{:?}", e);
}
Device { name, tun, ctl }
};
device.enabled(true)?;
Ok(device)
+2 -1
View File
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::ffi::{c_void, CStr};
use std::net::Ipv4Addr;
use std::os::fd::AsRawFd;
@@ -225,7 +226,7 @@ impl Device {
}
}
impl Device {
pub fn as_tun_fd(&self) ->&Fd{
pub fn as_tun_fd(&self) -> &Fd {
&self.tun
}
}
+1
View File
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::{fmt, io};
/// 地址解析协议,由IP地址找到MAC地址
+4 -1
View File
@@ -21,7 +21,10 @@ impl<B: AsRef<[u8]>> EthernetPacket<B> {
let packet = EthernetPacket::unchecked(buffer);
//头部固定14位
if packet.buffer.as_ref().len() < 14 {
Err(io::Error::new(io::ErrorKind::InvalidData,format!("len={}", packet.buffer.as_ref().len())))?;
Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("len={}", packet.buffer.as_ref().len()),
))?;
}
Ok(packet)
+1 -1
View File
@@ -13,7 +13,7 @@ where
let mut eth_buf = [0; 65536];
loop {
let len = read_fn(&mut eth_buf)?;
if len == 0{
if len == 0 {
return Ok(len);
}
//处理arp包
+1 -1
View File
@@ -1,6 +1,6 @@
use libc::{fcntl, F_GETFL, F_SETFL, O_NONBLOCK};
use std::io;
use std::os::fd::{AsRawFd, IntoRawFd, RawFd};
use libc::{F_GETFL, F_SETFL, fcntl, O_NONBLOCK};
pub struct Fd(pub RawFd);
+2 -1
View File
@@ -1,6 +1,7 @@
#![allow(dead_code)]
use crate::windows::exe_cmd;
use std::io;
use std::net::Ipv4Addr;
use std::{io, process};
/// 设置网卡名称
pub fn set_interface_name(old_name: &str, new_name: &str) -> io::Result<()> {
+2 -5
View File
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::io;
use std::net::Ipv4Addr;
use winapi::shared::ifdef::NET_LUID;
@@ -11,8 +12,6 @@ use winapi::um::winnt::{
use crate::device::IFace;
use crate::packet;
use crate::packet::ethernet::protocol::Protocol;
use crate::packet::{arp, ethernet};
use crate::windows::{ctl_code, decode_utf16, encode_utf16, ffi, netsh, route};
/* Present in 8.1 */
@@ -97,7 +96,7 @@ impl Device {
let index = ffi::luid_to_index(&luid).map(|index| index as u32)?;
// 设置网卡跃点
if let Err(e) = netsh::set_interface_metric(index, 0) {
log::warn!("{:?}",e);
log::warn!("{:?}", e);
}
let device = Self {
handle,
@@ -122,8 +121,6 @@ impl Device {
}
}
const MAC: [u8; 6] = [0xf, 0xf, 0xf, 0xf, 0xe, 0x9];
impl IFace for Device {
fn version(&self) -> io::Result<String> {
let mut version = [0u32; 3];
+4 -3
View File
@@ -1,4 +1,5 @@
use libloading::{Error, Library};
#![allow(dead_code)]
use libloading::Library;
use std::io;
use std::net::Ipv4Addr;
@@ -84,7 +85,7 @@ impl Device {
//SAFETY: guid is a unique integer so transmuting either all zeroes or the user's preferred
//guid to the winapi guid type is safe and will allow the windows kernel to see our GUID
let guid_struct: wintun_raw::GUID = unsafe { std::mem::transmute(guid) };
let guid_struct: wintun_raw::GUID = std::mem::transmute(guid);
let guid_ptr = &guid_struct as *const wintun_raw::GUID;
//SAFETY: the function is loaded from the wintun dll properly, we are providing valid
@@ -118,7 +119,7 @@ impl Device {
let index = ffi::luid_to_index(&std::mem::transmute(luid)).map(|index| index as u32)?;
// 设置网卡跃点
if let Err(e) = netsh::set_interface_metric(index, 0) {
log::warn!("{:?}",e);
log::warn!("{:?}", e);
}
Ok(Self {
luid: std::mem::transmute(luid),
+1
View File
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use log::*;
use crate::windows::tun::wintun_raw;
+2
View File
@@ -1,3 +1,5 @@
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
/* automatically generated by rust-bindgen 0.59.1 */
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]