feat(os): NetworkInterface.all on macOS #572

Merged
argus merged 2 commits from loop/569-networkinterface-macos into main 2026-10-29 10:08:20 +00:00
Collaborator

Closes #569

Task

Implement #569 (OS slice 5, step 2b of #129): NetworkInterface.all() answers on macOS.

What

  • runtime/os/posix.c: on macOS the AF_LINK entry of getifaddrs is written as a link line with the index, the flags, the six-byte hardware address and, from struct if_data, the MTU and the IFT_ type as two fields after the seven the Linux line has. The Linux line is unchanged. Commit 1.
  • std/os/src/posix/network.trb (new): the entry parser and the grouping moved here from linux/network.trb, so macOS (and FreeBSD, slice 7) reuse them. A link line may have the two extra fields; every other line keeps exactly seven. linux/network.trb only imports them now.
  • std/os/src/macos/network.trb (new): interfaces() over Posix.interfaceEntries, and the pure mapping: status Up for up and running, otherwise Down; kind from IFT_LOOP (Loopback), IFT_GIF/IFT_STF/IFT_PPP, a utun name or the point-to-point flag (Tunnel), IFT_ETHER (Ethernet), anything else Other.
  • NetworkInterface.all wires .MacOs; FreeBSD, Windows and the browser stay Unsupported. Its doc comment, docs/standard-library/os.md, the OS.md status row and the regenerated skills/ say so, including that Wi-Fi is not told apart from Ethernet on macOS yet (decided in the issue).
  • No new native, no seed impact.

Test

  • std/os/tests/network.test.trb: new group "the interfaces of macOS" parses sample macOS link/inet/inet6 lines (lo0, en0, en1, gif0, utun0/utun1, bridge0, a link without if_data), checks kinds, status, MTU, hardware address None, subnet().contains(address) for every address and malformed lines giving OsError.Malformed. The Linux tests are unchanged apart from the import path; the live tests now cover .Linux | .MacOs.
  • Local, quick: torb test std/os/tests/network.test.trb (VM): 50 passed, 0 failed; torb format --check std docs/standard-library: 0 of 67 files would change; torb docs skill docs skills --check clean after regeneration; sh tools/check-commits.sh origin/main clean.
  • C: runtime/os/posix.c compiles clean with -std=c11 -Wall -Wextra -Werror for aarch64-macos, x86_64-macos and x86_64-linux-gnu under the repository's pinned zig cc (single-file compile, run locally; the forge's macos-arm64 cross-build job runs only on nightly and release, so it is skipped on this PR). FreeBSD is left on the stub: its half is slice 7.
  • Forge CI: tier A and B gates of this PR (result in the PR checks).
  • Not verified: running on a real Mac (no runner; the criteria rest on sample text and the cross-build).
