Thread: Setting ToS/Diffserv byte?

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

    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    have you tried to capture the same packet on the receivers side?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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, 05:19 AM
  4. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM
  5. sorting a structure of arrays
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 03-15-2002, 11:45 AM