libtins
4.0
|
Class that represents an IP PDU. More...
#include <ip.h>
Classes | |
struct | generic_route_option_type |
struct | option_identifier |
The type used to represent an option's type. More... | |
struct | security_type |
Public Types | |
enum | Flags { FLAG_RESERVED = 4, DONT_FRAGMENT = 2, MORE_FRAGMENTS = 1 } |
enum | OptionClass { CONTROL = 0, MEASUREMENT = 2 } |
Enum indicating the option's class. More... | |
enum | OptionNumber { END = 0, NOOP = 1, SEC = 2, LSRR = 3, TIMESTAMP = 4, EXTSEC = 5, RR = 7, SID = 8, SSRR = 9, MTUPROBE = 11, MTUREPLY = 12, EIP = 17, TR = 18, ADDEXT = 19, RTRALT = 20, SDB = 21, DPS = 23, UMP = 24, QS = 25 } |
Enum indicating the option's id number. More... | |
typedef IPv4Address | address_type |
typedef PDUOption< option_identifier, IP > | option |
typedef generic_route_option_type | lsrr_type |
typedef generic_route_option_type | ssrr_type |
typedef generic_route_option_type | record_route_type |
typedef std::vector< option > | options_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 | |
IP (address_type ip_dst=address_type(), address_type ip_src=address_type()) | |
Constructor for building the IP PDU. More... | |
IP (const uint8_t *buffer, uint32_t total_sz) | |
Constructs an IP object from a buffer and adds all identifiable PDUs found in the buffer as children of this one. More... | |
small_uint< 4 > | head_len () const |
Getter for the header length field. More... | |
uint8_t | tos () const |
Getter for the type of service field. More... | |
uint16_t | tot_len () const |
Getter for the total length field. More... | |
uint16_t | id () const |
Getter for the id field. More... | |
TINS_DEPRECATED (uint16_t frag_off() const) | |
Getter for the fragment offset field. More... | |
small_uint< 13 > | fragment_offset () const |
Getter for the fragment offset field. More... | |
Flags | flags () const |
Getter for the flags field. More... | |
uint8_t | ttl () const |
Getter for the time to live field. More... | |
uint8_t | protocol () const |
Getter for the protocol field. More... | |
uint16_t | checksum () const |
Getter for the checksum field. More... | |
address_type | src_addr () const |
Getter for the source address field. More... | |
address_type | dst_addr () const |
Getter for the destination address field. More... | |
small_uint< 4 > | version () const |
Getter for the version field. More... | |
const options_type & | options () const |
Getter for the IP options. More... | |
void | tos (uint8_t new_tos) |
Setter for the type of service field. More... | |
void | id (uint16_t new_id) |
Setter for the id field. More... | |
TINS_DEPRECATED (void frag_off(uint16_t new_frag_off)) | |
Setter for the fragment offset field. More... | |
void | fragment_offset (small_uint< 13 > new_frag_off) |
Setter for the fragment offset field. More... | |
void | flags (Flags new_flags) |
Setter for the flags field. More... | |
void | ttl (uint8_t new_ttl) |
Setter for the time to live field. More... | |
void | protocol (uint8_t new_protocol) |
Setter for the protocol field. More... | |
void | src_addr (address_type ip) |
Setter for the source address field. More... | |
void | dst_addr (address_type ip) |
Setter for the destination address field. More... | |
void | version (small_uint< 4 > ver) |
Setter for the version field. More... | |
void | add_option (const option &opt) |
Adds an IP option. More... | |
void | add_option (option &&opt) |
Adds an IP option. More... | |
template<typename... Args> | |
void | add_option (Args &&...args) |
Adds an IP option. More... | |
bool | remove_option (option_identifier id) |
Removes an IP option. More... | |
const option * | search_option (option_identifier id) const |
Searchs for an option that matchs the given flag. More... | |
void | eol () |
Adds an End Of List option. | |
void | noop () |
Adds a NOP option. | |
void | security (const security_type &data) |
Adds a security option. More... | |
void | lsrr (const lsrr_type &data) |
Adds a Loose Source and Record Route option. More... | |
void | ssrr (const ssrr_type &data) |
Adds a Strict Source and Record Route option. More... | |
void | record_route (const record_route_type &data) |
Adds a Record Route option. More... | |
void | stream_identifier (uint16_t stream_id) |
Adds a Stream Identifier option. More... | |
security_type | security () const |
Searchs and returns a security option. More... | |
lsrr_type | lsrr () const |
Searchs and returns a Loose Source and Record Route option. More... | |
ssrr_type | ssrr () const |
Searchs and returns a Strict Source and Record Route option. More... | |
record_route_type | record_route () const |
Searchs and returns a Record Route option. More... | |
uint16_t | stream_identifier () const |
Searchs and returns a Stream Identifier option. More... | |
uint32_t | header_size () const |
Returns the header size. More... | |
void | send (PacketSender &sender, const NetworkInterface &) |
bool | matches_response (const uint8_t *ptr, uint32_t total_sz) const |
Check whether ptr points to a valid response for this PDU. More... | |
PDU * | recv_response (PacketSender &sender, const NetworkInterface &) |
Receives a matching response for this packet. More... | |
bool | is_fragmented () const |
PDUType | pdu_type () const |
Getter for the PDU's type. More... | |
IP * | 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... | |
virtual uint32_t | trailer_size () const |
Trailer's size. 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 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... | |
Public Attributes | |
TINS_BEGIN_PACK struct Tins::IP::option_identifier | TINS_END_PACK |
Static Public Attributes | |
static const PDU::PDUType | pdu_flag = PDU::IP |
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... | |
void | serialize (uint8_t *buffer, uint32_t total_sz) |
Serializes this PDU and propagates this action to child PDUs. More... | |
Class that represents an IP PDU.
By default, IP PDUs are initialized, setting TTL to IP::DEFAULT_TTL, id field to 1 and version to 4. Taking this into account, users should set destination and source port and would be enough to send one.
When IP is the lowest layer on a packet, and the packet is serialized this willc heck if the source address is different than 0.0.0.0. If it is, the address of the interface in which the packet is going to be sent is retrieved (by using the routing table and the destination address) and set as the source address. If you don't want this behaviour, simply set the source address to 0.0.0.0.
typedef IPv4Address Tins::IP::address_type |
The type used to store addresses.
The type of the Loose Source and Record Route
typedef PDUOption<option_identifier, IP> Tins::IP::option |
The IP options type.
typedef std::vector<option> Tins::IP::options_type |
The type used to store IP options.
The type of the Record Route
The type of the Strict Source and Record Route
enum Tins::IP::Flags |
Type used to represent the different IP flags.
Enum indicating the option's class.
Enum OptionClass represents the different classes of IP Options.
Enum indicating the option's id number.
Enum Option indicates the possible IP Options.
Tins::IP::IP | ( | address_type | ip_dst = address_type() , |
address_type | ip_src = address_type() |
||
) |
Tins::IP::IP | ( | const uint8_t * | buffer, |
uint32_t | total_sz | ||
) |
Constructs an IP object from a buffer and adds all identifiable PDUs found in the buffer as children of this one.
If there is not enough size for an IP header, a malformed_packet exception is thrown.
buffer | The buffer from which this PDU will be constructed. |
total_sz | The total size of the buffer. |
void Tins::IP::add_option | ( | const option & | opt | ) |
Adds an IP option.
The option is added after the last option in the option fields.
opt | The option to be added |
|
inline |
|
inline |
Adds an IP option.
The option is constructed from the provided parameters.
args | The arguments to be used in the option's constructor. |
|
inline |
|
inlinevirtual |
Implements Tins::PDU.
|
inline |
void Tins::IP::dst_addr | ( | address_type | ip | ) |
Setter for the destination address field.
ip | The destination address to be set. |
|
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::IP::flags | ( | Flags | new_flags | ) |
Setter for the flags field.
new_flags | The new IP flags field value. |
|
inline |
Getter for the fragment offset field.
This will return the fragment offset field, as present in the packet, which indicates the offset of this fragment in blocks of 8 bytes.
void Tins::IP::fragment_offset | ( | small_uint< 13 > | new_frag_off | ) |
Setter for the fragment offset field.
The value provided is measured in units of 8 byte blocks. This means that if you want this packet to have a fragment offset of X, you need to provide X / 8 as the argument to this method.
new_frag_off | The new fragment offset, measured in units of 8 byte blocks. |
|
inline |
Getter for the header length field.
|
virtual |
Returns the header size.
This method overrides PDU::header_size.
Implements Tins::PDU.
void Tins::IP::id | ( | uint16_t | new_id | ) |
Setter for the id field.
new_id | The new id. |
bool Tins::IP::is_fragmented | ( | ) | const |
|
inline |
Adds a Loose Source and Record Route option.
data | The data to be stored in this option. |
|
inline |
Searchs and returns a Loose Source and Record Route option.
If no such option exists, an option_not_found exception is thrown.
|
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.
|
inline |
Getter for the IP options.
|
inlinevirtual |
|
inline |
void Tins::IP::protocol | ( | uint8_t | new_protocol | ) |
Setter for the protocol field.
Note that this protocol will be overwritten using the inner_pdu's protocol type during serialization unless the IP datagram is fragmented.
If the packet is fragmented and was originally sniffed, the original protocol type will be kept when serialized.
If this packet has been crafted manually and the inner_pdu is, for example, a RawPDU, then setting the protocol yourself is necessary.
new_protocol | The new protocol. |
|
inline |
Adds a Record Route option.
data | The data to be stored in this option. |
|
inline |
Searchs and returns a Record Route option.
If no such option exists, an option_not_found exception is thrown.
|
virtual |
Receives a matching response for this packet.
sender | The packet sender which will receive the packet. |
Reimplemented from Tins::PDU.
bool Tins::IP::remove_option | ( | option_identifier | id | ) |
Removes an IP option.
If there are multiple options of the given type, only the first one will be removed.
type | The type of the option to be removed. |
const IP::option * Tins::IP::search_option | ( | option_identifier | id | ) | const |
Searchs for an option that matchs the given flag.
If the option is not found, a null pointer is returned. Deleting the returned pointer will result in undefined behaviour.
id | The option identifier to be searched. |
void Tins::IP::security | ( | const security_type & | data | ) |
Adds a security option.
data | The data to be stored in this option. |
IP::security_type Tins::IP::security | ( | ) | const |
Searchs and returns a security option.
If no such option exists, an option_not_found exception is thrown.
|
virtual |
Reimplemented from Tins::PDU.
|
inline |
void Tins::IP::src_addr | ( | address_type | ip | ) |
Setter for the source address field.
ip | The source address to be set. |
|
inline |
Adds a Strict Source and Record Route option.
data | The data to be stored in this option. |
|
inline |
Searchs and returns a Strict Source and Record Route option.
If no such option exists, an option_not_found exception is thrown.
void Tins::IP::stream_identifier | ( | uint16_t | stream_id | ) |
Adds a Stream Identifier option.
stream_id | The stream id to be stored in this option. |
uint16_t Tins::IP::stream_identifier | ( | ) | const |
Searchs and returns a Stream Identifier option.
If no such option exists, an option_not_found exception is thrown.
|
inline |
Getter for the fragment offset field.
This method is deprecated. Use IP::fragment_offset and IP::flags.
Tins::IP::TINS_DEPRECATED | ( | void | frag_offuint16_t new_frag_off | ) |
Setter for the fragment offset field.
This method is deprecated. Use IP::fragment_offset and IP::flags.
new_frag_off | The new fragment offset. |
|
inline |
void Tins::IP::tos | ( | uint8_t | new_tos | ) |
Setter for the type of service field.
new_tos | The new type of service. |
|
inline |
|
inline |
void Tins::IP::ttl | ( | uint8_t | new_ttl | ) |
Setter for the time to live field.
new_ttl | The new time to live. |
|
inline |
void Tins::IP::version | ( | small_uint< 4 > | ver | ) |
Setter for the version field.
ver | The version field to be set. |
|
static |
This PDU's flag.