Skip to content

Commit a2bead8

Browse files
committed
std::net: tests for Ipv4addr::is_ietf_protocol_assignment()
Also add tests to IpAddr to make sure these addresses are not global.
1 parent 9dcfd9f commit a2bead8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libstd/net/ip.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,9 +2023,14 @@ mod tests {
20232023
check!("224.0.0.0", global|multicast);
20242024
check!("239.255.255.255", global|multicast);
20252025
check!("255.255.255.255");
2026+
// make sure benchmarking addresses are not global
20262027
check!("198.18.0.0");
20272028
check!("198.18.54.2");
20282029
check!("198.19.255.255");
2030+
// make sure addresses reserved for protocol assignment are not global
2031+
check!("192.0.0.0");
2032+
check!("192.0.0.255");
2033+
check!("192.0.0.100");
20292034

20302035
check!("::", unspec);
20312036
check!("::1", loopback);
@@ -2070,6 +2075,7 @@ mod tests {
20702075
let broadcast: u16 = 1 << 6;
20712076
let documentation: u16 = 1 << 7;
20722077
let benchmarking: u16 = 1 << 8;
2078+
let ietf_protocol_assignment: u16 = 1 << 9;
20732079

20742080
if ($mask & unspec) == unspec {
20752081
assert!(ip!($s).is_unspecified());
@@ -2124,6 +2130,12 @@ mod tests {
21242130
} else {
21252131
assert!(!ip!($s).is_benchmarking());
21262132
}
2133+
2134+
if ($mask & ietf_protocol_assignment) == ietf_protocol_assignment {
2135+
assert!(ip!($s).is_ietf_protocol_assignment());
2136+
} else {
2137+
assert!(!ip!($s).is_ietf_protocol_assignment());
2138+
}
21272139
}}
21282140
}
21292141

@@ -2136,6 +2148,7 @@ mod tests {
21362148
let broadcast: u16 = 1 << 6;
21372149
let documentation: u16 = 1 << 7;
21382150
let benchmarking: u16 = 1 << 8;
2151+
let ietf_protocol_assignment: u16 = 1 << 9;
21392152

21402153
check!("0.0.0.0", unspec);
21412154
check!("0.0.0.1");
@@ -2156,6 +2169,9 @@ mod tests {
21562169
check!("198.18.0.0", benchmarking);
21572170
check!("198.18.54.2", benchmarking);
21582171
check!("198.19.255.255", benchmarking);
2172+
check!("192.0.0.0", ietf_protocol_assignment);
2173+
check!("192.0.0.255", ietf_protocol_assignment);
2174+
check!("192.0.0.100", ietf_protocol_assignment);
21592175
}
21602176

21612177
#[test]

0 commit comments

Comments
 (0)