libtins  4.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Tins::ICMP Class Reference

Class that represents an ICMP PDU. More...

#include <icmp.h>

Inheritance diagram for Tins::ICMP:
Tins::PDU

Public Types

enum  Flags {
  ECHO_REPLY = 0, DEST_UNREACHABLE = 3, SOURCE_QUENCH = 4, REDIRECT = 5,
  ECHO_REQUEST = 8, TIME_EXCEEDED = 11, PARAM_PROBLEM = 12, TIMESTAMP_REQUEST = 13,
  TIMESTAMP_REPLY = 14, INFO_REQUEST = 15, INFO_REPLY = 16, ADDRESS_MASK_REQUEST = 17,
  ADDRESS_MASK_REPLY = 18
}
 ICMP flags.
 
typedef IPv4Address address_type
 
- Public Types inherited from Tins::PDU
enum  endian_type { BE, LE }
 
enum  PDUType {
  RAW, ETHERNET_II, IEEE802_3, DOT3 = IEEE802_3,
  RADIOTAP, DOT11, DOT11_ACK, DOT11_ASSOC_REQ,
  DOT11_ASSOC_RESP, DOT11_AUTH, DOT11_BEACON, DOT11_BLOCK_ACK,
  DOT11_BLOCK_ACK_REQ, DOT11_CF_END, DOT11_DATA, DOT11_CONTROL,
  DOT11_DEAUTH, DOT11_DIASSOC, DOT11_END_CF_ACK, DOT11_MANAGEMENT,
  DOT11_PROBE_REQ, DOT11_PROBE_RESP, DOT11_PS_POLL, DOT11_REASSOC_REQ,
  DOT11_REASSOC_RESP, DOT11_RTS, DOT11_QOS_DATA, LLC,
  SNAP, IP, ARP, TCP,
  UDP, ICMP, BOOTP, DHCP,
  EAPOL, RC4EAPOL, RSNEAPOL, DNS,
  LOOPBACK, IPv6, ICMPv6, SLL,
  DHCPv6, DOT1Q, PPPOE, STP,
  PPI, IPSEC_AH, IPSEC_ESP, PKTAP,
  MPLS, UNKNOWN = 999, USER_DEFINED_PDU = 1000
}
 Enum which identifies each type of PDU. More...
 
typedef byte_array serialization_type
 

Public Member Functions

 ICMP (Flags flag=ECHO_REQUEST)
 Creates an instance of ICMP. More...
 
 ICMP (const uint8_t *buffer, uint32_t total_sz)
 Constructs an ICMP object from a buffer. More...
 
void code (uint8_t new_code)
 Sets the code field. More...
 
void type (Flags type)
 Sets the type field. More...
 
void id (uint16_t new_id)
 Setter for the id field. More...
 
void sequence (uint16_t new_seq)
 Setter for the sequence field. More...
 
void gateway (address_type new_gw)
 Setter for the gateway field. More...
 
void mtu (uint16_t new_mtu)
 Setter for the mtu field. More...
 
void pointer (uint8_t new_pointer)
 Setter for the pointer field. More...
 
void original_timestamp (uint32_t new_timestamp)
 Setter for the original timestamp field. More...
 
void receive_timestamp (uint32_t new_timestamp)
 Setter for the receive timestamp field. More...
 
void transmit_timestamp (uint32_t new_timestamp)
 Setter for the transmit timestamp field. More...
 
void address_mask (address_type new_mask)
 Setter for the address mask field. More...
 
void set_echo_request (uint16_t id, uint16_t seq)
 Sets echo request flag for this PDU. More...
 
void set_echo_reply (uint16_t id, uint16_t seq)
 Sets echo reply flag for this PDU. More...
 
void set_info_request (uint16_t id, uint16_t seq)
 Sets information request flag for this PDU. More...
 
void set_info_reply (uint16_t id, uint16_t seq)
 Sets information reply flag for this PDU. More...
 
void set_dest_unreachable ()
 Sets destination unreachable for this PDU.
 
void set_time_exceeded (bool ttl_exceeded=true)
 Sets time exceeded flag for this PDU. More...
 
void set_param_problem (bool set_pointer=false, uint8_t bad_octet=0)
 Sets parameter problem flag for this PDU. More...
 
