netGetAddressBytes function net

Pointer<NativeType> netGetAddressBytes(
  1. Pointer<NetAddress> address,
  2. Pointer<Int32> numBytes
)

Get the protocol-level bytes of a network address from a resolved address.

This data is not human-readable, is protocol-specific, and might not even be in a specific byte order.

This is only useful for possibly hashing, to map a address to a specific player in a game, or possibly for handing to a system-level networking API (which is not recommended; an app does this at their own risk).

Do not store these bytes for future runs of the program; there is no promise the format won't change.

On return *num_bytes will hold the number of bytes provided with the address. Since the data is not NULL-terminated, this is the only way to determine its size; as such, this parameter must not be NULL.

Do not free or modify the returned data; it belongs to the NET_Address that was queried, and is valid as long as the object lives. Either make sure the address has a reference as long as you need this or make a copy of the bytes.

This will return NULL if resolution is still in progress, or if resolution failed. You can use NET_GetAddressStatus() or NET_WaitUntilResolved() to make sure resolution has successfully completed before calling this.

A human-readable version is available in NET_GetAddressString() and isn't any less efficient to query than the raw bytes.

\param address The NET_Address to query. \param num_bytes on return, will be set to the number of bytes returned. \returns a pointer to bytes, or NULL on error; call SDL_GetError() for details.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL_net 3.0.0.

\sa NET_GetAddressString \sa NET_GetAddressStatus \sa NET_WaitUntilResolved

extern SDL_DECLSPEC const void * SDLCALL NET_GetAddressBytes(NET_Address *address, int *num_bytes)

Implementation

Pointer<NativeType> netGetAddressBytes(
  Pointer<NetAddress> address,
  Pointer<Int32> numBytes,
) {
  final netGetAddressBytesLookupFunction = _libNet
      .lookupFunction<
        Pointer<NativeType> Function(
          Pointer<NetAddress> address,
          Pointer<Int32> numBytes,
        ),
        Pointer<NativeType> Function(
          Pointer<NetAddress> address,
          Pointer<Int32> numBytes,
        )
      >('NET_GetAddressBytes');
  return netGetAddressBytesLookupFunction(address, numBytes);
}