+ @staticmethod
+ def GetVersionFromAddressFamily(family):
+ """Convert an IP address family to the corresponding IP version.
+
+ @type family: int
+ @param family: IP address family, one of socket.AF_INET or socket.AF_INET6
+ @return: an int containing the IP version, one of L{constants.IP4_VERSION}
+ or L{constants.IP6_VERSION}
+ @raise errors.ProgrammerError: for unknown families
+
+ """
+ if family == socket.AF_INET:
+ return constants.IP4_VERSION
+ elif family == socket.AF_INET6:
+ return constants.IP6_VERSION
+
+ raise errors.ProgrammerError("%s is not a valid IP address family" % family)
+
+ @staticmethod
+ def GetAddressFamilyFromVersion(version):
+ """Convert an IP version to the corresponding IP address family.
+
+ @type version: int
+ @param version: IP version, one of L{constants.IP4_VERSION} or
+ L{constants.IP6_VERSION}
+ @return: an int containing the IP address family, one of C{socket.AF_INET}
+ or C{socket.AF_INET6}
+ @raise errors.ProgrammerError: for unknown IP versions
+
+ """
+ if version == constants.IP4_VERSION:
+ return socket.AF_INET
+ elif version == constants.IP6_VERSION:
+ return socket.AF_INET6
+
+ raise errors.ProgrammerError("%s is not a valid IP version" % version)
+
+ @staticmethod
+ def GetClassFromIpVersion(version):
+ """Return the IPAddress subclass for the given IP version.
+
+ @type version: int
+ @param version: IP version, one of L{constants.IP4_VERSION} or
+ L{constants.IP6_VERSION}
+ @return: a subclass of L{netutils.IPAddress}
+ @raise errors.ProgrammerError: for unknowo IP versions
+
+ """
+ if version == constants.IP4_VERSION:
+ return IP4Address
+ elif version == constants.IP6_VERSION:
+ return IP6Address
+
+ raise errors.ProgrammerError("%s is not a valid IP version" % version)
+
+ @staticmethod
+ def GetClassFromIpFamily(family):
+ """Return the IPAddress subclass for the given IP family.
+
+ @param family: IP family (one of C{socket.AF_INET} or C{socket.AF_INET6}
+ @return: a subclass of L{netutils.IPAddress}
+ @raise errors.ProgrammerError: for unknowo IP versions
+
+ """
+ return IPAddress.GetClassFromIpVersion(
+ IPAddress.GetVersionFromAddressFamily(family))
+