title: Windows socket error 10013
body: <p>Here is the code of program, which should send a simple 'ping'. I know that i could use <code>IcmpSendEcho2()</code> function, but i decide to do this this way:<br/></p>
  
  <pre><code>struct ICMPh
  {
  unsigned char typ;
  unsigned char kod;
  unsigned short suma_spr;
  unsigned short id;
  unsigned short seq;
  };
  unsigned short CalcChecksum (char *pBuffer, int nLen)
   { 
    ////Checksum for ICMP is calculated in the same way as for IP header
    //This code was taken from: http://www.netfor2.com/ipsum.htm
  
    unsigned short nWord;
    unsigned int nSum = 0;
    int i;
  
  
    for (i = 0; i &lt; nLen; i = i + 2)
    {
        nWord =((pBuffer [i] &lt;&lt; 8)&amp; 0xFF00) + (pBuffer [i + 1] &amp; 0xFF);
        nSum = nSum + (unsigned int)nWord;  
    }
  
  
   while (nSum &gt;&gt; 16)
    {
        nSum = (nSum &amp; 0xFFFF) + (nSum &gt;&gt; 16);
    }
  
    //One's complement the result
    nSum = ~nSum;
  
    return ((unsigned short) nSum);
   }
  int _tmain(int argc, _TCHAR* argv[])
  {
  WSADATA wsaData;
  if(WSAStartup(MAKEWORD(2,2),&amp;wsaData)==SOCKET_ERROR)
  {
      cout&lt;&lt;"ERROR at startup:\n";
      cout&lt;&lt;WSAGetLastError()&lt;&lt;"\n";
      system("pause");
      WSACleanup();
      return -1;
  }
  SOCKET soc;
  int seq=0;
  
  soc=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
  if(soc==INVALID_SOCKET)
  {
      cout&lt;&lt;"ERROR: INVALID SOCKET\n";
      cout&lt;&lt;WSAGetLastError()&lt;&lt;"\n";
      system("pause");
      WSACleanup();
      return -1;
  }
  char* addres=new char;
  cin&gt;&gt;addres;
  
  SOCKADDR_IN adr;
  adr.sin_addr.S_un.S_addr=inet_addr(addres);
  adr.sin_family=AF_INET;
  adr.sin_port=rand();
  
  ICMPh icmp;
  icmp.kod=0;
  icmp.seq=htons(seq++);
  icmp.typ=8;
  icmp.suma_spr=0;
  icmp.id=htons(rand());
  
  int size=32;
  char *buffer;
  
  buffer=new char[sizeof(ICMPh)+size];
  memcpy_s(buffer,sizeof(ICMPh),&amp;icmp,sizeof(ICMPh));
  memset(buffer+sizeof(ICMPh),'x',size);
  
  icmp.suma_spr=htons(CalcChecksum(buffer,sizeof(ICMPh)+size));
  
  memcpy_s(buffer,sizeof(ICMPh),&amp;icmp,sizeof(ICMPh));
  
  if(sendto(soc,buffer,sizeof(ICMPh)+size,0,(SOCKADDR*)&amp;adr,sizeof(SOCKADDR_IN))==SOCKET_ERROR)
  {
      cout&lt;&lt;"FAIL at 'sendto':\n";
      cout&lt;&lt;WSAGetLastError()&lt;&lt;"\n";
      system("pause");
      WSACleanup();
      delete []buffer;
      return -1;
  }
  else
      cout&lt;&lt;"FINE";
  WSACleanup();
  system("pause");
  delete []buffer;
  return 0;
  } 
  </code></pre>
  
  <p>And here is the problem. Everything is working fine untill it comes to <code>sendto()</code> function. I get an 10013 Error code form <code>WSAGetLastError()</code> which means <code>WSAEACCES Permission denied</code><br/>
  I start this application witch admin privliges, so i have no idea why i cant send data using this socket configuration.</p>