Export (0) Print
Expand All

getpeername (Windows Sockets)

Windows Mobile 6.5
A version of this page is also available for
4/8/2010

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
);

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.

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.

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.

Headerwinsock2.h
LibraryWs2.lib
Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

ADD
Show:
© 2014 Microsoft