Class InetAddress

java.lang.Object
dev.gmitch215.bytebox.net.InetAddress

public class InetAddress extends Object
An IP address, standing in for java.net.InetAddress.

The platform exposes no resolver, which is a statement about the API rather than about DNS: DNS is a protocol, and one of the ways to speak it is over HTTPS. So a name is resolved by asking a DNS-over-HTTPS resolver with fetch, which suspends the fiber the way any other lookup does and reads like an ordinary call.

getByName(java.lang.String) does not go over the network for an address written as one, nor for localhost, so the common cases cost nothing. A resolved name is remembered for the life of the isolate; the platform's own resolver caching is what decides how stale that can be, and a Worker lives far too short a time for a TTL to be worth tracking.

Two limits. isReachable(int) sends an HTTPS request rather than an ICMP echo, because the platform cannot send a datagram - so it reports whether a host answers HTTPS, which is a different question and is documented as such rather than faked. And a lookup is a subrequest, so it counts against the 50 the free plan allows per invocation.

What is not here, because nothing can back it: the local host's own address, a network interface, and a reverse lookup of a name from an address the resolver was not asked for.

Since:
1.0.0
  • Method Details

    • getByName

      public static InetAddress getByName(String host) throws UnknownHostException
      The address of a host.
      Parameters:
      host - a host name, or an address written as one
      Returns:
      the first address the resolver gave
      Throws:
      UnknownHostException - when the resolver has no address for it
    • getAllByName

      public static InetAddress[] getAllByName(String host) throws UnknownHostException
      Every address of a host.
      Parameters:
      host - a host name, or an address written as one
      Returns:
      the addresses, IPv4 before IPv6
      Throws:
      UnknownHostException - when the resolver has no address for it
    • getByAddress

      public static InetAddress getByAddress(String host, byte[] address) throws UnknownHostException
      An address for a host name, without asking a resolver.
      Parameters:
      host - the name to report, or null
      address - the four or sixteen bytes of the address
      Returns:
      the address
      Throws:
      UnknownHostException - when the length is neither four nor sixteen
    • getByAddress

      public static InetAddress getByAddress(byte[] address) throws UnknownHostException
      An address, without asking a resolver.
      Parameters:
      address - the four or sixteen bytes of the address
      Returns:
      the address
      Throws:
      UnknownHostException - when the length is neither four nor sixteen
    • getHostAddress

      public String getHostAddress()
      Returns the address as text.
      Returns:
      the address as text
    • getHostName

      public String getHostName()
      Returns the name this address was resolved from, or the address when there was none.
      Returns:
      the name this address was resolved from, or the address when there was none
    • getCanonicalHostName

      public String getCanonicalHostName()
      Returns the same as getHostName(), since no reverse lookup is made.
      Returns:
      the same as getHostName(), since no reverse lookup is made
    • getAddress

      public byte[] getAddress()
      Returns the four or sixteen bytes of the address.
      Returns:
      the four or sixteen bytes of the address
    • isReachable

      public boolean isReachable(int timeoutMillis) throws IOException
      Whether the host answers an HTTPS request within a deadline.

      Not an ICMP echo, which the platform cannot send. A host that is up but serves no HTTPS reads as unreachable here.

      Parameters:
      timeoutMillis - how long to allow, or zero for no limit
      Returns:
      whether it answered
      Throws:
      IOException - when the request could not be made at all
    • isLoopbackAddress

      public boolean isLoopbackAddress()
      Returns whether this is a loopback address.
      Returns:
      whether this is a loopback address
    • isSiteLocalAddress

      public boolean isSiteLocalAddress()
      Returns whether this is an address only reachable inside a private network.
      Returns:
      whether this is an address only reachable inside a private network
    • isMulticastAddress

      public boolean isMulticastAddress()
      Returns whether this is a multicast address.
      Returns:
      whether this is a multicast address
    • isAnyLocalAddress

      public boolean isAnyLocalAddress()
      Returns whether this is the unspecified address.
      Returns:
      whether this is the unspecified address
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object