title: C Socket programming on windows errors on listen but no errno
body: <p>I've done socket programming in other languages but never dealt with doing it in C directly. I'm trying to set up a simple server to listen on port 8080 under Windows. I'm using the gcc that comes with mingw to compile the code.</p>
  
  <pre>
  <code>
  
      #include &lt;stdio.h>
      #include &lt;string.h>
      #include &lt;WinSock2.h>
      #include &lt;stdint.h>
      #include &lt;time.h>
  
          int main(void) {
  
          int s;      
          int len;
          char  buffer[1025];  
          struct sockaddr_in servAddr; 
          struct sockaddr_in clntAddr; 
  
          int clntAddrLen; //length of client socket addre
  
      //Build local (server) socket add
  
          memset(&servAddr, 0, sizeof(servAddr));
          servAddr.sin_family = AF_INET;
          servAddr.sin_port = htons(8080);
          servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  
         //create socket
          if((s=socket(AF_INET, SOCK_STREAM, 0) %lt; 0 )){
              perror("Error: Socket Failed!");
                  printf("%d\n", errno);
              exit(1);
          }
  
      //bind socket to local address and port
          if((bind(s,(struct sockaddr*)&servAddr, sizeof(servAddr)) %lt; 0))
          {
              perror("Error:bind failed!");
                  printf("%d\n", errno);
              exit(1);
          }
  
          for(;;)
          {
              len = recvfrom(s,buffer, sizeof(buffer),0,(struct sockaddr*)&clntAddr, &clntAddrLen);
  
              //send string
              sendto(s, buffer, len, 0, (struct sockaddr*)&clntAddr, sizeof(clntAddr));
          }
  
      }
  
  </code>
  </pre>
  
  <p>When I run the code it errors out binding but there's no error. This code was taken and slightly modified from this thread: <a href="https://stackoverflow.com/questions/6769981/windows-socket-programming-in-c">Windows Socket Programming in C</a></p>
  
  <p>But there's no error code. The output prints that there's no error. It fails at the bind and I'm not sure why. I've been piecing together a few different sources. I literally just want something that can do a hello world/3 way handshake in C on Windows.</p>
  
  <p>Thanks in advance.</p>