-# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2003-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
from ._compat import binary_type
def inet_ntoa(address):
- """Convert an IPv4 address in network form to text form.
+ """Convert an IPv4 address in binary form to text form.
- @param address: The IPv4 address
- @type address: string
- @returns: string
+ *address*, a ``binary``, the IPv4 address in binary form.
+
+ Returns a ``text``.
"""
+
if len(address) != 4:
raise dns.exception.SyntaxError
if not isinstance(address, bytearray):
address[2], address[3]))
def inet_aton(text):
- """Convert an IPv4 address in text form to network form.
+ """Convert an IPv4 address in text form to binary form.
- @param text: The IPv4 address
- @type text: string
- @returns: string
+ *text*, a ``text``, the IPv4 address in textual form.
+
+ Returns a ``binary``.
"""
+
if not isinstance(text, binary_type):
text = text.encode()
parts = text.split(b'.')
-# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2003-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
_leading_zero = re.compile('0+([0-9a-f]+)')
def inet_ntoa(address):
- """Convert a network format IPv6 address into text.
+ """Convert an IPv6 address in binary form to text form.
- @param address: the binary address
- @type address: string
- @rtype: string
- @raises ValueError: the address isn't 16 bytes long
+ *address*, a ``binary``, the IPv6 address in binary form.
+
+ Raises ``ValueError`` if the address isn't 16 bytes long.
+ Returns a ``text``.
"""
if len(address) != 16:
_colon_colon_end = re.compile(b'.*::$')
def inet_aton(text):
- """Convert a text format IPv6 address into network format.
+ """Convert an IPv6 address in text form to binary form.
+
+ *text*, a ``text``, the IPv6 address in textual form.
- @param text: the textual address
- @type text: string
- @rtype: string
- @raises dns.exception.SyntaxError: the text was not properly formatted
+ Returns a ``binary``.
"""
#
_mapped_prefix = b'\x00' * 10 + b'\xff\xff'
def is_mapped(address):
+ """Is the specified address a mapped IPv4 address?
+
+ *address*, a ``binary`` is an IPv6 address in binary form.
+
+ Returns a ``bool``.
+ """
+
return address.startswith(_mapped_prefix)