|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|