Skip to content

feature: network utils supports#19

Merged
Charliechen114514 merged 8 commits into
mainfrom
feat/phase3-net
Jul 6, 2026
Merged

feature: network utils supports#19
Charliechen114514 merged 8 commits into
mainfrom
feat/phase3-net

Conversation

@Charliechen114514

Copy link
Copy Markdown
Member

No description provided.

…next

PLAN and ROADMAP had stalled at 'Phase 2 complete' while PR#17 (structure
gates + STRUCTURE-TASTE) and PR#18 (PERFORMANCE + io/tar/cmp/md5sum/sed
streaming + google-benchmark harness) landed on main. Sync the batch tables,
restate baseline 436 GTest / 439 KB / 123 applet, point next at Phase 3
network, and leave a backfilled batch note.
First slice of Phase 3 networking: a header-only cfbox::socket primitive
layer and the first applet that consumes it.

- include/cfbox/socket.hpp: make/resolve/connect_fd/set_reuseaddr/dial/
  listen_on/bound_port/accept_one/format_addr. Reuses cfbox::io::unique_fd
  for fd lifetime (DRY: a socket is a fd; no separate SocketFd class).
  Plaintext, dual-stack, errors via base::Result.
- src/applets/nc.cpp: connect mode (nc HOST PORT) and listen mode
  (nc -l -p PORT). Single-process poll(2) relay bridges stdin->sock and
  sock->stdout; SHUT_WR half-close on stdin EOF so a peer can still reply.
  No fork (keeps cfbox process state clean).
- Registered in APPLET_REGISTRY, Config.cmake CFBOX_APPLETS, and
  applet_config.hpp.in.
- tests/unit/test_socket.cpp: loopback echo + resolve + v4/v6 format.
- tests/integration/test_nc.sh: server listens, client sends one line.

Verified: 440/440 GTest (+4 SocketTest), structure gate PASS, size-opt
451 KB (+12, <=550 budget), 55 integration scripts green.
Add Phase 3 batch table to PLAN (batch 1 = socket.hpp + nc, 10f811f),
bump top-line baseline to 440 GTest / 451 KB / 124 applet, and leave a
batch note covering the three pitfalls hit (CFBOX_TRY in int-returning
entry, relay 4-fd bridge, test_nc.sh set -e) plus the SocketFd->unique_fd
DRY decision.
Ran the armhf gap that PR#18 left open (compile-only, no qemu run): static
build with /opt/arm-gnu-toolchain is clean at -WConversion, and
qemu-arm-static runs the five streamed applets (io/md5sum/tar/sed/cmp) plus
nc loopback echo end to end. No 32-bit regression. armhf static 1235 KB.
…wave 1a)

Wave 1 first slice: a read-only interface layer plus the ifconfig display
path. Mutations (addr/up/down/mtu) and ip/route/netstat come later.

- include/cfbox/net_util.hpp: InterfaceInfo + read_interfaces() (parses
  /proc/net/dev for counters, ioctl SIOCGIF* for flags/mtu/hwaddr/ipv4) +
  format_ifconfig() in BusyBox multi-line style. Hand-rolled field parser
  avoids <sstream>.
- src/applets/ifconfig.cpp: 'ifconfig' (up only), '-a' (all), 'ifconfig IFACE'.
- ipv4_from_ioctl helper memcpy's sockaddr->sockaddr_in instead of casting,
  sidestepping -Wcast-align on 32-bit ARM (x86-64 is silent; armhf -Werror
  caught it).
- tests/unit/test_net_util.cpp: live /proc/net/dev + format coverage.
- tests/integration/test_ifconfig.sh: -a/no-arg/named/bogus-exit.

Verified: 446/446 GTest (+6 NetUtilTest), structure gate PASS, size-opt
455 KB (+4), 56 integration scripts green, armhf static clean + qemu ifconfig.
Add batch 2 row to Phase 3 table (f4279d6), bump baseline to 446 GTest /
455 KB / 125 applet, and note the armhf -Wcast-align catch (sockaddr ->
sockaddr_in memcpy via ipv4_from_ioctl) plus the loopback Bcast and
collisions/txqueuelen output fixes.
…e 3 wave 1b)

Wave 1b: two new display applets and the hostname options, all built on
the net_util layer from wave 1a.

- include/cfbox/net_util.hpp: RouteEntry + read_routes() (parses
  /proc/net/route tab-separated hex fields) + format_route_table() (BusyBox
  route -n layout) + hex_to_ipv4 (host-endian hex → dotted) + prefix_len.
  hex_to_ipv4 explicitly casts strtoul's unsigned long to uint32_t
  (-Wshorten-64-to-32 on x86-64).
- src/applets/ip.cpp: 'ip addr [show] [IFACE]' — iproute2-style index, flags,
  mtu, link, inet/prefix/scope. addr subtree only (link/route/add later).
- src/applets/route.cpp: 'route [-n]' — prints the table; add/del rejected.
- src/applets/hostname.cpp: add -i (resolve_ipv4 via getaddrinfo, memcpy to
  dodge -Wcast-align), -f (FQDN via AI_CANONNAME), -d (domain part).
- tests: NetUtil +3 (hex/prefix/route-table), IpTest +3, test_ip.sh,
  test_route.sh.

Verified: 452/452 GTest (+9), structure gate PASS, size-opt 463 KB (+8),
58 integration scripts green, armhf static clean + qemu ip/route/hostname.
Add batch 3 row (f0ff0db), bump baseline to 452 GTest / 463 KB / 127 applet,
and note the strtoul-uint32 shorten catch plus the getaddrinfo ai_addr
memcpy (reusing the ipv4_from_ioctl cast-align pattern from wave 1a).
@Charliechen114514 Charliechen114514 merged commit e2e8cc0 into main Jul 6, 2026
8 checks passed
@Charliechen114514 Charliechen114514 deleted the feat/phase3-net branch July 6, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant