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

Represents an ARP PDU. More...

#include <arp.h>

Inheritance diagram for Tins::ARP:
Tins::PDU

Public Types

enum  Flags { REQUEST = 0x0001, REPLY = 0x0002 }
 Enum which indicates the type of ARP packet.
 
enum  e {
  NETROM = 0, ETHER = 1, EETHER = 2, AX25 = 3,
  PRONET = 4, CHAOS = 5, IEEE802 = 6, ARCNET = 7,
  APPLETLK = 8, DLCI = 15, ATM = 19, METRICOM = 23,
  IEEE1394 = 24, EUI64 = 27, INFINIBAND = 32, SLIP = 256,
  CSLIP = 257, SLIP6 = 258, CSLIP6 = 259, RSRVD = 260,
  ADAPT = 264, ROSE = 270, X25 = 271, HWX25 = 272,
  PPP = 512, CISCO = 513, HDLC = CISCO, LAPB = 516,
  DDCMP = 517, RAWHDLC = 518, TUNNEL = 768, TUNNEL6 = 769,
  FRAD = 770, SKIP = 771, LOOPBACK = 772, LOCALTLK = 773,
  FDDI = 774, BIF = 775, SIT = 776, IPDDP = 777,
  IPGRE = 778, PIMREG = 779, HIPPI = 780, ASH = 781,
  ECONET = 782, IRDA = 783, FCPP = 784, FCAL = 785,
  FCPL = 786, FCFABRIC = 787, IEEE802_TR = 800, IEEE80211 = 801,
  IEEE80211_PRISM = 802, IEEE80211_RADIOTAP = 803, IEEE802154 = 804, IEEE802154_PHY = 805,
  VOID_TYPE = 0xFFFF, NONE = 0xFFFE
}
 
typedef HWAddress< 6 > hwaddress_type
 
typedef IPv4Address ipaddress_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

 ARP (ipaddress_type target_ip=ipaddress_type(), ipaddress_type sender_ip=ipaddress_type(), const hwaddress_type &target_hw=hwaddress_type(), const hwaddress_type &sender_hw=hwaddress_type())
 Constructs an ARP object using the provided addresses. More...
 
 ARP (const uint8_t *buffer, uint32_t total_sz)
 Constructs an ARP object from a buffer. More...
 
hwaddress_type sender_hw_addr () const
 Getter for the sender's hardware address. More...
 
ipaddress_type sender_ip_addr () const
 Getter for the sender's IP address. More...
 
hwaddress_type target_hw_addr () const
 Getter for the target's hardware address. More...
 
ipaddress_type target_ip_addr () const
 Getter for the target's IP address. More...
 
uint16_t hw_addr_format () const
 Getter for the hardware address format field. More...
 
uint16_t prot_addr_format () const
 Getter for the protocol address format field. More...
 
uint8_t hw_addr_length () const
 Getter for the hardware address length field. More...
 
uint8_t prot_addr_length () const
 Getter for the protocol address length field. More...
 
uint16_t opcode () const
 Getter for the ARP opcode field. More...
 
uint32_t header_size () const
 Getter for the header size. More...
 
void sender_hw_addr (const hwaddress_type &address)
 Setter for the sender's hardware address. More...
 
void sender_ip_addr (ipaddress_type address)
 Setter for the sender's IP address. More...
 
void target_hw_addr (const hwaddress_type &address)
 Setter for the target's hardware address. More...
 
void target_ip_addr (ipaddress_type address)
 Setter for the target's IP address. More...
 
void hw_addr_format (uint16_t format)
 Setter for the hardware address format field. More...
 
void prot_addr_format (uint16_t format)
 Setter for the protocol address format field. More...
 
void hw_addr_length (uint8_t length)
 Setter for the hardware address length field. More...
 
void prot_addr_length (uint8_t length)
 Setter for the protocol address length field. More...
 
void opcode (Flags code)
 Setter for the ARP opcode field. More...
 
PDUType pdu_type () const
 Getter for the PDU's type. 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...
 
ARPclone () 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...
 
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...
 
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 EthernetII make_arp_request (ipaddress_type target, ipaddress_type sender, const hwaddress_type &hw_snd=hwaddress_type())
 Creates an ARP Request within an EthernetII PDU. More...
 
static EthernetII make_arp_reply (ipaddress_type target, ipaddress_type sender, const hwaddress_type &hw_tgt=hwaddress_type(), const hwaddress_type &hw_snd=hwaddress_type())
 Creates an ARP Reply within an EthernetII PDU. More...
 

Static Public Attributes

static const PDU::PDUType pdu_flag = PDU::ARP
 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

Represents an ARP PDU.

Member Typedef Documentation

The type of the hardware address.

The type of the IP address.

Constructor & Destructor Documentation

Tins::ARP::ARP ( ipaddress_type  target_ip = ipaddress_type(),
ipaddress_type  sender_ip = ipaddress_type(),
const hwaddress_type target_hw = hwaddress_type(),
const hwaddress_type sender_hw = hwaddress_type() 
)

