fix(macos): skip SO_BINDTODEVICE and use IP_BOUND_IF paths#20
Open
nesvet wants to merge 1 commit into
Open
Conversation
On macOS, SO_BINDTODEVICE is not a supported way to bind datagram sockets to an interface. The existing Linux-only branch also uses struct ifreq.ifr_ifrn, which does not exist on Darwin (ifr_name is used instead), so the project fails to compile with AppleClang. Guard the SO_BINDTODEVICE blocks with !defined(__APPLE__) so macOS builds use the existing IP_BOUND_IF / IPV6_BOUND_IF branches in new_recv_socket(). Tested on macOS 15 (Apple Silicon): cmake build succeeds; reflector starts with -fn4 between en0 and an OrbStack bridge interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
macOS cannot use Linux
SO_BINDTODEVICEfor interface-scoped mDNS sockets. The current#if defined(SO_BINDTODEVICE)blocks also referencestruct ifreq.ifr_ifrn, which is a Linux/glibc field name — Darwin usesifr_name, so the project does not compile with AppleClang today.This change guards those blocks with
!defined(__APPLE__), allowing the existingIP_BOUND_IF/IPV6_BOUND_IFbranches innew_recv_socket()to be used on macOS (same pattern as mDNSResponder and other portable networking code).Test plan
cmake -S . -B build && cmake --build buildon macOS 15 (Apple Silicon)./build/src/mdns-reflector -fn4 en0 <bridge>starts and reflects between LAN and a VM bridge (OrbStack)Notes
No new socket options — only enables the
#elif defined(IP_BOUND_IF)/IPV6_BOUND_IFpaths that are already present for Apple platforms.