Run `cargo fmt`

main
shellrow 1 year ago
parent 63ec068733
commit 162240457f
  1. 24
      src/bpf/mod.rs
  2. 35
      src/gateway/macos.rs
  3. 11
      src/gateway/mod.rs
  4. 6
      src/lib.rs
  5. 24
      src/socket/mod.rs

@ -1,27 +1,11 @@
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
mod binding; mod binding;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
pub use self::binding::*; pub use self::binding::*;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
mod unix; mod unix;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
pub use self::unix::*; pub use self::unix::*;
#[cfg(any( #[cfg(any(

@ -4,8 +4,9 @@ use super::Gateway;
use crate::interface::MacAddr; use crate::interface::MacAddr;
use std::{ use std::{
collections::HashMap,
io, io,
net::{IpAddr, Ipv4Addr, Ipv6Addr}, collections::HashMap, net::{IpAddr, Ipv4Addr, Ipv6Addr},
}; };
const CTL_NET: u32 = 4; const CTL_NET: u32 = 4;
@ -346,10 +347,32 @@ fn message_to_arppair(msg_bytes: *mut u8) -> (IpAddr, MacAddr) {
const IP_END_INDEX: usize = 7; const IP_END_INDEX: usize = 7;
const MAC_START_INDEX: usize = 24; const MAC_START_INDEX: usize = 24;
const MAC_END_INDEX: usize = 29; const MAC_END_INDEX: usize = 29;
let ip_bytes = unsafe { std::slice::from_raw_parts(msg_bytes.add(IP_START_INDEX), IP_END_INDEX + 1 - IP_START_INDEX) }; let ip_bytes = unsafe {
let mac_bytes = unsafe { std::slice::from_raw_parts(msg_bytes.add(MAC_START_INDEX), MAC_END_INDEX + 1 - MAC_START_INDEX) }; std::slice::from_raw_parts(
let ip_addr = IpAddr::V4(Ipv4Addr::new(ip_bytes[0], ip_bytes[1], ip_bytes[2], ip_bytes[3])); msg_bytes.add(IP_START_INDEX),
let mac_addr = MacAddr::new([mac_bytes[0], mac_bytes[1], mac_bytes[2], mac_bytes[3], mac_bytes[4], mac_bytes[5]]); IP_END_INDEX + 1 - IP_START_INDEX,
)
};
let mac_bytes = unsafe {
std::slice::from_raw_parts(
msg_bytes.add(MAC_START_INDEX),
MAC_END_INDEX + 1 - MAC_START_INDEX,
)
};
let ip_addr = IpAddr::V4(Ipv4Addr::new(
ip_bytes[0],
ip_bytes[1],
ip_bytes[2],
ip_bytes[3],
));
let mac_addr = MacAddr::new([
mac_bytes[0],
mac_bytes[1],
mac_bytes[2],
mac_bytes[3],
mac_bytes[4],
mac_bytes[5],
]);
(ip_addr, mac_addr) (ip_addr, mac_addr)
} }
@ -430,7 +453,7 @@ fn get_default_route() -> Option<Route> {
} }
} }
} }
Err(_) => {}, Err(_) => {}
} }
None None
} }

@ -1,14 +1,7 @@
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
pub(crate) mod unix; pub(crate) mod unix;
#[cfg(any( #[cfg(any(target_os = "macos", target_os = "ios"))]
target_os = "macos",
target_os = "ios"
))]
pub(crate) mod macos; pub(crate) mod macos;
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]

@ -6,11 +6,7 @@
target_os = "ios" target_os = "ios"
))] ))]
mod bpf; mod bpf;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
mod socket; mod socket;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
mod sys; mod sys;

@ -1,28 +1,12 @@
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
pub mod packet; pub mod packet;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
mod unix; mod unix;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
pub use self::unix::*; pub use self::unix::*;
#[cfg(any( #[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))]
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd"
))]
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

Loading…
Cancel
Save