Class Sockaddr

All Implemented Interfaces:
AutoCloseable, NativeResource, Pointer

public class Sockaddr extends Struct<Sockaddr> implements NativeResource

 struct sockaddr {
     sa_family_t sa_family;
     char sa_data[14];
 }
  • Field Details

    • SIZEOF

      public static final int SIZEOF
      The struct size in bytes.
    • ALIGNOF

      public static final int ALIGNOF
      The struct alignment in bytes.
    • SA_FAMILY

      public static final int SA_FAMILY
      The struct member offsets.
    • SA_DATA

      public static final int SA_DATA
      The struct member offsets.
  • Constructor Details

    • Sockaddr

      public Sockaddr(ByteBuffer container)
      Creates a Sockaddr instance at the current position of the specified ByteBuffer container. Changes to the buffer's content will be visible to the struct instance and vice versa.

      The created instance holds a strong reference to the container object.

  • Method Details

    • sizeof

      public int sizeof()
      Description copied from class: Struct
      Returns sizeof(struct).
      Specified by:
      sizeof in class Struct<Sockaddr>
    • sa_family

      public short sa_family()
      Returns:
      the value of the sa_family field.
    • sa_data

      public ByteBuffer sa_data()
      Returns:
      a ByteBuffer view of the sa_data field.
    • sa_data

      public byte sa_data(int index)
      Returns:
      the value at the specified index of the sa_data field.
    • sa_family

      public Sockaddr sa_family(short value)
      Sets the specified value to the sa_family field.
    • sa_data

      public Sockaddr sa_data(ByteBuffer value)
      Copies the specified ByteBuffer to the sa_data field.
    • sa_data

      public Sockaddr sa_data(int index, byte value)
      Sets the specified value at the specified index of the sa_data field.
    • set

      public Sockaddr set(short sa_family, ByteBuffer sa_data)
      Initializes this struct with the specified values.
    • set

      public Sockaddr set(Sockaddr src)
      Copies the specified struct data to this struct.
      Parameters:
      src - the source struct
      Returns:
      this struct
    • malloc

      public static Sockaddr malloc()
      Returns a new Sockaddr instance allocated with memAlloc. The instance must be explicitly freed.
    • calloc

      public static Sockaddr calloc()
      Returns a new Sockaddr instance allocated with memCalloc. The instance must be explicitly freed.
    • create

      public static Sockaddr create()
      Returns a new Sockaddr instance allocated with BufferUtils.
    • create

      public static Sockaddr create(long address)
      Returns a new Sockaddr instance for the specified memory address.
    • createSafe

      public static @Nullable Sockaddr createSafe(long address)
      Like create, but returns null if address is NULL.
    • malloc

      public static Sockaddr.Buffer malloc(int capacity)
      Returns a new Sockaddr.Buffer instance allocated with memAlloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • calloc

      public static Sockaddr.Buffer calloc(int capacity)
      Returns a new Sockaddr.Buffer instance allocated with memCalloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • create

      public static Sockaddr.Buffer create(int capacity)
      Returns a new Sockaddr.Buffer instance allocated with BufferUtils.
      Parameters:
      capacity - the buffer capacity
    • create

      public static Sockaddr.Buffer create(long address, int capacity)
      Create a Sockaddr.Buffer instance at the specified memory.
      Parameters:
      address - the memory address
      capacity - the buffer capacity
    • createSafe

      public static @Nullable Sockaddr.Buffer createSafe(long address, int capacity)
      Like create, but returns null if address is NULL.
    • malloc

      public static Sockaddr malloc(MemoryStack stack)
      Returns a new Sockaddr instance allocated on the specified MemoryStack.
      Parameters:
      stack - the stack from which to allocate
    • calloc

      public static Sockaddr calloc(MemoryStack stack)
      Returns a new Sockaddr instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      stack - the stack from which to allocate
    • malloc

      public static Sockaddr.Buffer malloc(int capacity, MemoryStack stack)
      Returns a new Sockaddr.Buffer instance allocated on the specified MemoryStack.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • calloc

      public static Sockaddr.Buffer calloc(int capacity, MemoryStack stack)
      Returns a new Sockaddr.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • nsa_family

      public static short nsa_family(long struct)
      Unsafe version of sa_family().
    • nsa_data

      public static ByteBuffer nsa_data(long struct)
      Unsafe version of sa_data().
    • nsa_data

      public static byte nsa_data(long struct, int index)
      Unsafe version of sa_data.
    • nsa_family

      public static void nsa_family(long struct, short value)
      Unsafe version of sa_family.
    • nsa_data

      public static void nsa_data(long struct, ByteBuffer value)
      Unsafe version of sa_data.
    • nsa_data

      public static void nsa_data(long struct, int index, byte value)
      Unsafe version of sa_data.