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

login
register
mail settings
Submitter Danek Duvall
Date Feb. 25, 2016, 6:11 p.m.
Message ID <e996712094de22f8cc78.1456423880@smelly.us.oracle.com>
Download mbox | patch
Permalink /patch/13398/
State Accepted
Headers show

Comments

Danek Duvall - Feb. 25, 2016, 6:11 p.m.
# HG changeset patch
# User Danek Duvall <danek.duvall@oracle.com>
# 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
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.

Patch

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