Documentation
WASIX
sock_addr_local

sock_addr_local()

Returns the local address to which the socket is bound.

Description

The sock_addr_local() function retrieves the local address to which the socket identified by the file descriptor sock is bound and stores the address in the ret_addr memory location.

Syntax

  ;;; either IP4 or IP6.
  ;;; When successful, the contents of the output buffer consist of an IP address,
  ;;;
  ;;; Note: This is similar to `getsockname` in POSIX
  ;;;
  ;;; Returns the local address to which the socket is bound.
  (@interface func (export "sock_addr_local")
    ;;; Socket that the address is bound to
    (param $fd $fd)
    (result $error (expected $addr_port (error $errno)))
  )

Parameters

  • ctx: A mutable reference to the function environment.
  • sock: The file descriptor of the socket.
  • ret_addr: A WebAssembly pointer to a memory location where the local address will be stored.

Return Value

The function returns an Errno value indicating the outcome of the operation. If the operation is successful, Errno::Success is returned. If an error occurs, an appropriate Errno value is returned.

Notes

  • The sock_addr_local() function retrieves the local address to which the socket identified by the file descriptor sock is bound.
  • The local address consists of an IP address (either IPv4 or IPv6) and a port number.
  • The local address is stored in the ret_addr memory location, which should be a WasmPtr<__wasi_addr_port_t> pointing to a writable memory region.
  • The function sock_addr_local() is similar to the getsockname function in POSIX.
  • The behavior and limitations of the sock_addr_local() function may vary depending on the specific runtime environment and underlying networking implementation. It is important to consult the documentation or specifications of the specific environment to understand its behavior in that context.