From d9f3e6ef07662990538a9a6fb46f8120ffc37ee5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 21 Sep 2022 21:25:59 -0400 Subject: [PATCH] djbdns/common.py: assume IPv6 if an address isn't IPv4. In other words, probably crash if convert_ip() is fed garbage. That's OK. We could check the length of the hex string and raise a ValueError if it isn't 8 or 32, but we might be solving problems that don't exist. --- djbdns/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/djbdns/common.py b/djbdns/common.py index 6ef4e1c..1381011 100644 --- a/djbdns/common.py +++ b/djbdns/common.py @@ -67,6 +67,6 @@ def convert_ip(ip : str) -> str: if len(ip) == 8: # IPv4, eg. "7f000001" -> "7f 00 00 01" -> "127.0.0.1" return ".".join(map(str, pack(">L", int(ip, 16)))) - elif len(ip) == 32: - # IPv6 is actually simpler -- it's just a string-slicing operation. - return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)]) + + # IPv6 is actually simpler -- it's just a string-slicing operation. + return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)]) -- 2.44.2