Expand description
IPv4/IPv6 literal parsing helpers.
These functions parse IP address literals from strings into byte arrays suitable for network operations. They handle both dotted-decimal (IPv4) and colon-hex (IPv6) formats.
§Examples
ⓘ
use strat9_abi::ip::{parse_ipv4_literal, parse_ipv6_literal};
// IPv4
assert_eq!(parse_ipv4_literal("192.168.1.10"), Some([192, 168, 1, 10]));
assert_eq!(parse_ipv4_literal("10.0.0.1"), Some([10, 0, 0, 1]));
assert_eq!(parse_ipv4_literal("256.1.1.1"), None); // octet > 255
// IPv6
assert_eq!(
parse_ipv6_literal("::1"),
Some([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
);
assert_eq!(
parse_ipv6_literal("fe80::1"),
Some([0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
);Functions§
- is_
ipv4_ literal_ candidate - Returns true when the input looks like a dotted IPv4 literal candidate.
- is_
ipv6_ literal_ candidate - Returns true when the input looks like an IPv6 literal candidate.
- parse_
hex_ 🔒u16 - Parses a hex string of 1-4 digits into a
u16. - parse_
ipv4_ literal - Parses an IPv4 literal into network-order octets.
- parse_
ipv6_ literal - Parses an IPv6 literal into network-order octets.