c++ – Boost.Asio IP Header how to set and read DSCP or TOS field

My application (coded in C++, using Boost.Asio lib, running on a LINUX machine) handles several UDP Multicast / IP sockets.

(#1) For the outbound traffic, I need to set the DSCP field of the IP Header (the 6 MSBits of the IPV4_TOS field). Moreover, the DSCP value to set is different for each socket (but remains constant for all packets emitted by a given socket).

(#2) Also, I put in place some UT using as well Boost.Asio, to check if my DSCP field are correctly set.

After some web digging (including Boost.Asio doc) and the “help” of ChatGPT, I conclude Boost.asio does not implement the option to set such (DSCP) option on a socket. So I had to use the root way with setsockopt() (from ) and native_handle() of the asio socket.

About (#2), it’s worst: you can’t use getsockopt() as it is not updated with each packed header received (it remains at the configured value). I had to either use recvmsg() (with all the raw struct and buffers and ptr … + MACROS) or recvfrom() but with a RAW socket (still from ).

Does anyone know another way to achieve this both topics using all way long Boost.asio? Or any smarter approach?

Read more here: Source link