Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Windows Socket Error 10013

All of a sudden, my PC has stopped letting me bind to sockets. It was working last night, and when I went to test a feature after a few hours of coding, nothing would bind.

Other facts:

  • The same code works on my other PCs, so it's clearly something unique to my main dev machine.
  • A bind to TCP port 8080 (the app has a mini-HTTP server) does work.
  • Other applications I've written that listen to the same 63000-range ports also fail on this computer.

Here's some code that is failing:

  err = WSAStartup(wVersionRequested, &wsaData);
  if(err == 0)
  {
    aSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(aSocket != INVALID_SOCKET)
    {
      SOCKADDR_IN        ReceiverAddr;
      // The IPv4 family
      ReceiverAddr.sin_family = AF_INET;
      // Port no. 63939
      ReceiverAddr.sin_port = htons(iPort);
      // From all interface (0.0.0.0)
      ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
      err = bind(aSocket, (SOCKADDR*)&ReceiverAddr, sizeof(ReceiverAddr));
      if(err == 0)
      {

I have tried:

  • Disabling my Windows firewall (as suggested as the common fix)
  • Disabling Windows Defender
  • Running the app as administrator
  • Rebooting
  • Disabling/enabling my network drivers
  • Renaming the app in question (in case the firewall was set to ban)
  • Reverting to a known-good version of the app
  • Trying some other known-good networking applications I've written (they also fail with 10013)
  • Trying different ports in the same area
  • Changing my network type from "public" to "home"

If I run netstat, there are no other applications using the ports I'm trying to listen on (generally TCP and UDP ports in and around the 63000 area). Doing another quick netstat check, the highest local port currently bound is 53843.

Pretty sure the only app I installed last night was Kerbal Space Program, which I can't imagine has broken my net drivers.

like image 237
ArtHare Avatar asked Oct 22 '22 07:10

ArtHare


1 Answers

Answer edit: My new theory is NetBalancer, as I just uninstalled it, would have installed it around the time I started having trouble, and have had 2 days of 10013-free development since then. Since I assume it ties its hooks fairly deep into the net stack, it makes sense too.

Will keep updating this if they come back...

like image 188
ArtHare Avatar answered Oct 30 '22 00:10

ArtHare