libtins
4.0
|
Class that represents an ICMP PDU. More...
#include <icmp.h>
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 ICMPExtensionsStructure & | extensions () const |
Getter for the extensions field. More... | |
ICMPExtensionsStructure & | extensions () |
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... | |
ICMP * | clone () const |
Public Member Functions inherited from Tins::PDU | |
PDU () | |
Default constructor. | |
PDU (PDU &&rhs) TINS_NOEXCEPT | |
Move constructor. More... | |
PDU & | operator= (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... | |
PDU * | inner_pdu () const |
Getter for the inner PDU. More... | |
PDU * | parent_pdu () const |
PDU * | release_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 PDU * | recv_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. | |
PDU & | operator= (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... | |
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.
typedef IPv4Address Tins::ICMP::address_type |
The type used to store addresses.
Tins::ICMP::ICMP | ( | Flags | flag = ECHO_REQUEST | ) |
Creates an instance of ICMP.
If no flag is specified, then ECHO_REQUEST will be used.
flag | The 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.
buffer | The buffer from which this PDU will be constructed. |
total_sz | The total size of the buffer. |
void Tins::ICMP::address_mask | ( | address_type | new_mask | ) |
Setter for the address mask field.
new_mask | the value to be set. |
|
inline |
Getter for the address mask field.
|
inline |
Getter for the checksum field.
|
inlinevirtual |
Implements Tins::PDU.
void Tins::ICMP::code | ( | uint8_t | new_code | ) |
Sets the code field.
new_code | The code which will be stored in the ICMP struct. |
|
inline |
|
inline |
Getter for the extensions field.
|
inline |
Getter for the extensions field.
|
static |
Extracts metadata for this protocol based on the buffer provided.
buffer | Pointer to a buffer |
total_sz | Size of the buffer pointed by buffer |
void Tins::ICMP::gateway | ( | address_type | new_gw | ) |
Setter for the gateway field.
new_gw | The new value for the gateway field. |
|
inline |
Getter for the gateway field.
|
virtual |
Returns the header size.
This method overrides PDU::header_size. This size includes the payload and options size.
Implements Tins::PDU.
void Tins::ICMP::id | ( | uint16_t | new_id | ) |
Setter for the id field.
new_id | uint16_t with the new id. |
|
inline |
Getter for the echo id.
|
inline |
Getter for the length field.
|
virtual |
Check whether ptr points to a valid response for this PDU.
ptr | The pointer to the buffer. |
total_sz | The size of the buffer. |
Reimplemented from Tins::PDU.
void Tins::ICMP::mtu | ( | uint16_t | new_mtu | ) |
Setter for the mtu field.
new_mtu | uint16_t with the new sequence. |
|
inline |
Getter for the mtu field.
void Tins::ICMP::original_timestamp | ( | uint32_t | new_timestamp | ) |
Setter for the original timestamp field.
new_timestamp | the value to be set. |
|
inline |
Getter for the original timestamp field.
|
inlinevirtual |
void Tins::ICMP::pointer | ( | uint8_t | new_pointer | ) |
Setter for the pointer field.
new_pointer | uint8_t with the new pointer. |
|
inline |
Getter for the pointer field.
void Tins::ICMP::receive_timestamp | ( | uint32_t | new_timestamp | ) |
Setter for the receive timestamp field.
new_timestamp | the value to be set. |
|
inline |
Getter for the receive timestamp field.
void Tins::ICMP::sequence | ( | uint16_t | new_seq | ) |
Setter for the sequence field.
new_seq | uint16_t with the new sequence. |
|
inline |
Getter for the echo sequence number.
void Tins::ICMP::set_echo_reply | ( | uint16_t | id, |
uint16_t | seq | ||
) |
Sets echo reply flag for this PDU.
id | The identifier for this request. |
seq | The sequence number for this request. |
void Tins::ICMP::set_echo_request | ( | uint16_t | id, |
uint16_t | seq | ||
) |
Sets echo request flag for this PDU.
id | The identifier for this request. |
seq | The sequence number for this request. |
void Tins::ICMP::set_info_reply | ( | uint16_t | id, |
uint16_t | seq | ||
) |
Sets information reply flag for this PDU.
id | The identifier for this request. |
seq | The sequence number for this request. |
void Tins::ICMP::set_info_request | ( | uint16_t | id, |
uint16_t | seq | ||
) |
Sets information request flag for this PDU.
id | The identifier for this request. |
seq | The 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.
set_pointer | Indicates whether a pointer to the bad octet is provided. |
bad_octet | Identifies 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.
icode | The code to be set. |
address | Address of the gateway to which traffic should be sent. |
void Tins::ICMP::set_time_exceeded | ( | bool | ttl_exceeded = true | ) |
|
virtual |
Returns the trailer size.
This method overrides PDU::trailer_size. This size will hold the extensions size
Reimplemented from Tins::PDU.
void Tins::ICMP::transmit_timestamp | ( | uint32_t | new_timestamp | ) |
Setter for the transmit timestamp field.
new_timestamp | the value to be set. |
|
inline |
Getter for the transmit timestamp field.
void Tins::ICMP::type | ( | Flags | type | ) |
Sets the type field.
type | The type which will be stored in the ICMP struct. |
|
inline |
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