nx_socket_list.nx
buildroot/runtime/nx_socket_list.nx
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
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
structs
| none |
consts
| 33 | const NX_SL_MAX_LISTEN_SOCKETS: i64 = 1024 |
| 34 | const NX_SL_MAX_PIDS: i64 = 4096 |
| 35 | const NX_SL_BUF_CAP: i64 = 65536 |
| 36 | const NX_SL_CMDLINE_CAP: i64 = 4096 |
| 39 | const NX_SL_OK: i64 = 0 |
| 40 | const NX_SL_ERR_PROC_OPEN: i64 = 1 |
| 41 | const NX_SL_ERR_PROC_READ: i64 = 2 |
functions
| 45 | func _sl_strlen(s: *u8) -> i64 called by 1: _sl_w |
| 51 | func _sl_w(fd: i64, s: *u8) -> i64 |
| 55 | func _sl_wi(fd: i64, n: i64) -> i64 |
| 76 | func _sl_parse_hex4(buf: *u8, off: i64) -> i64 called by 1: _sl_parse_family |
| 93 | func _sl_parse_dec(buf: *u8, off: i64, max_len: i64) -> i64 called by 1: _sl_parse_family |
| 113 | func _sl_read_file(path: *u8, out_buf: *u8, cap: i64) -> i64 |
| 139 | func _sl_parse_family(path: *u8, ports: *i64, inodes: *i64, cap: i64, base: i64) -> i64 |
| 310 | func _sl_parse_proc_net_tcp(ports: *i64, inodes: *i64, cap: i64) -> i64 |
| 323 | func _sl_inode_to_pid(target_inode: i64, out_pid: *i64) -> i64 |
| 374 | func nx_socket_list_emit() -> i64 |
| 405 | func main() -> i64 calls 1: nx_socket_list_emit |