0

I am trying understand how Ipv6 formatting works in rust. I have the following code -

fn main() {
    let ipv6_1 = Ipv6Addr::from_str("2001:db8:abcd:1781::78c").unwrap();
    println!("ipv6_1 - {}", ipv6_1);
    let ipv6_2 = Ipv6Addr::from_str("::a0a:5b0b").unwrap();
    println!("ipv6_2 - {}", ipv6_2);
}

Output:

ipv6_1 - 2001:db8:abcd:1781::78c
ipv6_2 - ::10.10.91.11

In both cases I was expecting output to match the input string format, but it does not appear to be the case for the second input. Any suggestions on how I can get the output to match in the second case as well (i.e. ipv6_2)?

I am trying to match the ipv6 input string format with the Ipv6Addr Display format. I am expecting both to be the same.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 5
    The second case returns correctly because it is in the [deprecated] IPv4-Compatible range. Also, it should return that way for the IPv4-Mapped range, e.g. `::ffff:10.10.91.11`. Addresses in those ranges are _not_ IPv6 addresses, they are IPv4 addresses formatted as IPv6 addresses. – Ron Maupin Mar 28 '23 at 23:52
  • 3
    "I am trying to match the ipv6 input string format with the Ipv6Addr Display format. I am expecting both to be the same." std guarantee nothing of that – Stargateur Mar 29 '23 at 00:04

0 Answers0