Skip to content

Commit 2133207

Browse files
authored
Merge pull request #134 from shellrow/ios-support
fix gateway path for non-macOS Apple platforms
2 parents 2a35ecf + 09b00d4 commit 2133207

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/interface/unix.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,39 @@ pub fn interfaces() -> Vec<Interface> {
9797

9898
#[cfg(all(target_vendor = "apple", not(target_os = "macos")))]
9999
pub fn interfaces() -> Vec<Interface> {
100-
unix_interfaces()
100+
let mut interfaces: Vec<Interface> = unix_interfaces();
101+
102+
#[cfg(feature = "gateway")]
103+
let local_ip_opt: Option<IpAddr> = super::get_local_ipaddr();
104+
105+
#[cfg(feature = "gateway")]
106+
let gateway_map = gateway::macos::get_gateway_map();
107+
108+
for iface in &mut interfaces {
109+
#[cfg(feature = "gateway")]
110+
{
111+
if let Some(gateway) = gateway_map.get(&iface.index) {
112+
iface.gateway = Some(gateway.clone());
113+
}
114+
115+
if let Some(local_ip) = local_ip_opt {
116+
iface.ipv4.iter().for_each(|ipv4| {
117+
if IpAddr::V4(ipv4.addr()) == local_ip {
118+
iface.dns_servers = get_system_dns_conf();
119+
iface.default = true;
120+
}
121+
});
122+
iface.ipv6.iter().for_each(|ipv6| {
123+
if IpAddr::V6(ipv6.addr()) == local_ip {
124+
iface.dns_servers = get_system_dns_conf();
125+
iface.default = true;
126+
}
127+
});
128+
}
129+
}
130+
}
131+
132+
interfaces
101133
}
102134

103135
#[cfg(any(target_os = "linux", target_os = "android"))]

0 commit comments

Comments
 (0)