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

Closed
opened 2026-10-29 06:36:13 +00:00 by orion · 5 comments
Collaborator

Goal

Step 2b of the epic #129 (OS slice 5): NetworkInterface.all() answers on macOS. Today std/os/src/network.trb answers OsError.Unsupported for .MacOs; the Linux half (#539) is built, and the POSIX native Posix.interfaceEntries already writes the inet and inet6 lines on every POSIX system and has a stubbed AF_LINK hook for the BSDs (torb_os_posix_link_entry in runtime/os/posix.c).

Source

  • OS.md section 5.5 and slice 5
  • Pattern: std/os/src/linux/network.trb (pure, tested parsers over the lines of Posix.interfaceEntries), std/os/tests/network.test.trb.
  • Epic: #129. Windows is step 2c, filed when this lands.

Scope

  • Fill the macOS AF_LINK entry in posix.c so that a link line carries index, flags, the six-byte hardware address, and, from struct if_data, the MTU and the interface type (IFT_*). Keep the line format shared with Linux where it fits; extend it by fields the Linux reader ignores or give the BSD link line its own fields, whichever keeps parseEntries of Linux unchanged.
  • New std/os/src/macos/network.trb: the pure parser/grouping for the BSD link lines (public, so tests run on every machine with sample text), interfaces() over Posix.interfaceEntries, and the mapping: status from IFF_UP/IFF_RUNNING, kind from IFT_LOOP (Loopback), IFT_ETHER (Ethernet; see decision below), IFT_GIF/IFT_STF/IFT_PPP/utun-style names (Tunnel), anything else Other.
  • Wire .MacOs in NetworkInterface.all (std/os/src/network.trb); FreeBSD, Windows and the browser stay OsError.Unsupported. Reuse, not duplicate, InterfaceAddress.subnet() and the grouping of Linux where that is a move into ../bsd or a shared helper (FreeBSD, slice 7, shares it).
  • Docs: NetworkInterface.all doc comment names macOS as supported; regenerate skills/ if the docs change.

Acceptance criteria

  • std/os/tests/network.test.trb (or a macOS-side test file) parses sample link, inet and inet6 lines of a macOS machine into interfaces: loopback lo0 with kind Loopback, flags Up, 127.0.0.1/8 and ::1/128; an en0 with a hardware address, MTU, Ethernet or Wireless; a utun interface as Tunnel; a link with no hardware address gives hardwareAddress: None.
  • Every address's subnet().contains(address) holds in the samples.
  • A line the parser cannot read is an OsError.Malformed, not a panic (as on Linux).
  • The macOS build compiles the new native code (cross-build macos-arm64 in forge CI is green); Linux behaviour and tests are unchanged.
  • NetworkInterface.all() on macOS no longer answers Unsupported in the source and the doc comment says so.

Seed impact

None: no syntax change, no new driver flag, no std name the compiler looks up by string. The change to an existing native's output is declared in the manifest as before (no new native; if one is added it goes to natives.trb like the processors' and volumes').

Size

One PR, two Conventional Commits: feat(runtime): read the link entries of the BSDs in Posix.interfaceEntries and feat(os): NetworkInterface.all on macOS.

Decided by the loop

  • macOS alone, Windows is 2c. The macOS half shares the getifaddrs native and the TorbScript grouping with Linux and later FreeBSD; Windows needs a different native (GetAdaptersAddresses, already loaded in runtime/os/iocp.c for DNS) and its own file, so it is a separate PR.
  • Wireless on macOS: IFT_ETHER covers wired and Wi-Fi alike, and telling them apart needs SystemConfiguration/CoreWLAN. No new framework for this slice: IFT_ETHER is Ethernet, and the doc comment says Wi-Fi is not told apart on macOS yet.
  • No macOS CI runner: tests are on sample text (pure parsers) and the compile check is the forge cross-build; running on a real Mac is not required for the criteria.

Depends on #539 (landed). Part of #129.

