From b0e3218208e3cbe6698b2a99062c9cbd78680d45 Mon Sep 17 00:00:00 2001 From: Eugene Nesvetaev Date: Sun, 21 Jun 2026 14:47:04 +0400 Subject: [PATCH] fix(macos): skip SO_BINDTODEVICE and use IP_BOUND_IF paths 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. --- src/reflector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reflector.c b/src/reflector.c index 4ca6565..ae7888a 100644 --- a/src/reflector.c +++ b/src/reflector.c @@ -65,7 +65,7 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ log_err(LOG_ERR, "IPv6 setsockopt IPV6_PKTINFO"); goto cleanup; } -#if defined(SO_BINDTODEVICE) +#if defined(SO_BINDTODEVICE) && !defined(__APPLE__) { struct ifreq ifr; if (if_indextoname(ifindex, ifr.ifr_ifrn.ifrn_name) == NULL) { @@ -101,7 +101,7 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ goto cleanup; } #endif -#if defined(SO_BINDTODEVICE) +#if defined(SO_BINDTODEVICE) && !defined(__APPLE__) { struct ifreq ifr; if (if_indextoname(ifindex, ifr.ifr_ifrn.ifrn_name) == NULL) {