Skip to content

Commit 394a13c

Browse files
committed
Export ip module, but without LocalAddresses
1 parent 451d4f6 commit 394a13c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

netwatch/src/ip.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
33
use std::net::{IpAddr, Ipv6Addr};
44

5+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
56
const IFF_UP: u32 = 0x1;
7+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
68
const IFF_LOOPBACK: u32 = 0x8;
79

810
/// List of machine's IP addresses.
11+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
912
#[derive(Debug, Clone, PartialEq, Eq)]
1013
pub struct LocalAddresses {
1114
/// Loopback addresses.
@@ -14,12 +17,14 @@ pub struct LocalAddresses {
1417
pub regular: Vec<IpAddr>,
1518
}
1619

20+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1721
impl Default for LocalAddresses {
1822
fn default() -> Self {
1923
Self::new()
2024
}
2125
}
2226

27+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
2328
impl LocalAddresses {
2429
/// Returns the machine's IP addresses.
2530
/// If there are no regular addresses it will return any IPv4 linklocal or IPv6 unique local
@@ -91,17 +96,20 @@ impl LocalAddresses {
9196
}
9297
}
9398

99+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
94100
pub(crate) const fn is_up(interface: &netdev::Interface) -> bool {
95101
interface.flags & IFF_UP != 0
96102
}
97103

104+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
98105
pub(crate) const fn is_loopback(interface: &netdev::Interface) -> bool {
99106
interface.flags & IFF_LOOPBACK != 0
100107
}
101108

102109
/// Reports whether ip is a private address, according to RFC 1918
103110
/// (IPv4 addresses) and RFC 4193 (IPv6 addresses). That is, it reports whether
104111
/// ip is in 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, or fc00::/7.
112+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
105113
pub(crate) fn is_private(ip: &IpAddr) -> bool {
106114
match ip {
107115
IpAddr::V4(ip) => {
@@ -116,11 +124,13 @@ pub(crate) fn is_private(ip: &IpAddr) -> bool {
116124
}
117125
}
118126

127+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
119128
pub(crate) fn is_private_v6(ip: &Ipv6Addr) -> bool {
120129
// RFC 4193 allocates fc00::/7 as the unique local unicast IPv6 address subnet.
121130
ip.octets()[0] & 0xfe == 0xfc
122131
}
123132

133+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
124134
pub(super) fn is_link_local(ip: IpAddr) -> bool {
125135
match ip {
126136
IpAddr::V4(ip) => ip.is_link_local(),

netwatch/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
path = "interfaces/wasm_browser.rs"
66
)]
77
pub mod interfaces;
8-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
98
pub mod ip;
109
mod ip_family;
1110
pub mod netmon;

0 commit comments

Comments
 (0)