On to the patches. With these changes, I can use the joinGroup API to add
myself to an IPv6 multicast group on Linux (verified via /proc/net/igmp6).
Additionally, trial reports the same two failures before and after these changes
(twisted.python.test.test_release.APIBuilderTests.test_build and
test_buildWithPolicy). These changes struck me as the obvious approach, but
given the changes to resolve, not necessarily the best.
diff --git a/twisted/internet/base.py b/twisted/internet/base.py
index 4f2c862..e813741 100644
--- a/twisted/internet/base.py
+++ b/twisted/internet/base.py
@@ -567,6 +567,8 @@ class ReactorBase(object):
return defer.succeed('0.0.0.0')
if abstract.isIPAddress(name):
return defer.succeed(name)
+ elif abstract.isIPv6Address(name):
+ return defer.succeed(name)
return self.resolver.getHostByName(name, timeout)
# Installation.
diff --git a/twisted/internet/udp.py b/twisted/internet/udp.py
index b5a5322..210b079 100644
--- a/twisted/internet/udp.py
+++ b/twisted/internet/udp.py
@@ -485,7 +485,10 @@ class MulticastMixin:
def _joinAddr1(self, addr, interface, join):
- return self.reactor.resolve(interface).addCallback(self._joinAddr2, addr, join)
+ if self.addressFamily == socket.AF_INET:
+ return self.reactor.resolve(interface).addCallback(self._joinAddr2, addr, join)
+ else:
+ return self.reactor.resolve(interface).addCallback(self._joinAddrIPv6, addr, join)
def _joinAddr2(self, interface, addr, join):
@@ -500,6 +503,18 @@ class MulticastMixin:
except socket.error as e:
return failure.Failure(error.MulticastJoinError(addr, interface, *e.args))
+ def _joinAddrIPv6(self, interface, addr, join):
+ addr = socket.inet_pton(socket.AF_INET6, addr)
+ interface = socket.inet_pton(socket.AF_INET6, interface)
+ if join:
+ cmd = socket.IPV6_JOIN_GROUP
+ else:
+ cmd = socket.IPV6_LEAVE_GROUP
+ try:
+ self.socket.setsockopt(socket.IPPROTO_IPV6, cmd, addr + interface)
+ except socket.error as e:
+ return failure.Failure(error.MulticastJoinError(addr, interface, *e.args))
+
def leaveGroup(self, addr, interface=""):
"""Leave multicast group, return Deferred of success."""
This does require the client specify the interface argument when calling
joinGroup, e.g. self.transport.joinGroup("ff02::1", interface="::").
Thanks in advance for any feedback!
-Jason Litzinger
[1]
http://twistedmatrix.com/pipermail/twisted-python/2016-March/030188.html_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.comhttp://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python