title: UDP buffer overflow w/o filling the receive buffer?
body: <p>If I send 1000 "Hello World!" UDP messages (12 bytes + 28 IP/UDP overhead), I observe that on the receiving side I only buffer 658 (always the same number, 658*40 = 26320 bytes). I do that, by sending the UDP messages while sleeping on the server (after creating the socket).</p>
  
  <p>Curiously the SO_RCVBUF option on the server is 42080 bytes. So, I wonder why I can not buffer the 1000 messages. Do you know where are spend the remaining 15760 bytes?</p>
  
  <p>Below the server code (where distrib.h contains basic error handling wrappers of the socket and signal handling functions):</p>
  
  <pre><code>#include "distrib.h"
  
  static int count;
  static void sigint_handler(int s) {
    printf("\n%d UDP messages received\n",count);
    exit(0);
  }
  
  int main(int argc, char **argv) 
  {
    struct addrinfo* serverinfo;
    struct addrinfo hints;
    struct sockaddr_storage sender;
    socklen_t len;
    int listenfd,n;
    char buf[MAXLINE+1];
  
    if (argc != 2) {
      log_error("usage: %s &lt;port&gt;\n", argv[0]);
      exit(1);
    }
  
    Signal(SIGINT,sigint_handler);
  
    bzero(&amp;hints,sizeof(hints));
    hints.ai_family = AF_INET;    
    hints.ai_socktype = SOCK_DGRAM; 
    hints.ai_protocol = IPPROTO_UDP;
    Getaddrinfo("127.0.0.1", argv[1], &amp;hints, &amp;serverinfo);
  
    listenfd = Socket(serverinfo-&gt;ai_family, serverinfo-&gt;ai_socktype, 
              serverinfo-&gt;ai_protocol);
    Bind(listenfd, serverinfo-&gt;ai_addr,serverinfo-&gt;ai_addrlen);
    freeaddrinfo(serverinfo);
  
    count =0;
    sleep(20); 
    while(true) {
      bzero(buf,sizeof(buf));
      len = sizeof(sender);
      n = Recvfrom(listenfd, buf, MAXLINE, 0, (struct sockaddr*)&amp;sender,&amp;len);
      buf[n]='\0';
      count++;
  
    }
  
    close(listenfd);
  
    return 0;
  }
  </code></pre>