Bluetooth socket bind() returns WSAENETDOWN

Posted on 2006-04-09
Last Modified: 2013-12-14

Hello there,
      This is the first time I'm probramming for bluetooth.
I installed a USB bluetooth device and the software comes with it works great, detecting other devices and communicates.

I'm trying to run my application in server mode (using WSASetService).
But it fails at bind() with WSANETDOWN. Any idea how to troubleshoot this ??

 DWORD lastError = ::WSAGetLastError();
     printf("Failed to get bluetooth socket! %s\n", GetLastErrorMessage(lastError));

 memset(&sbth, 0, sizeof(sbth));
 sbth.addressFamily = AF_BTH;
 sbth.btAddr = 0;
 sbth.port = BT_PORT_ANY;

 if (bind(s, (const sockaddr*)&sbth, sizeof(SOCKADDR_BTH)) == SOCKET_ERROR) {  // <<------ here is the problem
     lastError = ::WSAGetLastError(); // always WSANETDOWN
     printf("Failed to bind bluetooth socket! %s\n", GetLastErrorMessage(lastError));
Question by:mxjijo
    LVL 6

    Expert Comment

    Does your USB installed as Microsoft Bluetooth Stack ?!
    Or others, such as Widcomm stack?

    What is the stack? : Bluetooth is written standard by BluetoothSIG. Different companies, orgnaization and individuals have their own API's of Bluetooth by implementing the lower-part of software of Bluetooth acoording to the written standard. To program a Bluetooth application, you have to use the Bluetooth Stack that dongle are installed to. Usually, USB-Dongles can be configured to work in any stack.
    So, using Bluetooth lib of Microsoft means your device is installed to use Microsoft BT Stack

    How to know?
    Simpliest way is to use run this application (comes with XP SP2)
    Choose next, send file, then click on browse,
    If the search took less than a second or two, it's not installed on microsoft BT stack! try to update driver and let microsoft windows choose the driver.
    if it took more than 10 seconds , it's MS BT Stack and the problem because of other problem!

    LVL 8

    Author Comment


       I must have updated the posting earlier.
    I found the problem myself. It was caused by the software came with it.,
    I don't have time to invesigate what is wrong with it, but once I uninstalled
    the software and  let XP auto detect the h/w my program started working.
    I tried reporting the problem to the manufacturer but they never responded.

    thanks for spending time on it
    LVL 6

    Expert Comment

    Well, Why you are tring to REPORT the problem? There is no problem!
    I mean, your are using a dongle comes with stack different than Microsoft and it's working!
    But miscrosoft API's works ONLY for devices/dongles installed with Microsoft stack!
    So, It's like you try to use Windows API's on Linux!
    I hope you understand my point! and don't bother the manufacture :)

    LVL 8

    Author Comment



    As you can see my code above, I am not using any non-standard API's.
    FYI,  when a manufacturer install a network interface, no matter what their
    h/w is, it is their resposibility to make it compatible with standard socket API's.
    If what you're saying is correct, why should any network card OEM's release their own drivers ?? :)

    LVL 6

    Accepted Solution

    Try to understand me please:)

    Bluetooth is a standard, written in a PDF file (more than 1500 pages).
    Bluetooth has layers: Hardware layer (dongles and so), Low-Level software layer, High-Level software layer(profiles)
    The manufacture of the dongle implement the Hardware layer. Microsoft (for windows) and Widcomm(for windows) and FreeBT(for windows ) and dozens of other companies implemented the LowLevel layer of the Bluetooth and part of the HighLevel (some profiles).

    When you insert a dongle into your XP, and choose Widcomm as the Low-Level layer(e.g. installation CD), you don't call Microsoft Bluetooth Layer! Since it cannot find any associated dongle!
    Other side: Widcomm DOESN'T use sockets when dealing with dongles! So when you try to Assign a Socket, you got nothing!

    The above code is not Standard Bluetooth API's, It's Microsoft Bluetooth API's that uses sockets!

    For more information, try to look for the keywords: Bluetooth Stack .

    Have fun..


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Network it in WD Red

    There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

    MAC Filtering: MAC filtering is like handing a list of names to a doorman. If someone comes to the door and mentions a name, this name is checked by the doorman on his list and granted or denied access by this. This means that if someone menti…
    Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
    This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now