void set_source_quench ()
 Sets source quench flag for this PDU.
 
void set_redirect (uint8_t icode, address_type address)
 Sets redirect flag for this PDU. More...
 
Flags type () const
 Getter for the ICMP type flag. More...
 
uint8_t code () const
 Getter for the ICMP code flag. More...
 
uint16_t checksum () const
 Getter for the checksum field. More...
 
uint16_t id () const
 Getter for the echo id. More...
 
uint16_t sequence () const
 Getter for the echo sequence number. More...
 
address_type gateway () const
 Getter for the gateway field. More...
 
uint8_t pointer () const
 Getter for the pointer field. More...
 
uint8_t length () const
 Getter for the length field. More...
 
uint16_t mtu () const
 Getter for the mtu field. More...
 
uint32_t original_timestamp () const
 Getter for the original timestamp field. More...
 
uint32_t receive_timestamp () const
 Getter for the receive timestamp field. More...
 
uint32_t transmit_timestamp () const
 Getter for the transmit timestamp field. More...
 
address_type address_mask () const
 Getter for the address mask field. More...
 
uint32_t header_size () const
 Returns the header size. More...
 
uint32_t trailer_size () const
 Returns the trailer size. More...
 
bool matches_response (const uint8_t *ptr, uint32_t total_sz) const
 Check whether ptr points to a valid response for this PDU. More...
 
const ICMPExtensionsStructureextensions () const
 Getter for the extensions field. More...
 
ICMPExtensionsStructureextensions ()
 Getter for the extensions field. More...
 
bool has_extensions () const
 Indicates whether this object contains ICMP extensions.
 
void use_length_field (bool value)
 Sets whether the length field will be set for packets that use it. More...
 
PDUType pdu_type () const
 Getter for the PDU's type. More...
 
ICMPclone () const
 
- Public Member Functions inherited from Tins::PDU
 PDU ()
 Default constructor.
 
 PDU (PDU &&rhs) TINS_NOEXCEPT
 Move constructor. More...
 
PDUoperator= (PDU &&rhs) TINS_NOEXCEPT
 Move assignment operator. More...
 
virtual ~PDU ()
 PDU destructor. More...
 
uint32_t size () const
 The whole chain of PDU's size, including this one. More...
 
PDUinner_pdu () const
 Getter for the inner PDU. More...
 
PDUparent_pdu () const
 
PDUrelease_inner_pdu ()
 Releases the inner PDU. More...
 
void inner_pdu (PDU *next_pdu)
 Sets the child PDU. More...
 
void inner_pdu (const PDU &next_pdu)
 Sets the child PDU. More...
 
serialization_type serialize ()
 Serializes the whole chain of PDU's, including this one. More...
 
template<typename T >
T * find_pdu (PDUType type=T::pdu_flag)
 Finds and returns the first PDU that matches the given flag. More...
 
template<typename T >
const T * find_pdu (PDUType type=T::pdu_flag) const
 Finds and returns the first PDU that matches the given flag. More...
 
template<typename T >
T & rfind_pdu (PDUType type=T::pdu_flag)
 Finds and returns the first PDU that matches the given flag. More...
 
template<typename T >
const T & rfind_pdu (PDUType type=T::pdu_flag) const
 Finds and returns the first PDU that matches the given flag. More...
 
virtual void send (PacketSender &sender, const NetworkInterface &iface)
 Send the stack of PDUs through a PacketSender. More...
 
virtual PDUrecv_response (PacketSender &sender, const NetworkInterface &iface)
 Receives a matching response for this packet. More...
 
virtual bool matches_flag (PDUType flag) const
 Check whether this PDU matches the specified flag. More...
 

Static Public Member Functions

static metadata extract_metadata (const uint8_t *buffer, uint32_t total_sz)
 Extracts metadata for this protocol based on the buffer provided. More...
 

Static Public Attributes

static const PDU::PDUType pdu_flag = PDU::ICMP
 This PDU's flag.
 
- Static Public Attributes inherited from Tins::PDU
static const endian_type endianness = BE
 

Additional Inherited Members

- Protected Member Functions inherited from Tins::PDU
 PDU (const PDU &other)
 Copy constructor.
 
PDUoperator= (const PDU &other)
 Copy assignment operator.
 
