title: Invalid argument from sendto in ansi C when trying to implement UDP
body: <p>I know there are a few similar question on SO, but I feel like everyone has a different issue that is causing this. So I'm posting my particular case.</p>
  
  <p>I'm working on the raspberry pi, using raspbian, a debian derivative. I'm coding in ansi C. This is a server that sends some data to a udp client on another end through port 500.</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;stdio.h&gt;
  int main()
  {
     int sockfd;
     struct sockaddr_in servaddr,cliaddr;
     socklen_t clilen;
     char buffer[256];
  
     sockfd=socket(AF_INET,SOCK_DGRAM,0);
  
     bzero(&amp;servaddr,sizeof(servaddr));
     servaddr.sin_family = AF_INET;
     servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
     servaddr.sin_port=htons(500);
     bind(sockfd,(struct sockaddr *)&amp;servaddr,sizeof(servaddr));
     sprintf(buffer,"hi this is a test \n");
     if(sendto(sockfd,buffer,sizeof(buffer),0,(struct sockaddr *)&amp;cliaddr,sizeof(cliaddr))==-1)
     { error("fail:")
      };
  
     return 0;
  }
  </code></pre>
  
  <p>But this just gives me the error "invalid arguments", I can't figure out what could possibly be wrong. If the type of argument I supply to sendto is incorrect, this would fail on compile. But the type is correct and this compiles, only at runtime does it fail.</p>