FIX: TOS Bits Cannot Be Set for Unconnected Sockets

ID: Q196358

The information in this article applies to:

SYMPTOMS

Type-of-Service (TOS) bits on the header portion of IP packets cannot be set for unconnected User Datagram Protocol (UDP) sockets. Unconnected UDP sockets are Windows sockets of type SOCK_DGRAM in the address family AF_INET which do not use the connect/WSAConnect API to establish a default destination address for the send/WSASend and recv/WSARecv API calls.

RESOLUTION

To specify TOS values for UDP sockets, use connected UDP sockets or apply the fix provided in the MORE INFORMATION section of this article. To use connected UDP sockets, use the Winsock connect/WSAConnect API call where the operation performed by connect establishes a default destination address that can be used on subsequent send/WSASend and recv/WSARecv calls.

STATUS

Microsoft has confirmed this to be a problem in Windows NT version 4.0 and Windows NT 4.0 with Service Packs 1, 2, and 3. This problem was corrected in Microsoft Windows NT 4.0 Service Pack 4. To obtain the latest Windows NT 4.0 service pack, please see the following article in the Microsoft Knowledge Base.

   ARTICLE-ID: Q152734
   TITLE     : How to Obtain the Latest Windows NT 4.0 Service Pack

MORE INFORMATION

The Type-of-Service field in an IP packet is an 8-bit field that is composed of three precedence bits, four TOS bits, and an unused bit that must be 0. The four TOS bits represent network services such as minimize delay, maximize throughput, maximize reliability, and minimize monetary cost. Only one of these four bits can be turned on at a time. If all four bits are 0, it implies normal service. RFC 1340 further describes how standard applications should set these bits.

You can also modify the following key in the Registry Editor to change the TOS value set in the header of outgoing IP packets:

   HKEY_LOCAL_MACHIE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ 
   Value Name: DefaultTOS
   Value Type: REG_DWORD
   Valid Range: 0x00, 0x02, 0x04, 0x08, 0x10

The following code fragment demonstrates how to programmatically set TOS bits using the TCP/IP socket option IP_TOS:

   int tos, tos_len;
   tos_len = sizeof(tos);

   if (getsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&tos,
                  &tos_len) == SOCKET_ERROR)
       printf("\nWarning: TCPIP stack does not support the "
              "IP_TOS option - %d\n", WSAGetLastError());

   if (setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&tos,
                  tos_len) == SOCKET_ERROR)
      printf("\nWarning: Fail to set TOS value: error - %d",
             WSAGetLastError());

Keywords          : kbIP kbNTOS400bug kbWinsock kbNTOS400sp1bug kbNTOS400sp2bug kbNTOS400sp3bug kbNTOS400sp4fix 
Version           : WINDOWS:4.0
Platform          : WINDOWS
Issue type        : kbbug
Solution Type     : kbfix

Last Reviewed: December 2, 1998