void copy_inner_pdu (const PDU &pdu)
 Copy other PDU's inner PDU(if any). More...
 
virtual void prepare_for_serialize ()
 Prepares this PDU for serialization. More...
 
void serialize (uint8_t *buffer, uint32_t total_sz)
 Serializes this PDU and propagates this action to child PDUs. More...
 

Detailed Description

Class that represents an ICMP PDU.

ICMP is the representation of the ICMP PDU. Instances of this class must be sent over a level 3 PDU, this will otherwise fail.

Member Typedef Documentation

The type used to store addresses.

Constructor & Destructor Documentation

Tins::ICMP::ICMP ( Flags  flag = ECHO_REQUEST)

Creates an instance of ICMP.

If no flag is specified, then ECHO_REQUEST will be used.

Parameters
flagThe type flag which will be set.
Tins::ICMP::ICMP ( const uint8_t *  buffer,
uint32_t  total_sz 
)

Constructs an ICMP object from a buffer.

If there is not enough size for an ICMP header, a malformed_packet exception is thrown.

Any extra data in the buffer will be stored in a RawPDU.

Parameters
bufferThe buffer from which this PDU will be constructed.
total_szThe total size of the buffer.

Member Function Documentation

void Tins::ICMP::address_mask ( address_type  new_mask)

Setter for the address mask field.

Parameters
new_maskthe value to be set.
address_type Tins::ICMP::address_mask ( ) const
inline

Getter for the address mask field.

Returns
Returns the address mask value.
uint16_t Tins::ICMP::checksum ( ) const
inline

Getter for the checksum field.

Returns
Returns the checksum as an unit16_t.
ICMP* Tins::ICMP::clone ( ) const
inlinevirtual
See also
PDU::clone

Implements Tins::PDU.

void Tins::ICMP::code ( uint8_t  new_code)

Sets the code field.

Parameters
new_codeThe code which will be stored in the ICMP struct.
uint8_t Tins::ICMP::code ( ) const
inline

Getter for the ICMP code flag.

Returns
The code flag for this ICMP PDU.
const ICMPExtensionsStructure& Tins::ICMP::extensions ( ) const
inline

Getter for the extensions field.

Returns
The extensions field
ICMPExtensionsStructure& Tins::ICMP::extensions ( )
inline

Getter for the extensions field.

Returns
The extensions field
PDU::metadata Tins::ICMP::extract_metadata ( const uint8_t *  buffer,
uint32_t  total_sz 
)
static

Extracts metadata for this protocol based on the buffer provided.

Parameters
bufferPointer to a buffer
total_szSize of the buffer pointed by buffer
void Tins::ICMP::gateway ( address_type  new_gw)

Setter for the gateway field.

Parameters
new_gwThe new value for the gateway field.
address_type Tins::ICMP::gateway ( ) const
inline

Getter for the gateway field.

Returns
Returns the gateway field value.
uint32_t Tins::ICMP::header_size ( ) const
virtual

Returns the header size.

This method overrides PDU::header_size. This size includes the payload and options size.

See also
PDU::header_size

Implements Tins::PDU.

void Tins::ICMP::id ( uint16_t  new_id)

Setter for the id field.

Parameters
new_iduint16_t with the new id.
uint16_t Tins::ICMP::id ( ) const
inline

Getter for the echo id.

Returns
Returns the echo id.
uint8_t Tins::ICMP::length ( ) const
inline

Getter for the length field.

Returns
Returns the length field value.
bool Tins::ICMP::matches_response ( const uint8_t *  ptr,
uint32_t  total_sz 
) const
virtual

Check whether ptr points to a valid response for this PDU.

See also
PDU::matches_response
Parameters
ptrThe pointer to the buffer.
total_szThe size of the buffer.

Reimplemented from Tins::PDU.

void Tins::ICMP::mtu ( uint16_t  new_mtu)

Setter for the mtu field.

Parameters
new_mtuuint16_t with the new sequence.
uint16_t Tins::ICMP::mtu ( ) const
inline

Getter for the mtu field.

Returns
Returns the mtu field value.
void Tins::ICMP::original_timestamp ( uint32_t  new_timestamp)

Setter for the original timestamp field.

