From 11eb3fa691c6889a2d66ee3417d562deb6b35ec4 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Thu, 10 Jan 2019 23:27:07 +0100 Subject: Add `IPV6_V6ONLY` IPV6 socket option SO says this is required for proper UDP socket multi-homing. --- pysnmp/carrier/asyncore/dgram/base.py | 1 + pysnmp/carrier/sockmsg.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pysnmp/carrier/asyncore/dgram/base.py b/pysnmp/carrier/asyncore/dgram/base.py index 4edae19b..d38f3080 100644 --- a/pysnmp/carrier/asyncore/dgram/base.py +++ b/pysnmp/carrier/asyncore/dgram/base.py @@ -78,6 +78,7 @@ class DgramSocketTransport(AbstractSocketTransport): if self.socket.family == socket.AF_INET6: self.socket.setsockopt(socket.SOL_IPV6, socket.IPV6_RECVPKTINFO, flag) + self.socket.setsockopt(socket.SOL_IPV6, socket.IPV6_V6ONLY, not flag) except socket.error: raise error.CarrierError('setsockopt() for %s failed: %s' % (self.socket.family == socket.AF_INET6 and "IPV6_RECVPKTINFO" or "IP_PKTINFO", sys.exc_info()[1])) diff --git a/pysnmp/carrier/sockmsg.py b/pysnmp/carrier/sockmsg.py index 0b21233b..97273306 100644 --- a/pysnmp/carrier/sockmsg.py +++ b/pysnmp/carrier/sockmsg.py @@ -92,7 +92,7 @@ else: debug.logger & debug.flagIO and debug.logger( 'recvfrom: received %d octets from %s to %s; ' - 'iov blob %r' % (len(data), _from, _to, ancdata)) + 'iov blob %s' % (len(data), _from, _to, debug.hexdump(ancdata))) return data, addressType(_from).setLocalAddress(_to) @@ -120,7 +120,7 @@ else: ancdata = [(socket.SOL_IPV6, socket.IPV6_PKTINFO, memoryview(_f).tobytes())] debug.logger & debug.flagIO and debug.logger( - 'sendto: sending %d octets to %s; iov blob %r' % (len(data), _to, ancdata)) + 'sendto: sending %d octets to %s; iov blob %s' % (len(data), _to, debug.hexdump(ancdata))) return s.sendmsg([_data], ancdata, 0, _to) -- cgit v1.2.1