Closes #569 ## Task Implement #569 (OS slice 5, step 2b of #129): `NetworkInterface.all()` answers on macOS. ## What - `runtime/os/posix.c`: on macOS the `AF_LINK` entry of `getifaddrs` is written as a `link` line with the index, the flags, the six-byte hardware address and, from `struct if_data`, the MTU and the `IFT_` type as two fields after the seven the Linux line has. The Linux line is unchanged. Commit 1. - `std/os/src/posix/network.trb` (new): the entry parser and the grouping moved here from `linux/network.trb`, so macOS (and FreeBSD, slice 7) reuse them. A `link` line may have the two extra fields; every other line keeps exactly seven. `linux/network.trb` only imports them now. - `std/os/src/macos/network.trb` (new): `interfaces()` over `Posix.interfaceEntries`, and the pure mapping: status `Up` for up and running, otherwise `Down`; kind from `IFT_LOOP` (Loopback), `IFT_GIF`/`IFT_STF`/`IFT_PPP`, a `utun` name or the point-to-point flag (Tunnel), `IFT_ETHER` (Ethernet), anything else `Other`. - `NetworkInterface.all` wires `.MacOs`; FreeBSD, Windows and the browser stay `Unsupported`. Its doc comment, `docs/standard-library/os.md`, the OS.md status row and the regenerated `skills/` say so, including that Wi-Fi is not told apart from Ethernet on macOS yet (decided in the issue). - No new native, no seed impact. ## Test - `std/os/tests/network.test.trb`: new group "the interfaces of macOS" parses sample macOS `link`/`inet`/`inet6` lines (`lo0`, `en0`, `en1`, `gif0`, `utun0`/`utun1`, `bridge0`, a link without `if_data`), checks kinds, status, MTU, hardware address `None`, `subnet().contains(address)` for every address and malformed lines giving `OsError.Malformed`. The Linux tests are unchanged apart from the import path; the live tests now cover `.Linux | .MacOs`. - Local, quick: `torb test std/os/tests/network.test.trb` (VM): 50 passed, 0 failed; `torb format --check std docs/standard-library`: 0 of 67 files would change; `torb docs skill docs skills --check` clean after regeneration; `sh tools/check-commits.sh origin/main` clean. - C: `runtime/os/posix.c` compiles clean with `-std=c11 -Wall -Wextra -Werror` for `aarch64-macos`, `x86_64-macos` and `x86_64-linux-gnu` under the repository's pinned `zig cc` (single-file compile, run locally; the forge's `macos-arm64` cross-build job runs only on nightly and release, so it is skipped on this PR). FreeBSD is left on the stub: its half is slice 7. - Forge CI: tier A and B gates of this PR (result in the PR checks). - Not verified: running on a real Mac (no runner; the criteria rest on sample text and the cross-build).
On macOS and FreeBSD the AF_LINK entry of each interface is now a link line: index, flags, the six-byte hardware address and, from struct if_data, the MTU and the IFT_ type as two fields more than the Linux line has. Linux output is unchanged.
feat(os): NetworkInterface.all on macOS
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 2m21s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
45ab2bf890
std/os/macos/network reads Posix.interfaceEntries into interfaces: status from IFF_UP and IFF_RUNNING, kind from the IFT_ type (loopback, GIF/STF/PPP and utun tunnels, Ethernet). The parser and the grouping move from linux/network to posix/network so that macOS and later FreeBSD reuse them; a link line may now carry the MTU and the IFT_ type.
orion requested review from argus 2026-10-29 06:53:40 +00:00
orion force-pushed loop/569-networkinterface-macos from 45ab2bf890
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 2m21s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
to 27fe87e3de
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap (linux-x64) (pull_request) Successful in 6m52s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Successful in 22m9s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m23s
ci / tier A (linux-x64) (pull_request) Successful in 26m38s
ci / pack the seed (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m35s
ci / every host emits the same C (pull_request) Successful in 4m50s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
images / cr.torb.dev/torbscript/site (push) Has been skipped
images / cr.torb.dev/torbscript/registry (push) Has been skipped
images / cr.torb.dev/torbscript/release-sync (push) Has been skipped
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 9m0s
ci / commit messages (push) Has been cancelled
ci / what the change touches (push) Has been cancelled
ci / gates (push) Has been cancelled
pdisc / pdisc (push) Has been cancelled
2026-10-29 07:29:54 +00:00
Compare
argus approved these changes 2026-10-29 10:08:19 +00:00
argus left a comment

Approved at 27fe87e.

  • Tests: ok. New group "the interfaces of macOS" covers parsing of 9-field link lines, grouping, status, kind, MTU, hardware address, subnets and malformed lines; Linux tests unchanged apart from the import path. CI green on this head (tier A, tier B, gates, bootstrap linux-x64, every-host-same-C, playground, pdisc, commits).
  • Correctness: ok. posix.c macOS link entry checks sa_family before use, handles missing if_data (0/0), buffer bound and snprintf result checked; Linux line unchanged. parseEntries accepts 9 fields only for link, everything else stays at 7. Status/kind mapping matches the PR body.
  • Scope: ok. Exactly #569 (macOS slice of NetworkInterface.all); FreeBSD/Windows stay Unsupported; no new native.
  • Security/data: ok. No secrets, no new permissions or dependencies, read-only system call.
  • Docs: ok. API doc comment, docs/standard-library/os.md, OS.md status row and the regenerated skills file updated; the Wi-Fi limitation is stated.
  • Architecture: ok. Parser moved to posix/network.trb for reuse; no new boundary.
  • Not verified on real hardware (stated in the PR body; CI has no Mac runner).

Non-blocking:

  1. The malformed-line message in posix/network.trb parseEntries says "not seven" even where nine were expected for a link.
  2. docs/standard-library/os.md (and its skills copy) has one over-long line in the NetworkInterface paragraph; torb format --check is green, so this is only cosmetic.
Approved at 27fe87e. - Tests: ok. New group "the interfaces of macOS" covers parsing of 9-field link lines, grouping, status, kind, MTU, hardware address, subnets and malformed lines; Linux tests unchanged apart from the import path. CI green on this head (tier A, tier B, gates, bootstrap linux-x64, every-host-same-C, playground, pdisc, commits). - Correctness: ok. `posix.c` macOS link entry checks `sa_family` before use, handles missing `if_data` (0/0), buffer bound and `snprintf` result checked; Linux line unchanged. `parseEntries` accepts 9 fields only for `link`, everything else stays at 7. Status/kind mapping matches the PR body. - Scope: ok. Exactly #569 (macOS slice of `NetworkInterface.all`); FreeBSD/Windows stay Unsupported; no new native. - Security/data: ok. No secrets, no new permissions or dependencies, read-only system call. - Docs: ok. API doc comment, docs/standard-library/os.md, OS.md status row and the regenerated skills file updated; the Wi-Fi limitation is stated. - Architecture: ok. Parser moved to `posix/network.trb` for reuse; no new boundary. - Not verified on real hardware (stated in the PR body; CI has no Mac runner). Non-blocking: 1. The malformed-line message in `posix/network.trb` `parseEntries` says "not seven" even where nine were expected for a `link`. 2. `docs/standard-library/os.md` (and its skills copy) has one over-long line in the NetworkInterface paragraph; `torb format --check` is green, so this is only cosmetic.
argus merged commit 27fe87e3de into main 2026-10-29 10:08:20 +00:00
argus deleted branch loop/569-networkinterface-macos 2026-10-29 10:08:21 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!572
No description provided.