title: Understanding set/getsockopt SO_SNDBUF size doubles
body: <p>Hi I have the following program to check the send buffer size for a UDP socket. However, I the return value is a bit confusing to me. I use the following simple app:</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(int argc, char **argv)
  {
   int sockfd, sendbuff;
   socklen_t optlen;
  
   sockfd = socket(AF_INET, SOCK_DGRAM, 0);
   if(sockfd == -1)
       printf("Error");
  
   int res = 0;
  
   // Get buffer size
   optlen = sizeof(sendbuff);
   res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &amp;sendbuff, &amp;optlen);
  
   if(res == -1)
       printf("Error getsockopt one");
   else
       printf("send buffer size = %d\n", sendbuff);
  
   // Set buffer size
   sendbuff = 98304;
  
   printf("sets the send buffer to %d\n", sendbuff);
   res = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &amp;sendbuff, sizeof(sendbuff));
  
   if(res == -1)
       printf("Error setsockopt");
  
  
   // Get buffer size
   optlen = sizeof(sendbuff);
   res = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &amp;sendbuff, &amp;optlen);
  
   if(res == -1)
       printf("Error getsockopt two");
   else
       printf("send buffer size = %d\n", sendbuff);
  
   return 0;
  }
  </code></pre>
  
  <p>The output on my machine is:</p>
  
  <p>send buffer size = 129024</p>
  
  <p>sets the send buffer to 98304</p>
  
  <p>new send buffer size = 196608</p>
  
  <p>Can anybody clarify what I'm doing wrong here or how to interpret the output?</p>