Skip to content

Commit

Permalink
fix: fix cross compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
gongzhengyang committed Mar 5, 2024
1 parent e6d2436 commit a864c3e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ impl NetworkData {
///
/// let mut networks = Networks::new_with_refreshed_list();
/// for (interface_name, network) in &networks {
/// println!("Ip Networks: {}", network.ip_networks());
/// println!("Ip Networks: {:?}", network.ip_networks());
/// }
/// ```
pub fn ip_networks(&self) -> &[IpNetwork] {
Expand Down
5 changes: 2 additions & 3 deletions src/unix/apple/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use libc::{self, c_char, if_msghdr2, CTL_NET, NET_RT_IFLIST2, PF_ROUTE, RTM_IFIN
use std::collections::{hash_map, HashMap};
use std::ptr::null_mut;

use ipnetwork::IpNetwork;

use crate::common::MacAddr;
use crate::network::refresh_networks_addresses;
use crate::IpNetwork;
use crate::NetworkData;

macro_rules! old_and_new {
Expand Down Expand Up @@ -198,7 +197,7 @@ pub(crate) struct NetworkDataInner {
/// MAC address
pub(crate) mac_addr: MacAddr,
/// IP networks
pub(crate) ip_networks: Vec<ipnetwok::IpNetwork>,
pub(crate) ip_networks: Vec<IpNetwork>,
}

impl NetworkDataInner {
Expand Down
3 changes: 2 additions & 1 deletion src/unix/freebsd/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::mem::MaybeUninit;
use super::utils;
use crate::common::MacAddr;
use crate::network::refresh_networks_addresses;
use crate::IpNetwork;
use crate::NetworkData;

macro_rules! old_and_new {
Expand Down Expand Up @@ -151,7 +152,7 @@ pub(crate) struct NetworkDataInner {
/// MAC address
pub(crate) mac_addr: MacAddr,
/// IP networks
pub(crate) ip_networks: Vec<ipnetwok::IpNetwork>,
pub(crate) ip_networks: Vec<IpNetwork>,
}

impl NetworkDataInner {
Expand Down
1 change: 1 addition & 0 deletions src/unknown/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::common::MacAddr;
use crate::NetworkData;
use crate::IpNetwork;

use std::collections::HashMap;

Expand Down
2 changes: 2 additions & 0 deletions src/windows/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::common::MacAddr;
use crate::network::refresh_networks_addresses;
use crate::IpNetwork;
use crate::NetworkData;

use std::collections::{hash_map, HashMap};
Expand Down Expand Up @@ -137,6 +138,7 @@ impl NetworksInner {
errors_out: ptr.OutErrors,
old_errors_out: ptr.OutErrors,
mac_addr: MacAddr::UNSPECIFIED,
ip_networks: vec![],
updated: true,
},
});
Expand Down
8 changes: 4 additions & 4 deletions src/windows/network_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ pub(crate) fn get_interface_address() -> Result<InterfaceAddressIterator, String
}
}

pub(crate) fn get_interface_ip_network() -> HashMap<String, Vec<IpNetwork>> {
pub(crate) fn get_interface_ip_networks() -> HashMap<String, Vec<IpNetwork>> {
ipconfig::get_adapters()
.unwrap_or(vec![])
.into_iter()
.map(|a| {
(
a.friendly_name().to_owned(),
a.prefixes()
.into_iter()
.map(|(addr, prefix)| IpNetwork::new(addr, prefix))
.iter()
.filter_map(|(addr, prefix)| IpNetwork::new(*addr, *prefix as u8).ok())
.collect(),
)
})
.collect();
.collect()
}

0 comments on commit a864c3e

Please sign in to comment.