1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#
# This file is part of pysnmp software.
#
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pysnmp/license.html
#
from pysnmp.carrier import sockfix
from pysnmp.carrier.base import AbstractTransportAddress
from pysnmp.carrier.asyncore.dgram.base import DgramSocketTransport
import socket
DOMAIN_NAME = SNMP_UDP6_DOMAIN = (1, 3, 6, 1, 2, 1, 100, 1, 2)
class Udp6TransportAddress(tuple, AbstractTransportAddress):
pass
class Udp6SocketTransport(DgramSocketTransport):
SOCK_FAMILY = socket.has_ipv6 and socket.AF_INET6 or None
ADDRESS_TYPE = Udp6TransportAddress
def normalizeAddress(self, transportAddress):
if '%' in transportAddress[0]: # strip zone ID
ta = self.ADDRESS_TYPE((transportAddress[0].split('%')[0],
transportAddress[1],
0, # flowinfo
0)) # scopeid
else:
ta = self.ADDRESS_TYPE((transportAddress[0],
transportAddress[1], 0, 0))
if (isinstance(transportAddress, self.ADDRESS_TYPE) and
transportAddress.getLocalAddress()):
return ta.setLocalAddress(transportAddress.getLocalAddress())
else:
return ta.setLocalAddress(self.getLocalAddress())
Udp6Transport = Udp6SocketTransport
|