Search code examples
c++windows-7udpsdl

Why can't my application receive UDP packets when the Windows Base Filtering Engine service is enabled?


Before starting, I just want to say that this situation works perfectly using TCP, without any problems - the issue is that I want to auto-detect devices on my network however, so I still need UDP to broadcast and detect devices over my network.

I have a simple UDP broadcast/send/receive program running on my laptop and desktop, using UDP and SDL_Net, coded in C++. My desktop is running Linux, while my laptop is running Windows. The Linux machine can receive all UDP packets, while the Windows machine drops them. I installed Wireshark, and the machine does receive the packets - they just never make it to my application :(

After much deliberation, I narrowed the problem down to the Base Filtering Engine service, which when disabled, my program works perfectly! All UDP packets (broadcast or directed) are received across both machines when the service is disabled. While this is fine for testing purposes, it makes me wonder if my application will even work with client machines with the BFE enabled (which I'm betting 90% of Windows computers have enabled).

Is there an alternative cross-platform network stack that I can use to mitigate this issue? Is there any easy solution to "register" my application with the base filtering engine?


Solution

  • Are you listening for responses on the same port that you sent the query upon? Are the machines responding to your broadcast query are sending their responses to the same source address and port number that they received it from?

    Usually the firewall will automatically allow you to receive data on whatever port you sent data on, although I'm not sure how well this works for broadcast.

    Also keep in mind that when you first run an EXE under Vista or 7, you may be asked whether or not you want to allow that program to communicate on the network. If you answer anything other than "Allow" (including just closing the dialog), then that EXE or any other EXE which uses the same path name will be permanently blocked.

    Although you mention that the firewall was somehow "removed", that is evidently not true since BFE is still there: Base Filtering Engine is part of the Windows firewall. If some part of the firewall is missing, for example the part that asks whether to allow an EXE, then the automatic allow rules might not be working.

    Automatic rules aside, in order to receive incoming traffic, either you or your users will need to open the appropriate firewall port. If your program is run with administrative privileges, you can open the port programmatically, but its not easy and requires different APIs depending on whether you are running on XPSP2, Vista, or 7.

    Generally speaking, Windows since XPSP2 is always running a firewall (even if the user thinks they've disabled it) and the best practice is to inform the user of the need to open whatever ports need to be opened at installation time.

    But first make sure you are sending and receiving on the same UDP port and test on a fresh, unmodified Windows system.