views:

246

answers:

1

I'm writing an application to send data over a network, and need to know if it is possible to set the Type of Service (ToS) bits in the IP Packet header. Anyone know if this is supported by C#, and if so how I should go about implementing it?

I know I can use a raw socket type and specify my own header, but I'd rather not have to do this as I'm only using TCP, so it seems a bit pointless to create an entire header just so I can set three bits, when it can be automatically created without these bits set.

Any suggestions would be greatly appreciated.

+1  A: 

Wouldn't this work? (almost straight from TcpClient.Client help)

TcpClient client = new TcpClient();
Socket s = client.Client;

if (!s.Connected)
{
   s.SetSocketOption(SocketOptionLevel.IP, 
                     SocketOptionName.TypeOfService, 2);
}

Not sure what value you want to set it to, but this should work...

Moose
Thanks, this is exactly what I'm looking for. I'm not too sure on the value though. Some experimentation is needed I think!
Arducius
This doesn't work under XP and higher, see http://support.microsoft.com/kb/248611. The evil SetSocketOption returns without reporting any problem, but the TOS byte is not set.
r0u1i