Skip to content

Darwin: correct ipv6_pktinfo to IPV6_3542PKTINFO (46) - #233

Merged
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-1131-darwin-ipv6_pktinfo-constant-is-50-ipv6_3542dstopts-should
Jul 28, 2026
Merged

Darwin: correct ipv6_pktinfo to IPV6_3542PKTINFO (46)#233
swhitty merged 1 commit into
swhitty:mainfrom
ianegordon:ian/tvt-1131-darwin-ipv6_pktinfo-constant-is-50-ipv6_3542dstopts-should

Conversation

@ianegordon

Copy link
Copy Markdown
Contributor

Summary

The hardcoded Darwin ipv6_pktinfo constant is 50, which per the macOS SDK <netinet6/in6.h> is IPV6_3542DSTOPTS (destination-options header) — not pktinfo. The RFC 3542 value paired with the already-used IPV6_RECVPKTINFO (61) is IPV6_3542PKTINFO (46):

#define IPV6_3542PKTINFO        46 /* in6_pktinfo; send if, src addr */
#define IPV6_3542DSTOPTS        50 /* ip6_dest; send dst option befor rthdr */
#define IPV6_PKTINFO    IPV6_3542PKTINFO   // under __APPLE_USE_RFC_3542

Swift cannot define __APPLE_USE_RFC_3542 before importing Darwin, so these constants must be hardcoded — but with 50, getPacketInfoControl never matches the cmsg_type the kernel actually delivers (46), and every received IPv6 datagram Message carries interfaceIndex: nil, localAddress: nil on Darwin.

Changes

  • Socket+Darwin.swift: ipv6_pktinfo 50 → 46; comments corrected from __APPLE_USE_RFC_2292 to __APPLE_USE_RFC_3542 (61 and 46 are RFC 3542 values).
  • New test receiveMessage_ParsesIPv6PacketInfo: IPv6 loopback datagram round-trip asserting the received Message carries the parsed interface index and ::1 local address. Verified to fail with 50 and pass with 46 on macOS.

Notes

This is a prerequisite for a follow-up fix to the send-side pktinfo control message (its cmsg_level is currently SOL_SOCKET, which Darwin ignores; once corrected to IPPROTO_IPV6, the kernel interprets cmsg_type — and with 50 rejects IPv6 sends with EACCES).

🤖 Generated with Claude Code

The hardcoded value 50 is IPV6_3542DSTOPTS in <netinet6/in6.h>, not
IPV6_PKTINFO — so the cmsg_type the kernel delivers for
IPV6_RECVPKTINFO (61) never matched and received IPv6 datagram
Messages always carried nil interfaceIndex/localAddress. The RFC 3542
value paired with IPV6_RECVPKTINFO is IPV6_3542PKTINFO (46). Swift
cannot define __APPLE_USE_RFC_3542, hence the hardcoded constants.

Closes TVT-1131

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.97%. Comparing base (ac24c58) to head (35b0b0a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   92.83%   92.97%   +0.13%     
==========================================
  Files          71       71              
  Lines        3743     3743              
==========================================
+ Hits         3475     3480       +5     
+ Misses        268      263       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@swhitty

swhitty commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Great I think the original implementation was made and tested on Linux so Darwin was only quickly added and included in some tests. Thank you

@swhitty
swhitty merged commit f4499b4 into swhitty:main Jul 28, 2026
13 checks passed
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.

2 participants