getpeername (Windows Sockets) (Windows CE 5.0)
This function retrieves the name of the peer to which a socket is connected.
int getpeername(SOCKET s,struct sockaddr FAR* name,int FAR* namelen);
Parameters
- s
[in] Descriptor identifying a connected socket. - name
[out] Structure that receives the name of the peer. - namelen
[in, out] Pointer to the size of the name structure.
Return Values
If no error occurs, this function returns zero. If an error occurs, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
The following table shows the possible error codes.
Error code | Description |
---|---|
WSANOTINITIALISED | A successful WSAStartup call must occur before using this function. |
WSAENETDOWN | The network subsystem has failed. |
WSAEFAULT | The name or namelen parameter is not a valid part of the user address space, or the namelen parameter is too small. |
WSAEINPROGRESS | A blocking Winsock call is in progress, or the service provider is still processing a callback function. |
WSAENOTCONN | The socket is not connected. |
WSAENOTSOCK | The descriptor is not a socket. |
Remarks
This function retrieves the name of the peer connected to socket s and stores it in the sockaddr structure identified by name. The function can be used only on a connected socket. For datagram sockets, only the name of a peer specified in a previous connect (Windows Sockets) 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 size of the name buffer, in bytes. On return, the namelen parameter contains the actual size in bytes of the name returned.
Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winsock2.h.
Link Library: Ws2.lib.
See Also
bind (Windows Sockets) | connect (Windows Sockets) | getsockname (Windows Sockets) | sendto | socket (Windows Sockets) | WSAGetLastError | WSAStartup | sockaddr
Send Feedback on this topic to the authors