bind (Bluetooth)
A version of this page is also available for
4/8/2010
This function associates a local address with a socket.
Note
This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth.
Syntax
int bind(
SOCKET s,
const struct sockaddr FAR* name,
int namelen
);
Parameters
- s
[in] Descriptor identifying an unbound socket.
- name
[in] Address to assign to the socket from the SOCKADDR_BTH structure.
- namelen
[in] Length of the value in the name parameter.
Return Value
If no error occurs, this function returns zero. If an error occurs, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
Remarks
To bind a Bluetooth socket, name must be SOCKADDR_BTH, with the following members:
name.addressFamily = AF_BTH;
name.btAddr = 0;
name.serviceClassId = GUID_NULL;
name.port = number of service channel or 0;
If the port is 0, the port will be allocated automatically. Remember that server channels are a global resource and there are a total of 31 server channels available for RFCOMM on any Bluetooth device for all applications to share (both Winsock and virtual COM ports).
If there is no available server channel, or the specified server channel is already reserved by another application, the call will fail.
If the call succeeds, the server channel is reserved until the socket is closed. Use getsockname (Bluetooth) to retrieve the channel number (for SDP registration).
It is recommended that an application always use auto-allocation for a server channel, unless a fixed server channel is specified by a future Bluetooth profile specification. Currently, there are no profiles that fix channel numbers.
The following example code shows how to use auto-allocation for a server channel.
SOCKADDR_BTH sab;
memset (&sab, 0, sizeof(sab));
sab.addressFamily = AF_BTH;
sab.port = 0; // auto-allocate server channel
For more information about the bind function, see bind (Windows Sockets) in the Winsock reference.
Requirements
Header | winsock2.h |
Library | Ws2.lib |
Windows Embedded CE | Windows CE .NET 4.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |
See Also
Reference
Bluetooth Application Development Functions
getsockname (Bluetooth)