Patchwork [1,of,2] zeroconf: fix setsockopt() call on Solaris to send payload of correct length

mail settings
Submitter Danek Duvall
Date Feb. 25, 2016, 6:11 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/13398/
State Accepted
Headers show


Danek Duvall - Feb. 25, 2016, 6:11 p.m.
# HG changeset patch
# User Danek Duvall <>
# Date 1456381338 28800
#      Wed Feb 24 22:22:18 2016 -0800
# Node ID e996712094de22f8cc783b630baebed49d50fe57
# Parent  41dcd754526612c43b9695df8851557c851828ef
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

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.


diff --git a/hgext/zeroconf/ b/hgext/zeroconf/
--- a/hgext/zeroconf/
+++ b/hgext/zeroconf/
@@ -1266,8 +1266,8 @@  class Zeroconf(object):
 			# work as expected.
-		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")
 		except Exception: