Skip to content

Minor AF_INET socket conformance: SO_BROADCAST on sendto, MSG_TRUNC, SO_RCVBUF readback#860

Open
brandonpayton wants to merge 1 commit into
mainfrom
fix/socket-conformance-minors
Open

Minor AF_INET socket conformance: SO_BROADCAST on sendto, MSG_TRUNC, SO_RCVBUF readback#860
brandonpayton wants to merge 1 commit into
mainfrom
fix/socket-conformance-minors

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

Three small POSIX-conformance fixes to the AF_INET socket surface, each with a dedicated test.

Fixes

  1. SO_BROADCAST on sendto — a sendto to 255.255.255.255 now requires SO_BROADCAST and returns EACCES without it, matching the enforcement connect() already did.
  2. MSG_TRUNC on recvfrom — reports the real datagram length even when the caller buffer is too small (excess bytes are still discarded, as datagram sockets are lossy).
  3. SO_RCVBUF/SO_SNDBUF readbackgetsockopt returns a previously set value instead of always returning the default, so set/get round-trips consistently. The value remains advisory (not enforced as a hard buffer size).

ABI

No change — MSG_TRUNC is a local constant; no new exports/imports or structs.

Validation

  • cargo test -p kandelo --target aarch64-apple-darwin --lib966 pass, including three new tests (test_sendto_broadcast_requires_so_broadcast, test_recvfrom_msg_trunc_reports_full_length, test_getsockopt_so_rcvbuf_reflects_set_value).
  • scripts/check-abi-version.sh — snapshot in sync.

Deliberately deferred (from the same audit, not bundled here)

  • listen() backlog enforcement — bounding the accept queue is a behavior change (Linux treats backlog as a hint; a hard cap risks the loopback service demos) and over-permissiveness is not a correctness break. Wants its own scoped change.
  • Cross-process MSG_OOB on loopback TCP — currently returns success but loses the urgent byte. Delivering it cross-process needs the same machinery as cross-process connect; MSG_OOB is legacy/rarely used. Wants its own change.

🤖 Generated with Claude Code

…SO_RCVBUF readback

Three small POSIX-conformance fixes to the AF_INET socket surface, each with a
dedicated test:

- sendto to the broadcast address (255.255.255.255) now requires SO_BROADCAST
  and returns EACCES without it, matching the enforcement connect() already did.
- recvfrom honors MSG_TRUNC: it reports the real datagram length even when the
  caller buffer is too small (excess bytes are still discarded).
- getsockopt(SO_RCVBUF/SO_SNDBUF) returns a previously set value instead of
  always returning the default, so set/get round-trips consistently. The value
  remains advisory (not enforced as a hard buffer size).

No ABI change (MSG_TRUNC is a local constant; no new exports/imports or structs).

Validation: `cargo test -p kandelo --lib` (966 pass, incl. three new tests:
`test_sendto_broadcast_requires_so_broadcast`,
`test_recvfrom_msg_trunc_reports_full_length`,
`test_getsockopt_so_rcvbuf_reflects_set_value`). `scripts/check-abi-version.sh`
in sync.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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