sdlNetResolveHost function

int sdlNetResolveHost(
  1. Pointer<IPaddress> address,
  2. String? host,
  3. int port
)

Resolve a host name and port to an IP address in network form.

If host is NULL, the resolved host will be set to INADDR_ANY.

If the host couldn't be resolved, the host portion of the returned address will be INADDR_NONE, and the function will return -1.

\param address to be filled in with the resolved address and port. \param host the hostname to lookup (like "libsdl.org") \param port the port intended to be connected to, to fill into address. \returns zero on success, -1 on error.

\since This function is available since SDL_net 2.0.0.

extern DECLSPEC int SDLCALL SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)

Implementation

int sdlNetResolveHost(Pointer<IPaddress> address, String? host, int port) {
  final sdlNetResolveHostLookupFunction = libSdl2Net.lookupFunction<
      Int32 Function(
          Pointer<IPaddress> address, Pointer<Utf8> host, Uint16 port),
      int Function(Pointer<IPaddress> address, Pointer<Utf8> host,
          int port)>('SDLNet_ResolveHost');
  final hostPointer = host != null ? host.toNativeUtf8() : nullptr;
  final result = sdlNetResolveHostLookupFunction(address, hostPointer, port);
  calloc.free(hostPointer);
  return result;
}