Transferred from: http://zhangjunxin520.blog.163.com/blog/static/305037032011721102857609/
In the IP header, there is a type-of-service field that describes the IP packet's
Priority and QoS options, use Ip_tos to set the value of the field: usesetsockopt Set the Ip_tos code as follows:unsigned char service_type = 0XE0 | Iptos_lowdelay | Iptos_reliability;if (
setsockopt (sock, sol_ip/*ipproto_ip*/, Ip_tos, (void *) &service_type, sizeof (Service_type))< 0) perror ("setsockopt (Ip_tos) failed:"); Use getsockopt to read the Ip_tos code as follows: int optval = 0;int Optlen = sizeof (optval); if (
getsockopt (sock, Sol_ip, Ip_tos, (void *) &optval, &optlen)< 0) perror ("GetSockOpt (Ip_tos) failed:"), Else printf ("optval=%x.\n", OPTVAL) after socket set Ip_tos, Wireshark Grab the data sent on the socket, and look at the IP header to see the set value. Manual Ip_tos, so_priority Description:
ip_tos:
sol_ip/ipproto_ip (BSD); Ip_tos Set or receive the Type-of-service (TOS) field That's sent with every IP packet originating from the this socket. It's used to prioritize packetsOn the network. TOS is a byte. There is some standard TOS the flags defined:Iptos_lowdelay to minimize delays for interactive traffic, iptos_throughput tooptimize throughput, iptos_reliability to optimize for reliability, Iptos_mincostshould is used for "filler data" where slow transmission doesn ' t matter. at the most one of theseTOS values can be specified. Other bits is invalid and shall be cleared. Linux sendsiptos_lowdelay datagrams First by default and the exact behaviour depends on theconfigured queueing discipline. Some levels may require Superuserprivileges (the cap_net_admin capability). The priority can also is set in a protocolIndependent-by-the (Sol_socket, so_priority) socket option (see socket (7)).
so_priority:
Sol_socket; So_priority Set The protocol-defined priority for all packets to is sent on this socket. Linux uses this value to order the networking queues:packets with a higher priority may be processed FIR St Depending on the selected device queueing discipline. for IPs (7), this also sets the IP type-of-service (TOS) field for outgoing packets. Setting a priority outside the range 0 to 6 requires the cap_net_admin capability.
Set socket Ip_tos option (reprint)