次の方法で共有


getpeername (Bluetooth) (Compact 2013)

3/26/2014

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

Returns zero on success; otherwise SOCKET_ERROR. The specific error code can be retrieved by calling WSAGetLastError.

Remarks

Note

This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth.

Use getpeername on a connected socket to retrieve the Bluetooth address of the peer Bluetooth device.

For more information about the getpeername function, see getpeername (Windows Sockets) in the Winsock reference.

Example

The following example code shows how to use getpeername.

SOCKADDR_BTH sab;
int len = sizeof(sab);
if (0 == getpeername (s, &sab, &len)) {
  wprintf (L"Remote Bluetooth device is %04x%08x, connected to %d\n",
  GET_NAP(sab.btAddr), GET_SAP(sab.btAddr), sab.port);
}

Requirements

Header

winsock2.h

Library

Ws2.lib

See Also

Reference

Bluetooth API Miscellaneous Functions