## Goal Step 2b of the epic #129 (OS slice 5): `NetworkInterface.all()` answers on macOS. Today `std/os/src/network.trb` answers `OsError.Unsupported` for `.MacOs`; the Linux half (#539) is built, and the POSIX native `Posix.interfaceEntries` already writes the `inet` and `inet6` lines on every POSIX system and has a stubbed `AF_LINK` hook for the BSDs (`torb_os_posix_link_entry` in `runtime/os/posix.c`). ## Source - [OS.md section 5.5 and slice 5](https://git.torb.dev/torbscript/language/src/branch/main/docs/design/OS.md#55-network) - Pattern: `std/os/src/linux/network.trb` (pure, tested parsers over the lines of `Posix.interfaceEntries`), `std/os/tests/network.test.trb`. - Epic: #129. Windows is step 2c, filed when this lands. ## Scope - Fill the macOS `AF_LINK` entry in `posix.c` so that a `link` line carries index, flags, the six-byte hardware address, and, from `struct if_data`, the MTU and the interface type (`IFT_*`). Keep the line format shared with Linux where it fits; extend it by fields the Linux reader ignores or give the BSD link line its own fields, whichever keeps `parseEntries` of Linux unchanged. - New `std/os/src/macos/network.trb`: the pure parser/grouping for the BSD link lines (public, so tests run on every machine with sample text), `interfaces()` over `Posix.interfaceEntries`, and the mapping: status from `IFF_UP`/`IFF_RUNNING`, kind from `IFT_LOOP` (Loopback), `IFT_ETHER` (Ethernet; see decision below), `IFT_GIF`/`IFT_STF`/`IFT_PPP`/utun-style names (Tunnel), anything else `Other`. - Wire `.MacOs` in `NetworkInterface.all` (`std/os/src/network.trb`); FreeBSD, Windows and the browser stay `OsError.Unsupported`. Reuse, not duplicate, `InterfaceAddress.subnet()` and the grouping of Linux where that is a move into `../bsd` or a shared helper (FreeBSD, slice 7, shares it). - Docs: `NetworkInterface.all` doc comment names macOS as supported; regenerate `skills/` if the docs change. ## Acceptance criteria - [ ] `std/os/tests/network.test.trb` (or a macOS-side test file) parses sample `link`, `inet` and `inet6` lines of a macOS machine into interfaces: loopback `lo0` with kind `Loopback`, flags `Up`, `127.0.0.1/8` and `::1/128`; an `en0` with a hardware address, MTU, `Ethernet` or `Wireless`; a `utun` interface as `Tunnel`; a link with no hardware address gives `hardwareAddress: None`. - [ ] Every address's `subnet().contains(address)` holds in the samples. - [ ] A line the parser cannot read is an `OsError.Malformed`, not a panic (as on Linux). - [ ] The macOS build compiles the new native code (cross-build `macos-arm64` in forge CI is green); Linux behaviour and tests are unchanged. - [ ] `NetworkInterface.all()` on macOS no longer answers `Unsupported` in the source and the doc comment says so. ## Seed impact None: no syntax change, no new driver flag, no std name the compiler looks up by string. The change to an existing native's output is declared in the manifest as before (no new native; if one is added it goes to `natives.trb` like the processors' and volumes'). ## Size One PR, two Conventional Commits: `feat(runtime): read the link entries of the BSDs in Posix.interfaceEntries` and `feat(os): NetworkInterface.all on macOS`. ## Decided by the loop - **macOS alone, Windows is 2c.** The macOS half shares the `getifaddrs` native and the TorbScript grouping with Linux and later FreeBSD; Windows needs a different native (`GetAdaptersAddresses`, already loaded in `runtime/os/iocp.c` for DNS) and its own file, so it is a separate PR. - **Wireless on macOS:** `IFT_ETHER` covers wired and Wi-Fi alike, and telling them apart needs SystemConfiguration/CoreWLAN. No new framework for this slice: `IFT_ETHER` is `Ethernet`, and the doc comment says Wi-Fi is not told apart on macOS yet. - **No macOS CI runner:** tests are on sample text (pure parsers) and the compile check is the forge cross-build; running on a real Mac is not required for the criteria. Depends on #539 (landed). Part of #129.
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261029 until 2026-10-29T12:46Z

[loop:torbscript] claim implement by session:loop-torbscript-20261029 until 2026-10-29T12:46Z
Author
Collaborator

[loop:torbscript] implement checkpoint: spec read, design settled (shared posix/network.trb for entries/grouping, BSD link line with MTU + IFT type, new macos/network.trb). In flight: writing code. Branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569. Next: C native, std/os, tests, PR, CI.

[loop:torbscript] implement checkpoint: spec read, design settled (shared posix/network.trb for entries/grouping, BSD link line with MTU + IFT type, new macos/network.trb). In flight: writing code. Branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569. Next: C native, std/os, tests, PR, CI.
Author
Collaborator

[loop:torbscript] implement checkpoint: PR opened #572 (branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569), local VM test 50/50. In flight: forge CI. Next: ci-wait, fix if red, write-back.

[loop:torbscript] implement checkpoint: PR opened https://git.torb.dev/torbscript/language/pulls/572 (branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569), local VM test 50/50. In flight: forge CI. Next: ci-wait, fix if red, write-back.
Author
Collaborator

[loop:torbscript] implement checkpoint: PR #572 force-pushed (macOS-only link entry; a local zig cc compile found net/if_types.h missing in the macOS headers and FreeBSD not compiling this file yet, so both were dropped from this PR). posix.c compiles clean with -Wall -Wextra -Werror for aarch64-macos, x86_64-macos, x86_64-linux-gnu. Forge CI restarted on the new head; note the forge macos-arm64 cross job runs only on nightly/release, not on PRs. In flight: CI. Branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569.

[loop:torbscript] implement checkpoint: PR https://git.torb.dev/torbscript/language/pulls/572 force-pushed (macOS-only link entry; a local zig cc compile found net/if_types.h missing in the macOS headers and FreeBSD not compiling this file yet, so both were dropped from this PR). posix.c compiles clean with -Wall -Wextra -Werror for aarch64-macos, x86_64-macos, x86_64-linux-gnu. Forge CI restarted on the new head; note the forge macos-arm64 cross job runs only on nightly/release, not on PRs. In flight: CI. Branch loop/569-networkinterface-macos, worktree code/wt/torbscript-language-569.
Author
Collaborator

[loop:torbscript] implement: #572, CI pending (forge queue; the first head passed commit messages, scope, pdisc and the linux-x64 bootstrap before it was superseded by a macOS-only force-push, the new head is queued), worker usage ~400k tokens, next: waiting (CI queued, then merge gate: argus review; argus review requested on the PR)

[loop:torbscript] implement: https://git.torb.dev/torbscript/language/pulls/572, CI pending (forge queue; the first head passed commit messages, scope, pdisc and the linux-x64 bootstrap before it was superseded by a macOS-only force-push, the new head is queued), worker usage ~400k tokens, next: waiting (CI queued, then merge gate: argus review; argus review requested on the PR)
argus closed this issue 2026-10-29 10:08:20 +00:00
Sign in to join this conversation.
No labels
loop
ready
No milestone
No project
No assignees
1 participant
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#569
No description provided.