Skip to content

Latest commit

 

History

History
194 lines (148 loc) · 5.19 KB

nf-winsock-getpeername.md

File metadata and controls

194 lines (148 loc) · 5.19 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winsock.getpeername
getpeername function (winsock.h)
The getpeername function (winsock.h) retrieves the address of the peer to which a socket is connected.
_win32_getpeername_2
getpeername
getpeername function [Winsock]
winsock.getpeername_2
winsock/getpeername
winsock\getpeername_2.htm
WinSock
df2679a5-cdd9-468b-823a-f98044189f65
08/15/2022
_win32_getpeername_2, getpeername, getpeername function [Winsock], winsock.getpeername_2, winsock/getpeername
winsock.h
Winsock2.h
Windows
Windows 8.1, Windows Vista [desktop apps \| UWP apps]
Windows Server 2003 [desktop apps \| UWP apps]
Ws2_32.lib
Ws2_32.dll
Windows
19H1
getpeername
winsock/getpeername
c++
APIRef
kbSyntax
DllExport
Ws2_32.dll
getpeername

getpeername function

-description

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

-parameters

-param s [in]

A descriptor identifying a connected socket.

-param name [out]

The SOCKADDR structure that receives the address of the peer.

-param namelen [in, out]

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

-returns

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 code Meaning
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.

Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

-see-also

Winsock Functions

Winsock Reference

bind

connect

getsockname

sendto

socket