]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
In cases where we care that something is just an IPv4 or IPv6 address,
authorBob Halley <halley@dnspython.org>
Mon, 4 May 2020 14:17:11 +0000 (07:17 -0700)
committerBob Halley <halley@dnspython.org>
Mon, 4 May 2020 14:17:11 +0000 (07:17 -0700)
without any extras like IPv6 scope, explicitly use dns.ipv4 and dns.ipv6
instead of dns.inet.  This will let us be tolerant of scopes in other
cases (e.g. ordinary network connections).

dns/edns.py
dns/rdtypes/IN/AAAA.py
dns/rdtypes/IN/APL.py
dns/rdtypes/IN/IPSECKEY.py

index b501590dc08d99c419bbcad35386e5f9383e37cc..6618ccae2154b72d194b6292dff35a3d81ec0f99 100644 (file)
@@ -267,15 +267,14 @@ class ECSOption(Option):
         addrlen = int(math.ceil(src/8.0))
 
         if family == 1:
-            af = dns.inet.AF_INET
             pad = 4 - addrlen
+            addr = dns.ipv4.inet_ntoa(wire[cur:cur+addrlen] + b'\x00' * pad)
         elif family == 2:
-            af = dns.inet.AF_INET6
             pad = 16 - addrlen
+            addr = dns.ipv6.inet_ntoa(wire[cur:cur+addrlen] + b'\x00' * pad)
         else:
             raise ValueError('unsupported family')
 
-        addr = dns.inet.inet_ntop(af, wire[cur:cur+addrlen] + b'\x00' * pad)
         return cls(addr, src, scope)
 
     def _cmp(self, other):
index 46ff6159877dca787920fd28b095d4aa0e7af6e7..6eb1bdb8b844a94e732e7af89d34a562de05618e 100644 (file)
@@ -16,7 +16,7 @@
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import dns.exception
-import dns.inet
+import dns.ipv6
 import dns.rdata
 import dns.tokenizer
 
@@ -33,7 +33,7 @@ class AAAA(dns.rdata.Rdata):
     def __init__(self, rdclass, rdtype, address):
         super().__init__(rdclass, rdtype)
         # check that it's OK
-        dns.inet.inet_pton(dns.inet.AF_INET6, address)
+        dns.ipv6.inet_aton(address)
         object.__setattr__(self, 'address', address)
 
     def to_text(self, origin=None, relativize=True, **kw):
@@ -47,10 +47,9 @@ class AAAA(dns.rdata.Rdata):
         return cls(rdclass, rdtype, address)
 
     def to_wire(self, file, compress=None, origin=None):
-        file.write(dns.inet.inet_pton(dns.inet.AF_INET6, self.address))
+        file.write(dns.ipv6.inet_aton(self.address))
 
     @classmethod
     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
-        address = dns.inet.inet_ntop(dns.inet.AF_INET6,
-                                     wire[current: current + rdlen])
+        address = dns.ipv6.inet_ntoa(wire[current: current + rdlen])
         return cls(rdclass, rdtype, address)
index be9397bf9aba242f177dfe92770afb032f9aa46f..443d7149923d67971072d096b4f86a559c020019 100644 (file)
@@ -20,7 +20,8 @@ import codecs
 import struct
 
 import dns.exception
-import dns.inet
+import dns.ipv4
+import dns.ipv6
 import dns.rdata
 import dns.tokenizer
 
@@ -54,9 +55,9 @@ class APLItem(object):
 
     def to_wire(self, file):
         if self.family == 1:
-            address = dns.inet.inet_pton(dns.inet.AF_INET, self.address)
+            address = dns.ipv4.inet_aton(self.address)
         elif self.family == 2:
-            address = dns.inet.inet_pton(dns.inet.AF_INET6, self.address)
+            address = dns.ipv6.inet_aton(self.address)
         else:
             address = binascii.unhexlify(self.address)
         #
@@ -146,11 +147,11 @@ class APL(dns.rdata.Rdata):
             if header[0] == 1:
                 if l < 4:
                     address += b'\x00' * (4 - l)
-                address = dns.inet.inet_ntop(dns.inet.AF_INET, address)
+                address = dns.ipv4.inet_ntoa(address)
             elif header[0] == 2:
                 if l < 16:
                     address += b'\x00' * (16 - l)
-                address = dns.inet.inet_ntop(dns.inet.AF_INET6, address)
+                address = dns.ipv6.inet_ntoa(address)
             else:
                 #
                 # This isn't really right according to the RFC, but it
index 85e147c6fd8e2bd8abfc89ccfe2e2fde86b226f7..17955155dc17ed872d5a46aa23059732a690ffe0 100644 (file)
@@ -19,7 +19,8 @@ import struct
 import base64
 
 import dns.exception
-import dns.inet
+import dns.ipv4
+import dns.ipv6
 import dns.name
 
 
@@ -50,10 +51,10 @@ class IPSECKEY(dns.rdata.Rdata):
             gateway = None
         elif gateway_type == 1:
             # check that it's OK
-            dns.inet.inet_pton(dns.inet.AF_INET, gateway)
+            dns.ipv4.inet_aton(gateway)
         elif gateway_type == 2:
             # check that it's OK
-            dns.inet.inet_pton(dns.inet.AF_INET6, gateway)
+            dns.ipv6.inet_aton(gateway)
         elif gateway_type == 3:
             pass
         else:
@@ -110,9 +111,9 @@ class IPSECKEY(dns.rdata.Rdata):
         if self.gateway_type == 0:
             pass
         elif self.gateway_type == 1:
-            file.write(dns.inet.inet_pton(dns.inet.AF_INET, self.gateway))
+            file.write(dns.ipv4.inet_aton(self.gateway))
         elif self.gateway_type == 2:
-            file.write(dns.inet.inet_pton(dns.inet.AF_INET6, self.gateway))
+            file.write(dns.ipv6.inet_aton(self.gateway))
         elif self.gateway_type == 3:
             self.gateway.to_wire(file, None, origin)
         else:
@@ -130,13 +131,11 @@ class IPSECKEY(dns.rdata.Rdata):
         if gateway_type == 0:
             gateway = None
         elif gateway_type == 1:
-            gateway = dns.inet.inet_ntop(dns.inet.AF_INET,
-                                         wire[current: current + 4])
+            gateway = dns.ipv4.inet_ntoa(wire[current: current + 4])
             current += 4
             rdlen -= 4
         elif gateway_type == 2:
-            gateway = dns.inet.inet_ntop(dns.inet.AF_INET6,
-                                         wire[current: current + 16])
+            gateway = dns.ipv6.inet_ntoa(wire[current: current + 16])
             current += 16
             rdlen -= 16
         elif gateway_type == 3: