36 #ifdef TIMESTAMP_REQUEST 37 #undef TIMESTAMP_REQUEST 38 #endif // TIMESTAMP_REQUEST 40 #ifdef TIMESTAMP_REPLY 41 #undef TIMESTAMP_REPLY 42 #endif // TIMESTAMP_REPLY 45 #include <tins/macros.h> 47 #include <tins/endianness.h> 48 #include <tins/ip_address.h> 49 #include <tins/icmp_extension.h> 54 class InputMemoryStream;
87 TIMESTAMP_REQUEST = 13,
91 ADDRESS_MASK_REQUEST = 17,
92 ADDRESS_MASK_REPLY = 18
101 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
122 ICMP(
const uint8_t* buffer, uint32_t total_sz);
129 void code(uint8_t new_code);
135 void type(
Flags type);
142 void id(uint16_t new_id);
149 void sequence(uint16_t new_seq);
156 void gateway(address_type new_gw);
163 void mtu(uint16_t new_mtu);
170 void pointer(uint8_t new_pointer);
177 void original_timestamp(uint32_t new_timestamp);
184 void receive_timestamp(uint32_t new_timestamp);
191 void transmit_timestamp(uint32_t new_timestamp);
198 void address_mask(address_type new_mask);
206 void set_echo_request(uint16_t
id, uint16_t seq);
214 void set_echo_reply(uint16_t
id, uint16_t seq);
222 void set_info_request(uint16_t
id, uint16_t seq);
230 void set_info_reply(uint16_t
id, uint16_t seq);
235 void set_dest_unreachable();
244 void set_time_exceeded(
bool ttl_exceeded =
true);
254 void set_param_problem(
bool set_pointer =
false, uint8_t bad_octet = 0);
259 void set_source_quench();
268 void set_redirect(uint8_t icode, address_type address);
276 return (
Flags)header_.type;
294 return Endian::be_to_host(header_.check);
302 uint16_t
id()
const {
303 return Endian::be_to_host(header_.un.echo.id);
312 return Endian::be_to_host(header_.un.echo.sequence);
321 return address_type(Endian::be_to_host(header_.un.gateway));
330 return header_.un.rfc4884.pointer;
339 return header_.un.rfc4884.length;
348 return Endian::be_to_host(header_.un.frag.mtu);
357 return Endian::be_to_host(orig_timestamp_or_address_mask_);
366 return Endian::be_to_host(recv_timestamp_);
375 return Endian::be_to_host(trans_timestamp_);
384 return address_type(Endian::be_to_host(orig_timestamp_or_address_mask_));
395 uint32_t header_size()
const;
404 uint32_t trailer_size()
const;
413 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
437 return !extensions_.extensions().empty();
455 void use_length_field(
bool value);
470 return new ICMP(*
this);
496 void checksum(uint16_t new_check);
497 void write_serialization(uint8_t* buffer, uint32_t total_sz);
498 uint32_t get_adjusted_inner_pdu_size()
const;
499 void try_parse_extensions(Memory::InputMemoryStream& stream);
500 bool are_extensions_allowed()
const;
503 uint32_t orig_timestamp_or_address_mask_;
504 uint32_t recv_timestamp_;
505 uint32_t trans_timestamp_;
511 #endif // TINS_ICMP_H uint8_t code() const
Getter for the ICMP code flag.
Definition: icmp.h:284
uint8_t pointer() const
Getter for the pointer field.
Definition: icmp.h:329
Class that represents an ICMP PDU.
Definition: icmp.h:65
ICMPExtensionsStructure & extensions()
Getter for the extensions field.
Definition: icmp.h:429
Flags
ICMP flags.
Definition: icmp.h:79
IPv4Address address_type
Definition: icmp.h:75
uint16_t id() const
Getter for the echo id.
Definition: icmp.h:302
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
ICMP * clone() const
Definition: icmp.h:469
address_type address_mask() const
Getter for the address mask field.
Definition: icmp.h:383
const ICMPExtensionsStructure & extensions() const
Getter for the extensions field.
Definition: icmp.h:420
bool has_extensions() const
Indicates whether this object contains ICMP extensions.
Definition: icmp.h:436
uint32_t receive_timestamp() const
Getter for the receive timestamp field.
Definition: icmp.h:365
PDUType pdu_type() const
Getter for the PDU's type.
Definition: icmp.h:462
The Tins namespace.
Definition: address_range.h:38
uint32_t transmit_timestamp() const
Getter for the transmit timestamp field.
Definition: icmp.h:374
uint16_t checksum() const
Getter for the checksum field.
Definition: icmp.h:293
uint8_t length() const
Getter for the length field.
Definition: icmp.h:338
Flags type() const
Getter for the ICMP type flag.
Definition: icmp.h:275
address_type gateway() const
Getter for the gateway field.
Definition: icmp.h:320
uint16_t mtu() const
Getter for the mtu field.
Definition: icmp.h:347
Abstraction of an IPv4 address.
Definition: ip_address.h:45
uint16_t sequence() const
Getter for the echo sequence number.
Definition: icmp.h:311
Class that represents an ICMP extensions structure.
Definition: icmp_extension.h:161
Base class for protocol data units.
Definition: pdu.h:107
uint32_t original_timestamp() const
Getter for the original timestamp field.
Definition: icmp.h:356