Skip to main content

Module ip

Module ip 

Source
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.