sock_addr_peer()
Returns the remote address to which the socket is connected to.
Description
The sock_addr_peer() function retrieves the remote address to which the socket identified by the file descriptor sock is connected and stores the address in the ro_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 `getpeername` in POSIX
;;;
;;; Returns the remote address to which the socket is connected to.
(@interface func (export "sock_addr_peer")
;;; 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.ro_addr: A WebAssembly pointer to a memory location where the remote 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_peer()function retrieves the remote address to which the socket identified by the file descriptorsockis connected. - The remote address consists of an IP address (either IPv4 or IPv6) and a port number.
- The remote address is stored in the
ro_addrmemory location, which should be aWasmPtr<__wasi_addr_port_t>pointing to a writable memory region. - The function
sock_addr_peer()is similar to thegetpeernamefunction in POSIX. - The behavior and limitations of the
sock_addr_peer()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.