getsockname

getsockname fills in the IP address and port that we are using on a specified socket.

Syntax

int getsockname(
    SOCKET s,
    struct sockaddr *name,
    int *namelen
);

Parameters

s

Socket descriptor.

name

Pointer to a socket address structure that will be filled in by getsockname.

namelen

Pointer to an integer that defines the size of the socket address structure indicated by name. Upon return, namelen shall contain the actual size in bytes of name.

Return Value

0 (zero) if the function succeeds, SOCKET_ERROR if the function fails

Use WSAGetLastError to retrieve a specific error code.

Requirements

Minimum Supported Version RTX64 2013
Header Winsock2.h
Library RtTcpip.lib