Skip to content
Start free evaluation

pdcomm_tcp_local_address

Function

Copies the local socket address as text.

PdcommStatus pdcomm_tcp_local_address(PdcommTcpEndpoint *endpoint, uint8_t *output, size_t capacity, size_t *required)

Declared in: #include <pdcomm_tcp.h>

A passive endpoint reports its listening address while it owns a listening socket: from creation until pdcomm_tcp_stop(), and again after pdcomm_tcp_start(). An active endpoint reports the local address of its current connection. The text has the form 127.0.0.1:5000 or [::1]:5000, has no NUL terminator, and fits in 80 bytes.

Parameters

NameDescription
endpointLive endpoint.
outputDestination. May be NULL when capacity is 0 for a size query.
capacitySize of output in bytes.
requiredReceives the text length; set to 0 first. Must not be NULL.

Returns

#PDCOMM_OK when the text was copied; #PDCOMM_BUFFER_TOO_SMALL when capacity is smaller than *required (output untouched); #PDCOMM_INVALID_ARGUMENT when required or endpoint is NULL, or output is NULL with sufficient capacity; #PDCOMM_IO_ERROR when there is no listening socket or connection, or the operating system cannot report the address; #PDCOMM_POISONED.