Windows support

main
shellrow 3 years ago
parent b64c013a9b
commit 7fe034af2d
  1. 5
      src/os/unix.rs
  2. 62
      src/os/windows.rs

@ -153,6 +153,7 @@ fn icmpv6_handler(ip_packet: &pnet_packet::ipv6::Ipv6Packet) -> Option<IpAddr> {
} }
} }
// Get network interfaces
pub fn interfaces() -> Vec<Interface> { pub fn interfaces() -> Vec<Interface> {
let mut result: Vec<Interface> = vec![]; let mut result: Vec<Interface> = vec![];
let local_ip: IpAddr = match super::get_local_ipaddr(){ let local_ip: IpAddr = match super::get_local_ipaddr(){
@ -206,7 +207,7 @@ pub fn interfaces() -> Vec<Interface> {
return result; return result;
} }
/// Get default Interface index // Get default Interface index
pub fn default_interface_index() -> Option<u32> { pub fn default_interface_index() -> Option<u32> {
let local_ip: IpAddr = match super::get_local_ipaddr(){ let local_ip: IpAddr = match super::get_local_ipaddr(){
Some(local_ip) => local_ip, Some(local_ip) => local_ip,
@ -223,7 +224,7 @@ pub fn default_interface_index() -> Option<u32> {
return None; return None;
} }
/// Get default Interface name // Get default Interface name
pub fn default_interface_name() -> Option<String> { pub fn default_interface_name() -> Option<String> {
let local_ip: IpAddr = match super::get_local_ipaddr(){ let local_ip: IpAddr = match super::get_local_ipaddr(){
Some(local_ip) => local_ip, Some(local_ip) => local_ip,

@ -166,22 +166,50 @@ pub fn interfaces() -> Vec<Interface> {
return interfaces; return interfaces;
} }
#[cfg(test)] // Get default Interface index
mod tests { pub fn default_interface_index() -> Option<u32> {
use std::net::Ipv4Addr; let local_ip: IpAddr = match super::get_local_ipaddr(){
use super::*; Some(local_ip) => local_ip,
#[test] None => return None,
fn test_nw_interfaces() { };
let interfaces = get_interfaces(); let interfaces = interfaces();
for interface in interfaces { for iface in interfaces {
println!("{:?}", interface); match local_ip {
} IpAddr::V4(local_ipv4) => {
} if iface.ipv4.contains(&local_ipv4) {
#[test] return Some(iface.index);
fn test_arp() { }
let src_ip: Ipv4Addr = Ipv4Addr::new(192, 168, 1, 2); },
let dst_ip: Ipv4Addr = Ipv4Addr::new(192, 168, 1, 1); IpAddr::V6(local_ipv6) => {
let mac_addr = get_mac_through_arp(src_ip, dst_ip); if iface.ipv6.contains(&local_ipv6) {
println!("{}", mac_addr); return Some(iface.index);
}
},
} }
} }
None
}
// Get default Interface name
pub fn default_interface_name() -> Option<String> {
let local_ip: IpAddr = match super::get_local_ipaddr(){
Some(local_ip) => local_ip,
None => return None,
};
let interfaces = interfaces();
for iface in interfaces {
match local_ip {
IpAddr::V4(local_ipv4) => {
if iface.ipv4.contains(&local_ipv4) {
return Some(iface.name);
}
},
IpAddr::V6(local_ipv6) => {
if iface.ipv6.contains(&local_ipv6) {
return Some(iface.name);
}
},
}
}
None
}

Loading…
Cancel
Save