pub fn parse_host_ip(host: &str) -> Option<ParsedHostIp>Expand description
Parse a host string as an IP address the way inet_aton and system resolvers do, and say
how it was spelled. The input is a host as it appears in a URL: ASCII case does not
matter, IPv6 may be bracketed, and one trailing dot is allowed (and makes an IPv4
spelling non-canonical).
Accepted, with the result:
| Input | addr | kind | is_canonical |
|---|---|---|---|
1.1.1.1 | 1.1.1.1 | Ipv4DottedQuad | true |
127.1 | 127.0.0.1 | Ipv4Legacy | false |
10.1.2 | 10.1.0.2 | Ipv4Legacy | false |
0177.0.0.1 (octal parts) | 127.0.0.1 | Ipv4Legacy | false |
0x7f.0.0.1, 0x7f000001 (hex) | 127.0.0.1 | Ipv4Legacy | false |
2130706433 (one 32-bit part) | 127.0.0.1 | Ipv4Legacy | false |
1.1.1.1. (trailing dot) | 1.1.1.1 | Ipv4Legacy | false |
::1, [::1], ::ffff:127.0.0.1 | as written | Ipv6 | true |
inet_aton rules: one to four parts; each part is decimal, octal (a leading 0) or hex
(0x); every part but the last is at most 255; the last part fills the remaining bytes
(so a.b.c has a 16-bit last part and a.b a 24-bit one). Returns None for hostnames,
for more than four parts, for out-of-range parts, for a digit outside the part’s radix
(08.1), and for empty parts.