zeroconf: fix setsockopt() call on Solaris to send payload of correct length
The zeroconf extension has been broken on Solaris since the beginning, but
no one noticed until the testsuite started poking it after changeset
72f2a19c5f88, when it started running "hg paths" with the extension
enabled.
Solaris requires that, for IP_MULTICAST_{TTL,LOOP}, the argument passed in
be of length 1. With the original code here, it gets passed in as an int
-- length 4 -- and so the system call fails with EINVAL. Thankfully,
Python's socket.setsockopt() allows you to pass in a string instead of an
integer, and it passes that string to libc's setsockopt() with the correct
value and length.
--- a/hgext/zeroconf/Zeroconf.py Wed Feb 03 04:54:40 2016 +0000
+++ b/hgext/zeroconf/Zeroconf.py Wed Feb 24 22:22:18 2016 -0800
@@ -1266,8 +1266,8 @@
# work as expected.
#
pass
- self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_TTL, 255)
- self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1)
+ self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_TTL, "\xff")
+ self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, "\x01")
try:
self.socket.bind(self.group)
except Exception: