次の方法で共有


getsockname (Bluetooth) (Compact 2013)

3/26/2014

This function retrieves the local name for a socket.

Syntax

int getsockname(
  SOCKET s,
  struct sockaddr FAR* name,
  int FAR* namelen
);

Parameters

  • s
    [in] Descriptor identifying a socket.
  • name
    [out] Receives the address (name) of the socket.
  • namelen
    [in, out] Size of the name buffer.

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 getsockname to retrieve the server channel allocated to the socket by a call to bind and the Bluetooth address of the local device.

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

Example

The following example code shows how to use getsockname.

SOCKADDR_BTH sab;
int len = sizeof(sab);
if (0 == getsockname (s, &sab, &len)) {
  wprintf (L"Local Bluetooth device is %04x%08x, server channel = %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
Bluetooth API Management Functions