Skip to main content

normalize

Function normalize 

Source
pub fn normalize(ip: IpAddr) -> IpAddr
Expand description

Turns an IPv4-mapped IPv6 address (::ffff:a.b.c.d) into the IPv4 address.

Nothing else is rewritten: scope ids are kept, and NAT64 (64:ff9b::/96) is not translated. net-io normalizes every peer at accept, so caps, gates, and logs agree on one form.

ยงExamples

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
let mapped = IpAddr::V6(Ipv4Addr::new(192, 0, 2, 7).to_ipv6_mapped());
assert_eq!(net_io::normalize(mapped), IpAddr::V4(Ipv4Addr::new(192, 0, 2, 7)));
assert_eq!(net_io::normalize(IpAddr::V6(Ipv6Addr::LOCALHOST)), IpAddr::V6(Ipv6Addr::LOCALHOST));