2
2
3
3
use std:: net:: { IpAddr , Ipv6Addr } ;
4
4
5
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
5
6
const IFF_UP : u32 = 0x1 ;
7
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
6
8
const IFF_LOOPBACK : u32 = 0x8 ;
7
9
8
10
/// List of machine's IP addresses.
11
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
9
12
#[ derive( Debug , Clone , PartialEq , Eq ) ]
10
13
pub struct LocalAddresses {
11
14
/// Loopback addresses.
@@ -14,12 +17,14 @@ pub struct LocalAddresses {
14
17
pub regular : Vec < IpAddr > ,
15
18
}
16
19
20
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
17
21
impl Default for LocalAddresses {
18
22
fn default ( ) -> Self {
19
23
Self :: new ( )
20
24
}
21
25
}
22
26
27
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
23
28
impl LocalAddresses {
24
29
/// Returns the machine's IP addresses.
25
30
/// If there are no regular addresses it will return any IPv4 linklocal or IPv6 unique local
@@ -91,17 +96,20 @@ impl LocalAddresses {
91
96
}
92
97
}
93
98
99
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
94
100
pub ( crate ) const fn is_up ( interface : & netdev:: Interface ) -> bool {
95
101
interface. flags & IFF_UP != 0
96
102
}
97
103
104
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
98
105
pub ( crate ) const fn is_loopback ( interface : & netdev:: Interface ) -> bool {
99
106
interface. flags & IFF_LOOPBACK != 0
100
107
}
101
108
102
109
/// Reports whether ip is a private address, according to RFC 1918
103
110
/// (IPv4 addresses) and RFC 4193 (IPv6 addresses). That is, it reports whether
104
111
/// 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" ) ) ) ]
105
113
pub ( crate ) fn is_private ( ip : & IpAddr ) -> bool {
106
114
match ip {
107
115
IpAddr :: V4 ( ip) => {
@@ -116,11 +124,13 @@ pub(crate) fn is_private(ip: &IpAddr) -> bool {
116
124
}
117
125
}
118
126
127
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
119
128
pub ( crate ) fn is_private_v6 ( ip : & Ipv6Addr ) -> bool {
120
129
// RFC 4193 allocates fc00::/7 as the unique local unicast IPv6 address subnet.
121
130
ip. octets ( ) [ 0 ] & 0xfe == 0xfc
122
131
}
123
132
133
+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
124
134
pub ( super ) fn is_link_local ( ip : IpAddr ) -> bool {
125
135
match ip {
126
136
IpAddr :: V4 ( ip) => ip. is_link_local ( ) ,
0 commit comments