Skip to content

fix(macos): skip SO_BINDTODEVICE and use IP_BOUND_IF paths#20

Open
nesvet wants to merge 1 commit into
vfreex:mainfrom
nesvet:fix/macos-interface-bind
Open

fix(macos): skip SO_BINDTODEVICE and use IP_BOUND_IF paths#20
nesvet wants to merge 1 commit into
vfreex:mainfrom
nesvet:fix/macos-interface-bind

Conversation

@nesvet

@nesvet nesvet commented Jun 21, 2026

Copy link
Copy Markdown

Summary

macOS cannot use Linux SO_BINDTODEVICE for interface-scoped mDNS sockets. The current #if defined(SO_BINDTODEVICE) blocks also reference struct ifreq.ifr_ifrn, which is a Linux/glibc field name — Darwin uses ifr_name, so the project does not compile with AppleClang today.

This change guards those blocks with !defined(__APPLE__), allowing the existing IP_BOUND_IF / IPV6_BOUND_IF branches in new_recv_socket() to be used on macOS (same pattern as mDNSResponder and other portable networking code).

Test plan

  • cmake -S . -B build && cmake --build build on 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_IF paths that are already present for Apple platforms.

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.
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