Skip to content

Conversation

@swhitty
Copy link
Owner

@swhitty swhitty commented Nov 21, 2024

There is currently an issue on the main branch where constructing a UDP socket with IP6 fails every time on both Darwin and Linux:

try Socket(domain: AF_INET6, type: .datagram)

Darin: SocketError.failed(type: "SetOption", errno: 13, message: "Permission denied")
Linux: SocketError.failed(type: "SetPktInfoOption", errno: 22, message: "Invalid argument")

While this PR does not fix the underlying issue, it moves the logic from init() so sockets can opt in to setting the packet info allowing users to sidestep the issue.

The private func setPktInfo() has now been removed completely as some recent refactoring allows these options to be set via the existing protocol SocketOption / setValue() API.

Users now enable the packet info options like so:

let socket = try Socket(domain: AF_INET, type: .datagram)
try socket.setValue(true, for: .packetInfoIP)

Unit tests have been added to cover this case, and because it still fails when using IPv6 the tests currently assert expected failures.

@codecov
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.08%. Comparing base (5a20fdc) to head (854a952).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
+ Coverage   90.02%   90.08%   +0.05%     
==========================================
  Files          60       60              
  Lines        3951     3933      -18     
==========================================
- Hits         3557     3543      -14     
+ Misses        394      390       -4     

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


🚨 Try these New Features:

@swhitty swhitty mentioned this pull request Nov 21, 2024
@lhoward
Copy link
Contributor

lhoward commented Nov 21, 2024

If setPktInfo() is not called then the caller will need to explicitly call it, otherwise receive() returning the local interface address will fail (well, it won't fail, but it won't return the local address). I think it's better if it's set by default, so let me look at what the correct fix is.

@lhoward
Copy link
Contributor

lhoward commented Nov 21, 2024

Will aim to have an answer by lunchtime.

@swhitty
Copy link
Owner Author

swhitty commented Nov 21, 2024

thanks, take your time though

@lhoward
Copy link
Contributor

lhoward commented Nov 21, 2024

OK, the fix is the sock opt is IPV6_RECVPKTINFO not IPV6_PKTINFO. However the latter is still the message type. I'll prepare a fix.

@lhoward
Copy link
Contributor

lhoward commented Nov 21, 2024

See #132

@swhitty swhitty closed this in 814d3f1 Nov 21, 2024
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.

3 participants