Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/domain/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ pub struct NetworkInterface {
pub mac: String,
/// IP address
pub ip: String,
/// IP prefix
pub prefix: String,
/// Interface speed
pub speed: Option<String>,
/// Interface type
Expand Down
2 changes: 2 additions & 0 deletions src/domain/legacy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ impl From<crate::NetworkInterface> for new::NetworkInterface {
name: legacy.name,
mac: legacy.mac,
ip: legacy.ip,
prefix: legacy.prefix,
speed: legacy.speed,
type_: legacy.type_,
vendor: legacy.vendor,
Expand All @@ -444,6 +445,7 @@ impl From<new::NetworkInterface> for crate::NetworkInterface {
name: new_iface.name,
mac: new_iface.mac,
ip: new_iface.ip,
prefix: new_iface.prefix,
speed: new_iface.speed,
type_: new_iface.type_,
vendor: new_iface.vendor,
Expand Down
2 changes: 2 additions & 0 deletions src/domain/parsers/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn parse_ip_output(ip_output: &str) -> Result<Vec<NetworkInterface>, String>
name: "eth0".to_string(),
mac: "00:00:00:00:00:00".to_string(),
ip: "192.168.1.100".to_string(),
prefix: "24".to_string(),
speed: Some("1000 Mbps".to_string()),
type_: "Ethernet".to_string(),
vendor: "Unknown".to_string(),
Expand Down Expand Up @@ -83,6 +84,7 @@ pub fn parse_macos_network_info(ifconfig_output: &str) -> Result<Vec<NetworkInte
name: name.to_string(),
mac: "Unknown".to_string(),
ip: "Unknown".to_string(),
prefix: "Unknown".to_string(),
speed: None,
type_: interface_type,
vendor: vendor.to_string(),
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ pub struct NetworkInterface {
pub mac: String,
/// IP address.
pub ip: String,
/// IP prefix.
pub prefix: String,
/// Interface speed.
pub speed: Option<String>,
/// Interface type.
Expand Down Expand Up @@ -2621,6 +2623,7 @@ impl ServerInfo {
name: name.clone(),
mac: data.get("mac").cloned().unwrap_or("Unknown".to_string()),
ip: data.get("ip").cloned().unwrap_or("Unknown".to_string()),
prefix: data.get("prefix").cloned().unwrap_or("Unknown".to_string()),
speed: Self::estimate_macos_interface_speed(&name, &interface_type),
type_: interface_type,
vendor: vendor.to_string(),
Expand Down Expand Up @@ -2684,6 +2687,10 @@ impl ServerInfo {
.get("ip")
.cloned()
.unwrap_or("Unknown".to_string()),
prefix: ifconfig_info
.get("prefix")
.cloned()
.unwrap_or("Unknown".to_string()),
speed: Self::estimate_macos_interface_speed(name, &interface_type),
type_: interface_type,
vendor: vendor.to_string(),
Expand Down Expand Up @@ -2900,12 +2907,14 @@ impl ServerInfo {

let mac = iface["address"].as_str().unwrap_or("").to_string();
let mut ip = String::new();
let mut prefix: String = String::new();

// Get IP address
if let Some(addr_info) = iface["addr_info"].as_array() {
for addr in addr_info {
if addr["family"].as_str() == Some("inet") {
ip = addr["local"].as_str().unwrap_or("").to_string();
prefix = addr["prefixlen"].as_str().unwrap_or("").to_string();
break;
}
}
Expand Down Expand Up @@ -2950,6 +2959,7 @@ impl ServerInfo {
name: name.to_string(),
mac,
ip,
prefix,
speed,
type_: iface["link_type"].as_str().unwrap_or("").to_string(),
vendor,
Expand Down
Loading