title: How to set message priority using TOS?
body: <p>The IP header has type of service (TOS) field. It can be used to set for Classful Queueing Disciplines, i.e. PRIO. </p>
  
  <p>I have tested the following codes.</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char**argv)
  {
     int listenfd, connfd, optval;
     struct sockaddr_in servaddr, cliaddr;
     socklen_t clilen;
     pid_t     childpid;
     char      mesg[16];
  
     listenfd = socket(AF_INET, SOCK_STREAM, 0);
  
     bzero(&amp;servaddr, sizeof(servaddr));
     bzero(mesg, 0, sizeof(mesg));
     servaddr.sin_family = AF_INET;
     servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
     servaddr.sin_port = htons(32000);
     bind(listenfd,(struct sockaddr *)&amp;servaddr, sizeof(servaddr));
  
     listen(listenfd, 1024);
  
     for (;;)
     {
        clilen = sizeof(cliaddr);
        connfd = accept(listenfd, (struct sockaddr *)&amp;cliaddr, &amp;clilen);
  
        if ((childpid = fork()) == 0)
        {
           close(listenfd);
  
           for (;;)
           {
              optval = 0x28;
              setsockopt(cliaddr, IPPROTO_IP, IP_TOS, &amp;optval, sizeof(optval));
              strcpy(mesg, "tos=0x28");
              sendto(connfd, mesg, sizeof(mesg), 0, (struct sockaddr *)&amp;cliaddr, sizeof(cliaddr));
              sleep(2);
  
              optval = 0x58;
              strcpy(mesg, "tos=0x58");
              setsockopt(cliaddr, IPPROTO_IP, IP_TOS, &amp;optval, sizeof(optval));
              sendto(connfd, mesg, sizeof(mesg), 0, (struct sockaddr *)&amp;cliaddr, sizeof(cliaddr));
              sleep(2);
           }
  
        }
  
        close(connfd);
     }
  }
  </code></pre>
  
  <p>The packets can be sent with TOS field set successfully. But what shall I do to make message priority take effect? Thanks!</p>