title: WriteFile with Windows Sockets returns invalid parameter error
body: <p>I've been struggling with Windows Sockets for two days not being able to just use write to socket as in Linux it is. I want to write my own shellcode and I'm playing around how to redirect stdout, stdin to socket handle (that's where my playings come from). I use Windows 7 x64, build 7601 if it's necessary. Here's my code</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  int main (int argc,char ** argv)
  {   
      // boring code starts
      if (argc &lt; 2)
      {
          printf("Usage getstdhandle &lt;ip&gt; &lt;port&gt; ");
      }
  
      WSADATA wsadata;
      int result = WSAStartup (MAKEWORD(2,2),&amp;wsadata);
      if (result != NO_ERROR)
      {
          printf("error with wsastartup");
      }
  
      struct sockaddr_in server;
      server.sin_family = AF_INET;
      server.sin_port = htons (atoi(argv[2]));
      server.sin_addr.s_addr = inet_addr (argv[1]);
  
      SOCKET soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
      if (soc == INVALID_SOCKET)
      {
          printf("Error with creating socket");
      }
  
      if (connect(soc,(struct sockaddr *)&amp;server,sizeof(server)) == SOCKET_ERROR)
      {
          printf("Problem with connecting");
      }
  
       // boring code ends
  
      const char * buf = "Tekscik \n"; // know it's not really good in new C standards
      const char buf[] = "Test\n";  // not working also, shouldn't have any influence
  
      bool isSent = WriteFile((HANDLE)soc,(LPCVOID)buf,(DWORD)10,NULL,NULL);
      DWORD ret = GetLastError();
      printf("%.08x",ret);
  
      closesocket(soc);
      WSACleanup();
      return 0;
  }
  </code></pre>
  
  <p>This is how i run my program</p>
  
  <pre><code>C:\Users\Domin568\Desktop&gt;getstdhandle 192.168.56.1 5555
  Tekscik
  00000057     &lt;---- Error code in hex
  </code></pre>
  
  <p>On my second machine i just run nc to listen for this data like this :</p>
  
  <pre><code>15:14|domin568[21] ~ $ nc -l -v -p 5555
  Connection from 192.168.56.101:50328
  15:15|domin568[22] ~ $ 
  </code></pre>
  
  <p>I get error code 0x57 which is :</p>
  
  <blockquote>
    <p>ERROR_INVALID_PARAMETER 87 (0x57)  The parameter is incorrect.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/IavL4.png" rel="nofollow noreferrer">Local network traffic</a> (any data sent, pure connections handshakes and FIN)</p>
  
  <p>What could be the reason of that ? I know it's not good way for sending data but MSDN says it should be possible. </p>