次の方法で共有


getpeername (Windows Sockets) (Windows Embedded CE 6.0)

1/6/2010

This function retrieves the name of the peer to which a socket is connected.

Syntax

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 Value

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

Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE 1.0 and later

See Also

Reference

bind (Windows Sockets)
connect (Windows Sockets)
getsockname (Windows Sockets)
sendto
socket (Windows Sockets)
WSAGetLastError
WSAStartup
sockaddr

Concepts

Socket Functions