code wiki / (root) / nx_ipaddr.nx

nx_ipaddr.nx

buildroot/runtime/nx_ipaddr.nx

11404 B348 linesdepth 2pulls 2 transitivereach 10 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

ipaddr.nx -- IPv4 + IPv6 address parse / format. Used by: net.nx (connect / bind with human-readable addresses), X.509 subjectAltName IP entries, HTTP Host header validation, access-control lists. IPv4: dotted quad "a.b.c.d" where each octet is 0..255. Packed as network-order u32 (big-endian): a in high byte. IPv6: colon-separated "1234:abcd:..." with optional "::" run- length compression. 16-byte value (8 x u16 hextets). Parser handles both full + compressed forms; emitter always produces compressed canonical form (RFC 5952). Invariants: IP1 All decoders are bounds-checked; malformed input returns a negative error code, never garbage. IP2 Encoders never overflow the output buffer -- caller guarantees >= 16 chars for IPv4 ("255.255.255.255\0"), >= 40 chars for IPv6 (":ffff:ffff:...:ffff\0"). IP3 Round-trip exact for canonical forms. Compressed IPv6 that uses "::" is normalised on re-format; the byte-level value round-trips even if the string doesn't. IP4 No IPv4-mapped IPv6 (::ffff:a.b.c.d) handling today. That form is RFC 4291 but complicates parsing; callers needing it can decompose manually.

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_ipaddr.nx nx_cidr.nx nx_cidr_smoke.nx

imports: nx_syscalls.nx

imported by: nx_cidr.nxnx_cidr_smoke.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ipv4_parse sys_mmap ipv4_format ip_emit_dec ipv6_parse sys_mmap ↻ ipv6_parse_hex

structs

none

consts

36const IPADDR_ERR_FORMAT: i64 = -1
37const IPADDR_ERR_RANGE: i64 = -2

functions

43func ipv4_parse(s: *u8, n: i64) -> i64
80func ip_emit_dec(out: *u8, off: i64, n: i64) -> i64;
called by 1: ipv4_format
84func ipv4_format(ip: i64, out: *u8) -> i64
called by 1: main calls 1: ip_emit_dec
101func ip_emit_dec(out: *u8, off: i64, n: i64) -> i64
126func ipv6_parse_hex(s: *u8, n: i64, pos: *i64, out_val: *i64) -> i64
called by 1: ipv6_parse
156func ipv6_parse(s: *u8, n: i64, out: *u8) -> i64
called by 1: main calls 2: sys_mmapipv6_parse_hex
249func ipv6_format(bytes: *u8, out: *u8) -> i64
calls 1: sys_mmap
331func main() -> i64