Thread: Socket Function - Error 10047

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    3

    Socket Function - Error 10047

    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!

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    It could be due to your WSAStartup() call. You are requesting version 1 of the winsock protocol, but bluetooth is in version 2. Try changing the call to:
    Code:
    if(WSAStartup(MAKEWORD(2,2), &wsd) != 0){

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    Thanks,

    I made the change, but I'm still getting the same error.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Hmm... I can't really help you then. A quick search on the internet seems to indicate that error means there is an issue with the SDK working with your hardware.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Maybe the socket type can't be streaming, try SOCK_DGRAM and report back if it complains no error.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Maybe the socket type can't be streaming, try SOCK_DGRAM and report back if it complains no error.
    The documentation says:
    To create a Bluetooth socket, use: type = SOCK_STREAM

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    I still get the same error using SOCK_DGRAM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM