Skip to content

Fix socket binding on macOS/BSD#19

Open
ortix wants to merge 1 commit into
vfreex:mainfrom
ortix:fix/macos-socket-binding
Open

Fix socket binding on macOS/BSD#19
ortix wants to merge 1 commit into
vfreex:mainfrom
ortix:fix/macos-socket-binding

Conversation

@ortix

@ortix ortix commented Jan 19, 2026

Copy link
Copy Markdown

Summary

This PR fixes socket binding issues that prevent compilation and correct operation on modern macOS versions.

Changes

  • Prioritize IPV6_BOUND_IF/IP_BOUND_IF over SO_BINDTODEVICE: On macOS/BSD, the native APIs for binding sockets to specific interfaces are IP_BOUND_IF and IPV6_BOUND_IF. The previous #if/#elif ordering caused the SO_BINDTODEVICE path (which doesn't work on macOS) to be selected.

  • Use portable ifr_name instead of ifr_ifrn.ifrn_name: The ifr_ifrn.ifrn_name member is Linux-specific. The standard portable way to access the interface name in struct ifreq is via ifr_name, which works on all POSIX platforms.

Testing

Verified that the code compiles and runs correctly on macOS (Tahoe). The changes are backwards-compatible and do not affect Linux behavior since SO_BINDTODEVICE is still used when available.

Notes

This is a non-breaking fix that improves cross-platform compatibility.

- Prioritize IPV6_BOUND_IF/IP_BOUND_IF over SO_BINDTODEVICE for
  macOS/BSD compatibility
- Use portable ifr_name instead of Linux-specific ifr_ifrn.ifrn_name
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