Constructs an ARP object using the provided addresses.

ARP requests and replies can be constructed easily using ARP::make_arp_request/reply static member functions.

See also
ARP::make_arp_request
ARP::make_arp_reply
Parameters
target_ipThe target IP address.
sender_ipThe sender IP address.
target_hwThe target hardware address.
sender_hwThe sender hardware address.
Tins::ARP::ARP ( const uint8_t *  buffer,
uint32_t  total_sz 
)

Constructs an ARP object from a buffer.

If there is not enough size for an ARP header in the buffer, a malformed_packet exception is thrown.

If the buffer is bigger than the size of the ARP header, then the extra data is stored in a RawPDU.

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

Member Function Documentation

ARP* Tins::ARP::clone ( ) const
inlinevirtual
See also
PDU::clone

Implements Tins::PDU.

PDU::metadata Tins::ARP::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
uint32_t Tins::ARP::header_size ( ) const
virtual

Getter for the header size.

Returns
Returns the ARP header size.
See also
PDU::header_size

Implements Tins::PDU.

uint16_t Tins::ARP::hw_addr_format ( ) const
inline

Getter for the hardware address format field.

Returns
The hardware address format.
void Tins::ARP::hw_addr_format ( uint16_t  format)

Setter for the hardware address format field.

Parameters
formatThe new hardware address format.
uint8_t Tins::ARP::hw_addr_length ( ) const
inline

Getter for the hardware address length field.

Returns
The hardware address length.
void Tins::ARP::hw_addr_length ( uint8_t  length)

Setter for the hardware address length field.

Parameters
lengthThe new hardware address length.
EthernetII Tins::ARP::make_arp_reply ( ipaddress_type  target,
ipaddress_type  sender,
const hwaddress_type hw_tgt = hwaddress_type(),
const hwaddress_type hw_snd = hwaddress_type() 
)
static

Creates an ARP Reply within an EthernetII PDU.

Creates an ARP Reply PDU and embeds it inside an EthernetII PDU.

Parameters
targetThe target's IP address.
senderThe sender's IP address.
hw_tgtThe target's hardware address.
hw_sndThe sender's hardware address.
Returns
EthernetII object containing the ARP Reply.
EthernetII Tins::ARP::make_arp_request ( ipaddress_type  target,
ipaddress_type  sender,
const hwaddress_type hw_snd = hwaddress_type() 
)
static

Creates an ARP Request within an EthernetII PDU.

Creates an ARP Request PDU and embeds it inside an EthernetII PDU.

Parameters
targetThe target's IP address.
senderThe sender's IP address.
hw_sndThe sender's hardware address.
Returns
EthernetII object containing the ARP Request.
bool Tins::ARP::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.

uint16_t Tins::ARP::opcode ( ) const
inline

Getter for the ARP opcode field.

Returns
The ARP opcode.
void Tins::ARP::opcode ( Flags  code)

Setter for the ARP opcode field.

Parameters
codeFlag enum value of the ARP opcode to set.
PDUType Tins::ARP::pdu_type ( ) const
inlinevirtual

Getter for the PDU's type.

See also
PDU::pdu_type

Implements Tins::PDU.

uint16_t Tins::ARP::prot_addr_format ( ) const
inline

Getter for the protocol address format field.

Returns
The protocol address format.
void Tins::ARP::prot_addr_format ( uint16_t  format)

Setter for the protocol address format field.

Parameters
formatThe new protocol address format.
uint8_t Tins::ARP::prot_addr_length ( ) const
inline

Getter for the protocol address length field.

Returns
The protocol address length.
void Tins::ARP::prot_addr_length ( uint8_t  length)

Setter for the protocol address length field.

Parameters
lengthThe new protocol address length.
hwaddress_type Tins::ARP::sender_hw_addr ( ) const
inline

Getter for the sender's hardware address.

Returns
The sender hardware address.
void Tins::ARP::sender_hw_addr ( const hwaddress_type address)

Setter for the sender's hardware address.

Parameters
addressThe new sender hardware address.
ipaddress_type Tins::ARP::sender_ip_addr ( ) const
inline

Getter for the sender's IP address.

Returns
The sender IP address.
void Tins::ARP::sender_ip_addr ( ipaddress_type  address)

Setter for the sender's IP address.

Parameters
addressThe new sender IP address.
hwaddress_type Tins::ARP::target_hw_addr ( ) const
inline

Getter for the target's hardware address.

Returns
The target hardware address.
void Tins::ARP::target_hw_addr ( const hwaddress_type address)

Setter for the target's hardware address.

Parameters
addressThe new target hardware address.
ipaddress_type Tins::ARP::target_ip_addr ( ) const
inline

Getter for the target's IP address.

Returns
The target IP address.
void Tins::ARP::target_ip_addr ( ipaddress_type  address)

Setter for the target's IP address.

Parameters
addressThe new target IP address.

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