36 #ifdef TIMESTAMP_REQUEST
37 #undef TIMESTAMP_REQUEST
40 #ifdef TIMESTAMP_REPLY
41 #undef TIMESTAMP_REPLY
45#include <tins/macros.h>
47#include <tins/endianness.h>
48#include <tins/ip_address.h>
49#include <tins/icmp_extension.h>
54class InputMemoryStream;
87 TIMESTAMP_REQUEST = 13,
91 ADDRESS_MASK_REQUEST = 17,
92 ADDRESS_MASK_REPLY = 18,
93 EXTENDED_ECHO_REQUEST = 42,
94 EXTENDED_ECHO_REPLY = 43
103 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
111 ICMP(Flags flag = ECHO_REQUEST);
124 ICMP(
const uint8_t* buffer, uint32_t total_sz);
131 void code(uint8_t new_code);
137 void type(Flags type);
144 void id(uint16_t new_id);
151 void sequence(uint16_t new_seq);
158 void gateway(address_type new_gw);
165 void mtu(uint16_t new_mtu);
172 void pointer(uint8_t new_pointer);
179 void original_timestamp(uint32_t new_timestamp);
186 void receive_timestamp(uint32_t new_timestamp);
193 void transmit_timestamp(uint32_t new_timestamp);
200 void address_mask(address_type new_mask);
208 void set_echo_request(uint16_t
id, uint16_t seq);
216 void set_echo_reply(uint16_t
id, uint16_t seq);
224 void set_info_request(uint16_t
id, uint16_t seq);
232 void set_info_reply(uint16_t
id, uint16_t seq);
237 void set_dest_unreachable();
246 void set_time_exceeded(
bool ttl_exceeded =
true);
256 void set_param_problem(
bool set_pointer =
false, uint8_t bad_octet = 0);
261 void set_source_quench();
270 void set_redirect(uint8_t icode, address_type address);
278 return (
Flags)header_.type;
296 return Endian::be_to_host(header_.check);
304 uint16_t
id()
const {
305 return Endian::be_to_host(header_.un.echo.id);
314 return Endian::be_to_host(header_.un.echo.sequence);
332 return header_.un.rfc4884.pointer;
341 return header_.un.rfc4884.length;
350 return Endian::be_to_host(header_.un.frag.mtu);
359 return Endian::be_to_host(orig_timestamp_or_address_mask_);
368 return Endian::be_to_host(recv_timestamp_);
377 return Endian::be_to_host(trans_timestamp_);
397 uint32_t header_size()
const;
406 uint32_t trailer_size()
const;
415 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
439 return !extensions_.extensions().empty();
457 void use_length_field(
bool value);
472 return new ICMP(*
this);
498 void checksum(uint16_t new_check);
499 void write_serialization(uint8_t* buffer, uint32_t total_sz);
500 uint32_t get_adjusted_inner_pdu_size()
const;
501 void try_parse_extensions(Memory::InputMemoryStream& stream);
502 bool are_extensions_allowed()
const;
505 uint32_t orig_timestamp_or_address_mask_;
506 uint32_t recv_timestamp_;
507 uint32_t trans_timestamp_;
508 ICMPExtensionsStructure extensions_;
Class that represents an ICMP extensions structure.
Definition icmp_extension.h:161
Class that represents an ICMP PDU.
Definition icmp.h:65
uint16_t id() const
Getter for the echo id.
Definition icmp.h:304
uint16_t sequence() const
Getter for the echo sequence number.
Definition icmp.h:313
uint16_t mtu() const
Getter for the mtu field.
Definition icmp.h:349
uint32_t receive_timestamp() const
Getter for the receive timestamp field.
Definition icmp.h:367
uint8_t length() const
Getter for the length field.
Definition icmp.h:340
IPv4Address address_type
Definition icmp.h:75
const ICMPExtensionsStructure & extensions() const
Getter for the extensions field.
Definition icmp.h:422
uint32_t transmit_timestamp() const
Getter for the transmit timestamp field.
Definition icmp.h:376
uint16_t checksum() const
Getter for the checksum field.
Definition icmp.h:295
bool has_extensions() const
Indicates whether this object contains ICMP extensions.
Definition icmp.h:438
uint8_t pointer() const
Getter for the pointer field.
Definition icmp.h:331
Flags type() const
Getter for the ICMP type flag.
Definition icmp.h:277
uint8_t code() const
Getter for the ICMP code flag.
Definition icmp.h:286
address_type address_mask() const
Getter for the address mask field.
Definition icmp.h:385
address_type gateway() const
Getter for the gateway field.
Definition icmp.h:322
PDUType pdu_type() const
Getter for the PDU's type.
Definition icmp.h:464
Flags
ICMP flags.
Definition icmp.h:79
uint32_t original_timestamp() const
Getter for the original timestamp field.
Definition icmp.h:358
ICMPExtensionsStructure & extensions()
Getter for the extensions field.
Definition icmp.h:431
ICMP * clone() const
Definition icmp.h:471
Abstraction of an IPv4 address.
Definition ip_address.h:45
Base class for protocol data units.
Definition pdu.h:107
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
The Tins namespace.
Definition address_range.h:38