Skip to content
BSD syscall#32

svc · unix #32

getsockname

Returns the locally bound address of a socket.

Prototype

int getsockname(int fdes, caddr_t asa, socklen_t *alen);

Returns: int

Arguments

NameTypeDirDescription
fdesint-
asacaddr_t-
alensocklen_t-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard32
xnu-1486.2.1132
xnu-1504.15.332
xnu-1504.3.1232
xnu-1504.7.432
xnu-1504.9.1732
xnu-1504.9.2632
xnu-1504.9.3732

Notes

After an implicit bind (issued by connect on an unbound socket) this is the only way to learn the ephemeral port the kernel picked. For AF_UNIX the returned sockaddr_un is truncated at the kernel-imposed 104-byte path limit. NetworkExtension flows can rewrite the apparent local address when traffic is redirected into a tunnel, so the value seen here may differ from the kernel routing table.

Detection

Not security-relevant in isolation. proc_pidfdinfo with PROC_PIDFDSOCKETINFO returns the same data without requiring the syscall.

Related APIs

getpeernamebindsocketsetsockopt