getpeername

This function gets the peer address to which a socket is connected.

At a Glance

Header file: Winsock.h
Windows CE versions: 1.0 and later

Syntax

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

Parameters

s

[in] Descriptor that identifies a connected socket.

name

[out] Structure that receives the peer name.

namelen

[in/out] Pointer to the name structure size.

Return Values

Zero indicates no error occurred. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

The getpeername function retrieves the peer name connected to the socket s and stores it in the a SOCKADDR structure identified by name. The getpeername function can be used only on a connected socket. For datagram sockets, only the name of a peer specified in a previous connect call will be returned—any name specified by a previous sendto call will not be returned by getpeername.

On call, the namelen argument contains the name buffer size, in bytes. On return, the namelen parameter contains the actual size, in bytes, of the name returned.

See Also

bind, getsockname, socket