Class SocketAddress

All Implemented Interfaces:
SocketConnectable, Proxy
Direct Known Subclasses:
InetSocketAddress, NativeSocketAddress, SocketAddress.SocketAddress$Impl, UnixSocketAddress

@Generated("org.javagi.JavaGI") public abstract class SocketAddress extends GObject implements SocketConnectable
GSocketAddress is the equivalent of struct sockaddr and its subtypes in the BSD sockets API. This is an abstract class; use InetSocketAddress for internet sockets, or UnixSocketAddress for UNIX domain sockets.
  • Constructor Details

    • SocketAddress

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

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

    • getType

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

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

      protected SocketAddress 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
    • fromNative

      public static SocketAddress fromNative(MemorySegment native_, long len)
      Creates a GSocketAddress subclass corresponding to the native struct sockaddr native.
      Parameters:
      native_ - a pointer to a struct sockaddr
      len - the size of the memory location pointed to by native_
      Returns:
      a new GSocketAddress if native_ could successfully be converted, otherwise null
      Since:
      2.22
    • getFamily

      public SocketFamily getFamily()
      Gets the socket family type of address.
      Returns:
      the socket family type of this SocketAddress
      Since:
      2.22
    • getNativeSize

      public long getNativeSize()
      Gets the size of address's native struct sockaddr. You can use this to allocate memory to pass to g_socket_address_to_native().
      Returns:
      the size of the native struct sockaddr that this SocketAddress represents, or -1 if this SocketAddress is not valid
      Since:
      2.22
    • toNative

      public boolean toNative(@Nullable MemorySegment dest, long destlen) throws GErrorException

      Converts a GSocketAddress to a native struct sockaddr, which can be passed to low-level functions like connect() or bind().

      If not enough space is available, a IOErrorEnum.NO_SPACE error is returned. If the address type is not known on the system then a IOErrorEnum.NOT_SUPPORTED error is returned.

      Parameters:
      dest - a pointer to a memory location that will contain the native struct sockaddr
      destlen - the size of dest. Must be at least as large as g_socket_address_get_native_size()
      Returns:
      true if dest was filled in, false on error
      Throws:
      GErrorException - see GError
      Since:
      2.22