Skip to content

Commit d67d5f4

Browse files
authored
Fix IPv6 setup under MacOS when binding to "" (#392)
- Setting IP_MULTICAST_TTL and IP_MULTICAST_LOOP does not work under MacOS when the bind address is ""
1 parent 33a3a6a commit d67d5f4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

zeroconf/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,12 @@ def new_socket(
22352235
if ip_version != IPVersion.V6Only:
22362236
# OpenBSD needs the ttl and loop values for the IP_MULTICAST_TTL and
22372237
# IP_MULTICAST_LOOP socket options as an unsigned char.
2238-
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
2239-
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, loop)
2238+
try:
2239+
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
2240+
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, loop)
2241+
except socket.error as e:
2242+
if bind_addr[0] != '' or get_errno(e) != errno.EINVAL: # Fails to set on MacOS
2243+
raise
22402244
if ip_version != IPVersion.V4Only:
22412245
# However, char doesn't work here (at least on Linux)
22422246
s.setsockopt(_IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, 255)

0 commit comments

Comments
 (0)