in reply to Can IO::Socket get/set TOS/ECN ?

No, IO::Socket cannot set type-of-service (TOS) options as these are set at a lower level of the OSI stack (Network, Layer 3) - As already referenced by sauoq, the NetPacket modules can be used for the manual construction of such packets. In terms of delivery of such packets to the network, Net::Divert may be of use in this task.

In terms of receiving or capturing packets and retaining lower level information, the Net::Pcap module is exceptionally effective at this task - Using this module it is quite easy to manually pull packets about and examine their contents. There is an introductory tutorial which I wrote for this module on this site here and examples of usage at:

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001000000011"))'