about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-11-10 20:58:51 +0000
committerbors <bors@rust-lang.org>2015-11-10 20:58:51 +0000
commit3519effc6e85b56360218a5a037346d56365376f (patch)
tree61b9a15ee766f88290d4a5d3142005b9f54e8905 /src/libstd/net
parentd668fab0efe1751fbf998383c48ad3ee269fceea (diff)
parentf16e7b4a419a5afcdd4d634da120cb834c8ebaba (diff)
downloadrust-3519effc6e85b56360218a5a037346d56365376f.tar.gz
rust-3519effc6e85b56360218a5a037346d56365376f.zip
Auto merge of #29724 - alexcrichton:ip-endian, r=aturon
The comparison of IP addresses should happen not always in network endianness
but rather in the host endianness format, so be sure to convert to that before
comparing addresses.

There are still locations where the endianness will factor into visible
properties, such as the hash, but these are not important to be independent of
the endianness in play (as hash values are pretty undefined anyway.

Closes #29691
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/ip.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs
index f3ad148e3da..c657a7aa0bd 100644
--- a/src/libstd/net/ip.rs
+++ b/src/libstd/net/ip.rs
@@ -236,7 +236,7 @@ impl PartialOrd for Ipv4Addr {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Ord for Ipv4Addr {
     fn cmp(&self, other: &Ipv4Addr) -> Ordering {
-        self.inner.s_addr.cmp(&other.inner.s_addr)
+        self.octets().cmp(&other.octets())
     }
 }
 
@@ -506,7 +506,7 @@ impl PartialOrd for Ipv6Addr {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Ord for Ipv6Addr {
     fn cmp(&self, other: &Ipv6Addr) -> Ordering {
-        self.inner.s6_addr.cmp(&other.inner.s6_addr)
+        self.segments().cmp(&other.segments())
     }
 }
 
@@ -794,4 +794,11 @@ mod tests {
         let a = Ipv4Addr::new(127, 0, 0, 1);
         assert_eq!(Ipv4Addr::from(2130706433), a);
     }
+
+    #[test]
+    fn ord() {
+        assert!(Ipv4Addr::new(100, 64, 3, 3) < Ipv4Addr::new(192, 0, 2, 2));
+        assert!("2001:db8:f00::1002".parse::<Ipv6Addr>().unwrap() <
+                "2001:db8:f00::2001".parse::<Ipv6Addr>().unwrap());
+    }
 }