Address (dnsjava documentation)
Date: 2013-04-10

org.xbill.DNS

## Class Address

- java.lang.Object
- - org.xbill.DNS.Address

-     public final class Address
      extends Object

  Routines dealing with IP addresses. Includes functions similar to those in the java.net.InetAddress class.
  Author:
    Brian Wellington

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `IPv4`
    `static int` | `IPv6`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `addressLength(int family)` Returns the length of an address in a particular family.
    `static int` | `familyOf(InetAddress address)` Returns the family of an InetAddress.
    `static InetAddress[]` | `getAllByName(String name)` Determines all IP address of a host
    `static InetAddress` | `getByAddress(String addr)` Converts an address from its string representation to an IP address.
    `static InetAddress` | `getByAddress(String addr, int family)` Converts an address from its string representation to an IP address in a particular family.
    `static InetAddress` | `getByName(String name)` Determines the IP address of a host
    `static String` | `getHostName(InetAddress addr)` Determines the hostname for an address
    `static boolean` | `isDottedQuad(String s)` Determines if a string contains a valid IP address.
    `static int[]` | `toArray(String s)` Convert a string containing an IPv4 address to an array of 4 integers.
    `static int[]` | `toArray(String s, int family)` Convert a string containing an IP address to an array of 4 or 16 integers.
    `static byte[]` | `toByteArray(String s, int family)` Convert a string containing an IP address to an array of 4 or 16 bytes.
    `static String` | `toDottedQuad(byte[] addr)` Converts a byte array containing an IPv4 address into a dotted quad string.
    `static String` | `toDottedQuad(int[] addr)` Converts an int array containing an IPv4 address into a dotted quad string.
    `static InetAddress` | `truncate(InetAddress address, int maskLength)` Truncates an address to the specified number of bits.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### IPv4

          public static final int IPv4

      See Also:
        Constant Field Values

    - #### IPv6

          public static final int IPv6

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### toArray

          public static int[] toArray(String s,
                      int family)

      Convert a string containing an IP address to an array of 4 or 16 integers.
      Parameters:
        `s` - The address, in text format.
        `family` - The address family.
      Returns:
        The address

    - #### toArray

          public static int[] toArray(String s)

      Convert a string containing an IPv4 address to an array of 4 integers.
      Parameters:
        `s` - The address, in text format.
      Returns:
        The address

    - #### toByteArray

          public static byte[] toByteArray(String s,
                           int family)

      Convert a string containing an IP address to an array of 4 or 16 bytes.
      Parameters:
        `s` - The address, in text format.
        `family` - The address family.
      Returns:
        The address

    - #### isDottedQuad

          public static boolean isDottedQuad(String s)

      Determines if a string contains a valid IP address.
      Parameters:
        `s` - The string
      Returns:
        Whether the string contains a valid IP address

    - #### toDottedQuad

          public static String toDottedQuad(byte[] addr)

      Converts a byte array containing an IPv4 address into a dotted quad string.
      Parameters:
        `addr` - The array
      Returns:
        The string representation

    - #### toDottedQuad

          public static String toDottedQuad(int[] addr)

      Converts an int array containing an IPv4 address into a dotted quad string.
      Parameters:
        `addr` - The array
      Returns:
        The string representation

    - #### getByName

          public static InetAddress getByName(String name)
                                       throws UnknownHostException

      Determines the IP address of a host
      Parameters:
        `name` - The hostname to look up
      Returns:
        The first matching IP address
      Throws:
        `UnknownHostException` - The hostname does not have any addresses

    - #### getAllByName

          public static InetAddress[] getAllByName(String name)
                                            throws UnknownHostException

      Determines all IP address of a host
      Parameters:
        `name` - The hostname to look up
      Returns:
        All matching IP addresses
      Throws:
        `UnknownHostException` - The hostname does not have any addresses

    - #### getByAddress

          public static InetAddress getByAddress(String addr)
                                          throws UnknownHostException

      Converts an address from its string representation to an IP address. The address can be either IPv4 or IPv6.
      Parameters:
        `addr` - The address, in string form
      Returns:
        The IP addresses
      Throws:
        `UnknownHostException` - The address is not a valid IP address.

    - #### getByAddress

          public static InetAddress getByAddress(String addr,
                                 int family)
                                          throws UnknownHostException

      Converts an address from its string representation to an IP address in a particular family.
      Parameters:
        `addr` - The address, in string form
        `family` - The address family, either IPv4 or IPv6.
      Returns:
        The IP addresses
      Throws:
        `UnknownHostException` - The address is not a valid IP address in the specified address family.

    - #### getHostName

          public static String getHostName(InetAddress addr)
                                    throws UnknownHostException

      Determines the hostname for an address
      Parameters:
        `addr` - The address to look up
      Returns:
        The associated host name
      Throws:
        `UnknownHostException` - There is no hostname for the address

    - #### familyOf

          public static int familyOf(InetAddress address)

      Returns the family of an InetAddress.
      Parameters:
        `address` - The supplied address.
      Returns:
        The family, either IPv4 or IPv6.

    - #### addressLength

          public static int addressLength(int family)

      Returns the length of an address in a particular family.
      Parameters:
        `family` - The address family, either IPv4 or IPv6.
      Returns:
        The length of addresses in that family.

    - #### truncate

          public static InetAddress truncate(InetAddress address,
                             int maskLength)

      Truncates an address to the specified number of bits. For example, truncating the address 10.1.2.3 to 8 bits would yield 10.0.0.0.
      Parameters:
        `address` - The source address
        `maskLength` - The number of bits to truncate the address to.