mirror of
https://github.com/domcyrus/rustnet.git
synced 2026-01-26 16:29:20 -06:00
refactor: Remove unused network functions
This commit is contained in:
@@ -542,72 +542,6 @@ impl NetworkMonitor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get IP addresses associated with an interface
|
||||
fn get_interface_addresses(&self, _interface: &str) -> Result<Vec<IpAddr>> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
// Linux implementation
|
||||
unimplemented!()
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
// Use macOS implementation
|
||||
macos::get_interface_addresses(interface)
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
// Windows implementation
|
||||
unimplemented!()
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
||||
{
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get location information for an IP address
|
||||
pub fn get_ip_location(&self, ip: IpAddr) -> Option<IpLocation> {
|
||||
if let Some(ref reader) = self.geo_db {
|
||||
// Access fields directly on the lookup result (geoip2::City)
|
||||
if let Ok(lookup_result) = reader.lookup::<geoip2::City>(ip) {
|
||||
let country_code = lookup_result
|
||||
.country
|
||||
.as_ref()
|
||||
.and_then(|c| c.iso_code)
|
||||
.map(|s| s.to_string());
|
||||
|
||||
let country_name = lookup_result
|
||||
.country
|
||||
.as_ref()
|
||||
.and_then(|c| c.names.as_ref())
|
||||
.and_then(|n| n.get("en"))
|
||||
.map(|s| s.to_string());
|
||||
|
||||
let city_name = lookup_result
|
||||
.city
|
||||
.as_ref()
|
||||
.and_then(|c| c.names.as_ref())
|
||||
.and_then(|n| n.get("en"))
|
||||
.map(|s| s.to_string());
|
||||
|
||||
let latitude = lookup_result.location.as_ref().and_then(|l| l.latitude);
|
||||
|
||||
let longitude = lookup_result.location.as_ref().and_then(|l| l.longitude);
|
||||
|
||||
return Some(IpLocation {
|
||||
country_code,
|
||||
country_name,
|
||||
city_name,
|
||||
latitude,
|
||||
longitude,
|
||||
isp: None, // Not available in GeoLite2-City
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Parse an address string into a SocketAddr
|
||||
fn parse_addr(&self, addr_str: &str) -> Option<std::net::SocketAddr> {
|
||||
// Handle IPv6 address format [addr]:port
|
||||
|
||||
Reference in New Issue
Block a user