I'm trying to open a socket for using bluetooth and I'm getting an error (10047: Address family not supported by protocol family).
I'm using a USB dongle that's WIDCOMM. I'm able to find and search for devices using the bluetooth manager, so I think that it should work with the Microsoft SDK.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <Winsock2.h>
#include <Bthsdpdef.h>
#include <Ws2bth.h>
#include <BluetoothAPIs.h>
int main()
{
WSADATA wsd;
SOCKADDR_BTH btconn;
SOCKADDR_BTH btclient;
SOCKET server_socket;
SOCKET client_socket;
BLUETOOTH_DEVICE_SEARCH_PARAMS BluetoothSearchParams;
BLUETOOTH_DEVICE_INFO BluetoothDeviceInfo;
HBLUETOOTH_DEVICE_FIND hBluetoothDevice;
int btclientsize;
int rError;
if(WSAStartup(MAKEWORD(1,0), &wsd) != 0){
printf("Unable to load Winsock! Error code is %d\n", WSAGetLastError());
while(1);
};
memset (&btconn, 0, sizeof(btconn));
btconn.addressFamily = AF_BTH;
btconn.port = BT_PORT_ANY;
btclientsize = sizeof(btclient);
server_socket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if(server_socket == INVALID_SOCKET){
rError = WSAGetLastError();
printf("socket error: %d", rError);
while(1);
}
...
Is there anyone who can help solve this?
Thanks!