feat(os): NetworkInterface.all on macOS #572
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/569-networkinterface-macos"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #569
Task
Implement #569 (OS slice 5, step 2b of #129):
NetworkInterface.all()answers on macOS.What
runtime/os/posix.c: on macOS theAF_LINKentry ofgetifaddrsis written as alinkline with the index, the flags, the six-byte hardware address and, fromstruct if_data, the MTU and theIFT_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 fromlinux/network.trb, so macOS (and FreeBSD, slice 7) reuse them. Alinkline may have the two extra fields; every other line keeps exactly seven.linux/network.trbonly imports them now.std/os/src/macos/network.trb(new):interfaces()overPosix.interfaceEntries, and the pure mapping: statusUpfor up and running, otherwiseDown; kind fromIFT_LOOP(Loopback),IFT_GIF/IFT_STF/IFT_PPP, autunname or the point-to-point flag (Tunnel),IFT_ETHER(Ethernet), anything elseOther.NetworkInterface.allwires.MacOs; FreeBSD, Windows and the browser stayUnsupported. Its doc comment,docs/standard-library/os.md, the OS.md status row and the regeneratedskills/say so, including that Wi-Fi is not told apart from Ethernet on macOS yet (decided in the issue).Test
std/os/tests/network.test.trb: new group "the interfaces of macOS" parses sample macOSlink/inet/inet6lines (lo0,en0,en1,gif0,utun0/utun1,bridge0, a link withoutif_data), checks kinds, status, MTU, hardware addressNone,subnet().contains(address)for every address and malformed lines givingOsError.Malformed. The Linux tests are unchanged apart from the import path; the live tests now cover.Linux | .MacOs.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 --checkclean after regeneration;sh tools/check-commits.sh origin/mainclean.runtime/os/posix.ccompiles clean with-std=c11 -Wall -Wextra -Werrorforaarch64-macos,x86_64-macosandx86_64-linux-gnuunder the repository's pinnedzig cc(single-file compile, run locally; the forge'smacos-arm64cross-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.45ab2bf89027fe87e3deApproved at
27fe87e.posix.cmacOS link entry checkssa_familybefore use, handles missingif_data(0/0), buffer bound andsnprintfresult checked; Linux line unchanged.parseEntriesaccepts 9 fields only forlink, everything else stays at 7. Status/kind mapping matches the PR body.NetworkInterface.all); FreeBSD/Windows stay Unsupported; no new native.posix/network.trbfor reuse; no new boundary.Non-blocking:
posix/network.trbparseEntriessays "not seven" even where nine were expected for alink.docs/standard-library/os.md(and its skills copy) has one over-long line in the NetworkInterface paragraph;torb format --checkis green, so this is only cosmetic.