Class InetAddress

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class InetAddress extends GObject

GInetAddress represents an IPv4 or IPv6 internet address. Use Resolver.lookupByName(String, Cancellable) or Resolver.lookupByNameAsync(String, Cancellable, AsyncReadyCallback) to look up the GInetAddress for a hostname. Use Resolver.lookupByAddress(InetAddress, Cancellable) or Resolver.lookupByAddressAsync(InetAddress, Cancellable, AsyncReadyCallback) to look up the hostname for a GInetAddress.

To actually connect to a remote host, you will need a InetSocketAddress (which includes a GInetAddress as well as a port number).

  • Constructor Details

    • InetAddress

      public InetAddress(MemorySegment address)
      Create a InetAddress instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • InetAddress

      public InetAddress()
      Create a new InetAddress.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the InetAddress class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected InetAddress asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • any

      public static InetAddress any(SocketFamily family)
      Creates a GInetAddress for the "any" address (unassigned/"don't care") for family.
      Parameters:
      family - the address family
      Returns:
      a new GInetAddress corresponding to the "any" address for family. Free the returned object with g_object_unref().
      Since:
      2.22
    • fromBytes

      public static InetAddress fromBytes(@Nullable byte @Nullable [] bytes, SocketFamily family)
      Creates a new GInetAddress from the given family and bytes. bytes should be 4 bytes for SocketFamily.IPV4 and 16 bytes for SocketFamily.IPV6.
      Parameters:
      bytes - raw address data
      family - the address family of bytes
      Returns:
      a new GInetAddress corresponding to family and bytes. Free the returned object with g_object_unref().
      Since:
      2.22
    • fromBytesWithIpv6Info

      public static InetAddress fromBytesWithIpv6Info(@Nullable byte @Nullable [] bytes, SocketFamily family, int flowinfo, int scopeId)

      Creates a new InetAddress from the given family, bytes and scopeId.

      bytes must be 4 bytes for Gio.SocketFamily.IPV4 and 16 bytes for Gio.SocketFamily.IPV6.

      Parameters:
      bytes - raw address data
      family - the address family of bytes
      scopeId - the scope-id of the address
      Returns:
      a new internet address corresponding to family, bytes and scopeId
      Since:
      2.86
    • fromString

      public static @Nullable InetAddress fromString(String string)

      Parses string as an IP address and creates a new GInetAddress.

      If address is an IPv6 address, it can also contain a scope ID (separated from the address by a %). Note that currently this behavior is platform specific. This may change in a future release.

      Parameters:
      string - a string representation of an IP address
      Returns:
      a new GInetAddress corresponding to string, or null if string could not be parsed. Free the returned object with g_object_unref().
      Since:
      2.22
    • loopback

      public static InetAddress loopback(SocketFamily family)
      Creates a GInetAddress for the loopback address for family.
      Parameters:
      family - the address family
      Returns:
      a new GInetAddress corresponding to the loopback address for family. Free the returned object with g_object_unref().
      Since:
      2.22
    • equal

      public boolean equal(InetAddress otherAddress)
      Checks if two GInetAddress instances are equal, e.g. the same address.
      Parameters:
      otherAddress - Another GInetAddress.
      Returns:
      true if this InetAddress and otherAddress are equal, false otherwise.
      Since:
      2.30
    • getFamily

      public SocketFamily getFamily()
      Gets address's family
      Returns:
      address's family
      Since:
      2.22
    • getFlowinfo

      public int getFlowinfo()
      Gets the value of Gio.InetAddress:flowinfo.
      Returns:
      The flowinfo for the address, 0 if unset or not IPv6 address.
      Since:
      2.86
    • getIsAny

      public boolean getIsAny()
      Tests whether this InetAddress is the "any" address for its family.
      Returns:
      true if this InetAddress is the "any" address for its family.
      Since:
      2.22
    • getIsLinkLocal

      public boolean getIsLinkLocal()
      Tests whether this InetAddress is a link-local address (that is, if it identifies a host on a local network that is not connected to the Internet).
      Returns:
      true if this InetAddress is a link-local address.
      Since:
      2.22
    • getIsLoopback

      public boolean getIsLoopback()
      Tests whether this InetAddress is the loopback address for its family.
      Returns:
      true if this InetAddress is the loopback address for its family.
      Since:
      2.22
    • getIsMcGlobal

      public boolean getIsMcGlobal()
      Tests whether this InetAddress is a global multicast address.
      Returns:
      true if this InetAddress is a global multicast address.
      Since:
      2.22
    • getIsMcLinkLocal

      public boolean getIsMcLinkLocal()
      Tests whether this InetAddress is a link-local multicast address.
      Returns:
      true if this InetAddress is a link-local multicast address.
      Since:
      2.22
    • getIsMcNodeLocal

      public boolean getIsMcNodeLocal()
      Tests whether this InetAddress is a node-local multicast address.
      Returns:
      true if this InetAddress is a node-local multicast address.
      Since:
      2.22
    • getIsMcOrgLocal

      public boolean getIsMcOrgLocal()
      Tests whether this InetAddress is an organization-local multicast address.
      Returns:
      true if this InetAddress is an organization-local multicast address.
      Since:
      2.22
    • getIsMcSiteLocal

      public boolean getIsMcSiteLocal()
      Tests whether this InetAddress is a site-local multicast address.
      Returns:
      true if this InetAddress is a site-local multicast address.
      Since:
      2.22
    • getIsMulticast

      public boolean getIsMulticast()
      Tests whether this InetAddress is a multicast address.
      Returns:
      true if this InetAddress is a multicast address.
      Since:
      2.22
    • getIsSiteLocal

      public boolean getIsSiteLocal()
      Tests whether this InetAddress is a site-local address such as 10.0.0.1 (that is, the address identifies a host on a local network that can not be reached directly from the Internet, but which may have outgoing Internet connectivity via a NAT or firewall).
      Returns:
      true if this InetAddress is a site-local address.
      Since:
      2.22
    • getNativeSize

      public long getNativeSize()
      Gets the size of the native raw binary address for address. This is the size of the data that you get from g_inet_address_to_bytes().
      Returns:
      the number of bytes used for the native version of address.
      Since:
      2.22
    • getScopeId

      public int getScopeId()
      Gets the value of Gio.InetAddress:scope-id.
      Returns:
      The scope-id for the address, 0 if unset or not IPv6 address.
      Since:
      2.86
    • toBytes

      public MemorySegment toBytes()
      Gets the raw binary address data from address.
      Returns:
      a pointer to an internal array of the bytes in address, which should not be modified, stored, or freed. The size of this array can be gotten with g_inet_address_get_native_size().
      Since:
      2.22
    • toString

      public String toString()
      Converts this InetAddress to string form.
      Overrides:
      toString in class Object
      Returns:
      a representation of this InetAddress as a string, which should be freed after use.
      Since:
      2.22
    • builder

      public static InetAddress.Builder<? extends InetAddress.Builder> builder()
      A InetAddress.Builder object constructs a InetAddress with the specified properties. Use the various set...() methods to set properties, and finish construction with InetAddress.Builder.build().
      Returns:
      the builder object