Setting ToS/Diffserv byte?

This is a discussion on Setting ToS/Diffserv byte? within the C# Programming forums, part of the General Programming Boards category; I found some sample code on setting the ToS byte of an IP packet that you are sending out in ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    126

    Setting ToS/Diffserv byte?

    I found some sample code on setting the ToS byte of an IP packet that you are sending out in C#, but can't seem to get it to work. What I have is very simple:

    Code:
    public static void Main(string[] args)
            {
                Console.WriteLine("Testing DSCP packet marking.Wireshark should already be running!\n");
    
                UdpClient cli = new UdpClient();
                //TcpClient cli = new TcpClient();
                cli.Client.SetSocketOption(SocketOptionLevel.IP,
                                           SocketOptionName.TypeOfService, 136);
    
                byte[] buf = new byte[16];
    
                //I fill buff here            
                
                cli.Connect("192.168.4.100", 10100);
                cli.Send(buf, buf.Length);
                /*NetworkStream mystream = cli.GetStream();
                if (mystream != null)
                {
                    mystream.Write(buf, 0, buf.Length);
                }
                if(cli.Connected)
                    cli.Close();*/
            }
    As you can see, I've tried this with both TCP and UDP. But when I view the traffic that gets sent out in wireshark, the diffserve byte is always 0. I can see that the payload is filled with what I set buf too, so I know I'm looking at my packet. Am I missing something?

  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,602
    have you tried to capture the same packet on the receivers side?
    To be or not to be == true

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    126
    Yes. According to Wireshark, it's still 0.

  4. #4
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,602
    I have tested your code...
    send packet from comp 192.168.2.8 to 192.168.2.10

    wireshark on 192.168.2.8 shows (as I have suspected) 0 in the DSF field both when SetSockOption is called and not...

    but on the 192.168.2.10 it is changed from 0 to 0x88 as it should be...

    (Sender compiled on Ubuntu using monodevelop)

    So the code has no problems - do your testing again... If it still failes - Sunday I can test the sender code on Windows XP

    BTW - using ping with -v switch on widows or -Q switch on ubuntu to set teh TOS does nothing for me...
    To be or not to be == true

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    126
    I didn't realize Ubuntu could run .NET code. But I'm sending from Windows 7 with no luck.

  6. #6
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,602
    Quote Originally Posted by homer_3 View Post
    I didn't realize Ubuntu could run .NET code. But I'm sending from Windows 7 with no luck.
    could be some shortcomings of Win7 - have you tried to run your program in XP mode?
    To be or not to be == true

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 04:19 AM
  4. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 04:46 PM
  5. sorting a structure of arrays
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 03-15-2002, 10:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21