nx_ipaddr.nx
buildroot/runtime/nx_ipaddr.nx
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
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
structs
| none |
consts
| 36 | const IPADDR_ERR_FORMAT: i64 = -1 |
| 37 | const IPADDR_ERR_RANGE: i64 = -2 |
functions
| 43 | func ipv4_parse(s: *u8, n: i64) -> i64 |
| 80 | func ip_emit_dec(out: *u8, off: i64, n: i64) -> i64; called by 1: ipv4_format |
| 84 | func ipv4_format(ip: i64, out: *u8) -> i64 |
| 101 | func ip_emit_dec(out: *u8, off: i64, n: i64) -> i64 |
| 126 | func ipv6_parse_hex(s: *u8, n: i64, pos: *i64, out_val: *i64) -> i64 called by 1: ipv6_parse |
| 156 | func ipv6_parse(s: *u8, n: i64, out: *u8) -> i64 |
| 249 | func ipv6_format(bytes: *u8, out: *u8) -> i64 calls 1: sys_mmap |
| 331 | func main() -> i64 |