def _addresses_equal(af, a1, a2): # Convert the first value of the tuple, which is a textual format # address into binary form, so that we are not confused by different # textual representations of the same address n1 = inet.inet_pton(af, a1[0]) n2 = inet.inet_pton(af, a2[0]) return n1 == n2 and a1[1:] == a2[1:]
def to_wire(self, file, compress=None, origin=None): header = struct.pack("!BBB", self.precedence, self.gateway_type, self.algorithm) file.write(header) if self.gateway_type == 0: pass elif self.gateway_type == 1: file.write(inet.inet_pton(inet.AF_INET, self.gateway)) elif self.gateway_type == 2: file.write(inet.inet_pton(inet.AF_INET6, self.gateway)) elif self.gateway_type == 3: self.gateway.to_wire(file, None, origin) else: raise ValueError('invalid gateway type') file.write(self.key)
def __init__(self, rdclass, rdtype, precedence, gateway_type, algorithm, gateway, key): super(IPSECKEY, self).__init__(rdclass, rdtype) if gateway_type == 0: if gateway != '.' and not gateway is None: raise SyntaxError('invalid gateway for gateway type 0') gateway = None elif gateway_type == 1: # check that it's OK junk = inet.inet_pton(inet.AF_INET, gateway) elif gateway_type == 2: # check that it's OK junk = inet.inet_pton(inet.AF_INET6, gateway) elif gateway_type == 3: pass else: raise SyntaxError('invalid IPSECKEY gateway type: %d' % gateway_type) self.precedence = precedence self.gateway_type = gateway_type self.algorithm = algorithm self.gateway = gateway self.key = key
def to_wire(self, file): if self.family == 1: address = inet.inet_pton(inet.AF_INET, self.address) elif self.family == 2: address = inet.inet_pton(inet.AF_INET6, self.address) else: address = self.address.decode('hex_codec') # # Truncate least significant zero bytes. # last = 0 for i in xrange(len(address) - 1, -1, -1): if address[i] != chr(0): last = i + 1 break address = address[0:last] l = len(address) assert l < 128 if self.negation: l |= 0x80 header = struct.pack('!HBB', self.family, self.prefix, l) file.write(header) file.write(address)
def _cmp(self, other): sa = inet.inet_pton(inet.AF_INET6, self.address) oa = inet.inet_pton(inet.AF_INET6, other.address) return cmp(sa, oa)
def to_wire(self, file, compress=None, origin=None): file.write(inet.inet_pton(inet.AF_INET6, self.address))
def __init__(self, rdclass, rdtype, address): super(AAAA, self).__init__(rdclass, rdtype) # check that it's OK junk = inet.inet_pton(inet.AF_INET6, address) self.address = address