FIX: TOS Bits Cannot Be Set for Unconnected Sockets (196358)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0, when used with:
    • the operating system: Microsoft Windows NT

This article was previously published under Q196358

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.

152734 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_MACHINE\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());
				

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbBug kbfix kbIP kbOSWinNT400sp4fix kbWinsock KB196358