Skip to content

Commit ae81151

Browse files
committed
Fix Ipv6Addr to_str for ::1:x.x.x.x addresses
Reported by luqmana@
1 parent 094e426 commit ae81151

File tree

1 file changed

+8
-1
lines changed
  • src/libstd/rt/io/net

1 file changed

+8
-1
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl ToStr for IpAddr {
4343
}
4444

4545
// Ipv4-Mapped address
46-
Ipv6Addr(0, 0, 0, 0, 0, 1, g, h) => {
46+
Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, g, h) => {
4747
let a = fmt!("%04x", g as uint);
4848
let b = FromStrRadix::from_str_radix(a.slice(2, 4), 16).unwrap();
4949
let a = FromStrRadix::from_str_radix(a.slice(0, 2), 16).unwrap();
@@ -437,4 +437,11 @@ mod test {
437437
// port out of range
438438
assert_eq!(None, FromStr::from_str::<SocketAddr>("127.0.0.1:123456"));
439439
}
440+
441+
#[test]
442+
fn ipv6_addr_to_str() {
443+
let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280);
444+
assert!(a1.to_str() == ~"::ffff:192.0.2.128" || a1.to_str() == ~"::FFFF:192.0.2.128");
445+
}
446+
440447
}

0 commit comments

Comments
 (0)