Parameters
new_timestampthe value to be set.
uint32_t Tins::ICMP::original_timestamp ( ) const
inline

Getter for the original timestamp field.

Returns
Returns the original timestamp value.
PDUType Tins::ICMP::pdu_type ( ) const
inlinevirtual

Getter for the PDU's type.

See also
PDU::pdu_type

Implements Tins::PDU.

void Tins::ICMP::pointer ( uint8_t  new_pointer)

Setter for the pointer field.

Parameters
new_pointeruint8_t with the new pointer.
uint8_t Tins::ICMP::pointer ( ) const
inline

Getter for the pointer field.

Returns
Returns the pointer field value.
void Tins::ICMP::receive_timestamp ( uint32_t  new_timestamp)

Setter for the receive timestamp field.

Parameters
new_timestampthe value to be set.
uint32_t Tins::ICMP::receive_timestamp ( ) const
inline

Getter for the receive timestamp field.

Returns
Returns the receive timestamp value.
void Tins::ICMP::sequence ( uint16_t  new_seq)

Setter for the sequence field.

Parameters
new_sequint16_t with the new sequence.
uint16_t Tins::ICMP::sequence ( ) const
inline

Getter for the echo sequence number.

Returns
Returns the echo sequence number.
void Tins::ICMP::set_echo_reply ( uint16_t  id,
uint16_t  seq 
)

Sets echo reply flag for this PDU.

Parameters
idThe identifier for this request.
seqThe sequence number for this request.
void Tins::ICMP::set_echo_request ( uint16_t  id,
uint16_t  seq 
)

Sets echo request flag for this PDU.

Parameters
idThe identifier for this request.
seqThe sequence number for this request.
void Tins::ICMP::set_info_reply ( uint16_t  id,
uint16_t  seq 
)

Sets information reply flag for this PDU.

Parameters
idThe identifier for this request.
seqThe sequence number for this request.
void Tins::ICMP::set_info_request ( uint16_t  id,
uint16_t  seq 
)

Sets information request flag for this PDU.

Parameters
idThe identifier for this request.
seqThe sequence number for this request.
void Tins::ICMP::set_param_problem ( bool  set_pointer = false,
uint8_t  bad_octet = 0 
)

Sets parameter problem flag for this PDU.

Parameters
set_pointerIndicates whether a pointer to the bad octet is provided.
bad_octetIdentifies the octet in which the error was detected. If set_pointer == false, it is ignored.
void Tins::ICMP::set_redirect ( uint8_t  icode,
address_type  address 
)

Sets redirect flag for this PDU.

Parameters
icodeThe code to be set.
addressAddress of the gateway to which traffic should be sent.
void Tins::ICMP::set_time_exceeded ( bool  ttl_exceeded = true)

Sets time exceeded flag for this PDU.

Parameters
ttl_exceededIf true this PDU will represent a ICMP ttl exceeded, otherwise it will represent a fragment reassembly time exceeded.
uint32_t Tins::ICMP::trailer_size ( ) const
virtual

Returns the trailer size.

This method overrides PDU::trailer_size. This size will hold the extensions size

See also
PDU::header_size

Reimplemented from Tins::PDU.

void Tins::ICMP::transmit_timestamp ( uint32_t  new_timestamp)

Setter for the transmit timestamp field.

Parameters
new_timestampthe value to be set.
uint32_t Tins::ICMP::transmit_timestamp ( ) const
inline

Getter for the transmit timestamp field.

Returns
Returns the transmit timestamp value.
void Tins::ICMP::type ( Flags  type)

Sets the type field.

Parameters
typeThe type which will be stored in the ICMP struct.
Flags Tins::ICMP::type ( ) const
inline

Getter for the ICMP type flag.

Returns
The type flag for this ICMP PDU.
void Tins::ICMP::use_length_field ( bool  value)

Sets whether the length field will be set for packets that use it.

As defined in RFC 4884, some ICMP packet types can have a length field. This method controlers whether the length field is set or not.

Note that this only indicates that the packet should use this field. The actual value will be set during the packet's serialization.

Note that, in order to br RFC compliant, if the size of the encapsulated PDU is greater than 128, the length field will always be set, regardless of whether this method was called or not.

/param value true iff the length field should be set appropriately


The documentation for this class was generated from the following files: