code wiki / (root) / nx_socket_list.nx

nx_socket_list.nx

buildroot/runtime/nx_socket_list.nx

15243 B407 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic socket
docsdependenciesstructsconstsfunctions

about

nx_socket_list.nx -- NS-2.5 of NISHI_NAS_CONTROL_ROADMAP. Bits-up substrate for "which process is listening on which TCP port". Closes the diagnostic gap from 2026-05-21 -- when the operator couldn't tell what was serving :443 because `netstat -tlnp` and `ss -tlnp` required sudo on the NAS. This tool reads /proc directly: no sudo, no third-party, no DSM-managed surfaces. Mechanism (pure bits-up): 1. Read /proc/net/tcp + /proc/net/tcp6 2. Filter state column == "0A" (TCP_LISTEN) 3. Extract local-port (hex) + inode (decimal) 4. Walk /proc/<pid>/fd/* symlinks 5. Match each socket:[N] target to LISTEN inodes 6. Read /proc/<pid>/cmdline (null-separated bytes) 7. Emit: PORT PID CMDLINE V1 scope: IPv4 only (parses /proc/net/tcp). V2 adds /proc/net/tcp6. V1 reads up to 64 listening sockets and 4096 processes -- generous for a NAS but bounded. V2 grows dynamically. Usage: nx_socket_list # lists ALL LISTEN ports nx_socket_list 443 # filter to port 443 (V2 -- argv)

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_socket_list.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main nx_socket_list_emit sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ _sl_parse_proc_net_tcp _sl_parse_family sys_mmap ↻ _sl_read_file sys_openat_rd sys_read sys_close _sl_parse_hex4 _sl_parse_dec _sl_w sys_write ↻ _sl_strlen _sl_wi sys_mmap ↻ sys_write ↻

structs

none

consts

33const NX_SL_MAX_LISTEN_SOCKETS: i64 = 1024
34const NX_SL_MAX_PIDS: i64 = 4096
35const NX_SL_BUF_CAP: i64 = 65536
36const NX_SL_CMDLINE_CAP: i64 = 4096
39const NX_SL_OK: i64 = 0
40const NX_SL_ERR_PROC_OPEN: i64 = 1
41const NX_SL_ERR_PROC_READ: i64 = 2

functions

45func _sl_strlen(s: *u8) -> i64
called by 1: _sl_w
51func _sl_w(fd: i64, s: *u8) -> i64
55func _sl_wi(fd: i64, n: i64) -> i64
76func _sl_parse_hex4(buf: *u8, off: i64) -> i64
called by 1: _sl_parse_family
93func _sl_parse_dec(buf: *u8, off: i64, max_len: i64) -> i64
called by 1: _sl_parse_family
113func _sl_read_file(path: *u8, out_buf: *u8, cap: i64) -> i64
139func _sl_parse_family(path: *u8, ports: *i64, inodes: *i64, cap: i64, base: i64) -> i64
310func _sl_parse_proc_net_tcp(ports: *i64, inodes: *i64, cap: i64) -> i64
323func _sl_inode_to_pid(target_inode: i64, out_pid: *i64) -> i64
374func nx_socket_list_emit() -> i64
405func main() -> i64