title: send_to returns EINVAL in udp
body: <p>I am creating a simple file transfer application, but send_to is returning EINVAL when i am trying to send from server side to client, while both send_to and recv_from are working fine on the client side.
  port_number, portno, hostname are passed as arguments.</p>
  
  <p>Code to set up server:</p>
  
  <pre><code>portno=port_number;
  
      sockfd = socket(AF_INET, SOCK_DGRAM, 0);
      if (sockfd &lt; 0)
        error("ERROR opening socket");
  
  
      optval = 1;
  
      setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
           (const void *)&amp;optval , sizeof(int));
  
  
      bzero((char *) &amp;serveraddr, sizeof(serveraddr));
      serveraddr.sin_family = AF_INET;
      serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
      serveraddr.sin_port = htons((unsigned short)portno);
  
  
      if (bind(sockfd, (struct sockaddr *) &amp;serveraddr,
         sizeof(serveraddr)) &lt; 0)
        error("ERROR on binding");
        //getsockname(sockfd, (struct sockaddr *)&amp;clientaddr, &amp;clientlen);
        cout&lt;&lt;"server port no"&lt;&lt;serveraddr.sin_port&lt;&lt;endl;
      clientlen = sizeof(clientaddr);
  </code></pre>
  
  <p>Code to set up client:
      hostname = name;
      portno = port;</p>
  
  <pre><code>/* socket: create the socket */
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd &lt; 0)
   error("ERROR opening socket");
  
  
  
  /* gethostbyname: get the server's DNS entry */
  server = gethostbyname(hostname);
  if (server == NULL)
  {
    fprintf(stderr,"ERROR, no such host as %s\n", hostname);
    exit(-1);
  }
  
  /* build the server's Internet address */
  memset((char *) &amp;serveraddr,0, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server-&gt;h_addr,
  (char *)&amp;serveraddr.sin_addr.s_addr, server-&gt;h_length);
  serveraddr.sin_port = htons(portno);
  serverlen = sizeof(serveraddr);
  struct timeval tv;
  
  tv.tv_sec = 1;                       // TIMEOUT IN SECONDS
  tv.tv_usec = 0;                      // DEFAULT
  if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &amp;tv, sizeof(tv)) &lt; 0)
    printf("Cannot Set SO_RCVTIMEO for socket\n");
  </code></pre>
  
  <p>Command that is failing:</p>
  
  <pre><code>  if(sendto (sockfd, ack, strlen(ack), 0,(struct sockaddr*) 
    &amp;clientaddr,sizeof(clientaddr) &lt; 0)
         error("ERROR in sending hello_ACK");
  </code></pre>
  
  <p>where clientadddr is declared  as struct sockaddr_in</p>