title: setsockopt fails for IPPROTO_TCP IP_TOS in C
body: <p>My code fails. I am running as root (same behavior as normal user)</p>
  
  <p>First I want to set the TOS and then get the value. </p>
  
  <pre><code>int tos_local = 0x28;
  if (setsockopt(sockfd, IPPROTO_TCP, IP_TOS,  &amp;tos_local, sizeof(tos_local))) {
      error("error at socket option");
  } else {
      int tos=0;
      int toslen=0;
  
      if (getsockopt(sockfd, IPPROTO_TCP, IP_TOS,  &amp;tos, &amp;toslen) &lt; 0) {
              error("error to get option");
      }else {
              printf ("changing tos opt = %d\n",tos);
      }
  }
  </code></pre>
  
  <p>the printf prints </p>
  
  <blockquote>
    <p>changing tos opt = 0</p>
  </blockquote>
  
  <p>I would expect to print 0x28 (40).</p>
  
  <p>What is the problem?</p>
  
  <p>The correct answer:</p>
  
  <pre><code>    if (setsockopt(sockfd, **IPPROTO_IP**, IP_TOS,  &amp;tos_local, sizeof(tos_local))) {
  
      int tos=0;
      int toslen=sizeof(tos); //that line here
  
      if (getsockopt(sockfd, IPPROTO_IP, IP_TOS,  &amp;tos, &amp;toslen) &lt; 0) {
  </code></pre>