rjsousa has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I need to set my datagrams to a certain value in th DSCP field(IP Precedence/IP TOS).
Unfortunatly, using somthing like: setsockopt($socket, Socket::SOL_IP...
doesn't seem to work.
Am I missing something obvious or is my Socket.pm missing it?
Regards

Replies are listed 'Best First'.
Re: Setting IP Precedence(TOS) on UDP traffic
by rob_au (Abbot) on Jan 06, 2003 at 14:11 UTC
    To do this you will need to construct the packet manually - The XS portion of the Socket module does not define the SO_PRIORITY macro which is used to set the protocol-defined priority for packets sent on a socket.

    The existing modules NetPacket and Net::RawIP may be of use in constructing UDP packets - Alternatively, an example of UDP packet construction from raw values using the pack function can be found in the Net::DHCPClient module.

     

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

Re: Setting IP Precedence(TOS) on UDP traffic
by pg (Canon) on Jan 06, 2003 at 15:51 UTC
    At the same time, you may want to look into Net::Pcap.

    Pcap is a widely used c library for low level packet capture, and it is system independent.

    This can help you to deal with inbound packets in your application.
      I quite like the pcap library, and in turn the Net::Pcap module. I thus thought it pertinent to add that Net::RawIP also incorporates an interface to pcap, specifically Net::RawIP::libpcap - This interface provides all the same functions as Net::Pcap and provides a capture mechanism to pair with Net::RawIP's packet building methods.

       

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