Click to Rate and Give Feedback
MSDN
MSDN Library
Networking
Network Protocols
Windows Sockets 2
Winsock Reference
Winsock Functions
 getpeername Function

  Switch on low bandwidth view
getpeername Function

The getpeername function retrieves the address of the peer to which a socket is connected.

Syntax

C++
int getpeername(
  __in     SOCKET s,
  __out    struct sockaddr *name,
  __inout  int *namelen
);

Parameters

s [in]

A descriptor identifying a connected socket.

name [out]

The SOCKADDR structure that receives the address of the peer.

namelen [in, out]

A pointer to the size, in bytes, of the name parameter.

Return Value

If no error occurs, getpeername returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Error codeMeaning
WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEFAULT

The name or the namelen parameter is not in a valid part of the user address space, or the namelen parameter is too small.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 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

The getpeername function retrieves the address of the peer connected to the socket s and stores the address in the SOCKADDR structure identified by the name parameter. This function works with any address family and it simply returns the address to which the socket is connected. The getpeername function can be used only on a connected socket.

For datagram sockets, only the address of a peer specified in a previous connect call will be returned. Any address specified by a previous sendto call will not be returned by getpeername.

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

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinsock2.h
LibraryWs2_32.lib
DLLWs2_32.dll

See Also

Winsock Reference
Winsock Functions
bind
connect
getsockname
sendto
socket

Send comments about this topic to Microsoft

Build date: 6/18/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker