WSPGetPeerName

The WSPGetPeerName function gets the address of the peer to which a socket is connected.

int WSPGetPeerName (
  SOCKET s,                     
  struct sockaddr FAR * name,   
  LPINT namelen,                
  LPINT lpErrno                 
);
 

Parameters

s
[in] A descriptor identifying a connected socket.
name
[out] A pointer to the structure which is to receive the name of the peer.
namelen
[in/out] A pointer to an integer which, on input, indicates the size of the structure pointed to by name, and on output indicates the size of the returned name.
lpErrno
[out] A pointer to the error code.

Remarks

WSPGetPeerName supplies the name of the peer connected to the socket s and stores it in the struct SOCKADDR referenced by name. It can be used only on a connected socket. For datagram sockets, only the name of a peer specified in a previous WSPConnect call will be returned—any name specified by a previous WSPSendTo call will not be returned by WSPGetPeerName.

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

Return Values

If no error occurs, WSPGetPeerName returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code is available in lpErrno.

Error Codes

WSAENETDOWN The network subsystem has failed.
WSAEFAULT The name or the namelen argument is not a valid part of the user address space, or the namelen argument is too small.
WSAEINPROGRESS The function is invoked when a callback is in progress.
WSAENOTCONN The socket is not connected.
WSAENOTSOCK The descriptor is not a socket.

QuickInfo

  Windows NT: Yes
  Windows: Yes
  Windows CE: Unsupported.
  Header: Declared in ws2spi.h.

See Also

WSPBind, WSPSocket, WSPGetSockName