]> git.lizzy.rs Git - rust.git/commitdiff
Fix Ipv6Addr to_str for ::1:x.x.x.x addresses
authorStepan Koltsov <stepan.koltsov@gmail.com>
Fri, 9 Aug 2013 09:53:28 +0000 (13:53 +0400)
committerStepan Koltsov <stepan.koltsov@gmail.com>
Fri, 9 Aug 2013 09:53:28 +0000 (13:53 +0400)
Reported by luqmana@

src/libstd/rt/io/net/ip.rs

index 81269d197d501ea6dc5dbd1b15b444fbe3fc8357..77176088801de7fc4f5c08e42451ad9af570239f 100644 (file)
@@ -43,7 +43,7 @@ fn to_str(&self) -> ~str {
             }
 
             // Ipv4-Mapped address
-            Ipv6Addr(0, 0, 0, 0, 0, 1, g, h) => {
+            Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, g, h) => {
                 let a = fmt!("%04x", g as uint);
                 let b = FromStrRadix::from_str_radix(a.slice(2, 4), 16).unwrap();
                 let a = FromStrRadix::from_str_radix(a.slice(0, 2), 16).unwrap();
@@ -437,4 +437,11 @@ fn test_from_str_socket_addr() {
         // port out of range
         assert_eq!(None, FromStr::from_str::<SocketAddr>("127.0.0.1:123456"));
     }
+
+    #[test]
+    fn ipv6_addr_to_str() {
+        let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280);
+        assert!(a1.to_str() == ~"::ffff:192.0.2.128" || a1.to_str() == ~"::FFFF:192.0.2.128");
+    }
+
 }