libtins  4.0
Public Types | Public Member Functions | List of all members
Tins::PDUOption< OptionType, PDUType > Class Template Reference

Represents a PDU option field. More...

#include <pdu_option.h>

Public Types

typedef uint8_t data_type
 
typedef OptionType option_type
 

Public Member Functions

 PDUOption (option_type opt=option_type(), size_t length=0, const data_type *data=0)
 Constructs a PDUOption. More...
 
 PDUOption (const PDUOption &rhs)
 Copy constructor. More...
 
 PDUOption (PDUOption &&rhs) TINS_NOEXCEPT
 Move constructor. More...
 
PDUOptionoperator= (PDUOption &&rhs) TINS_NOEXCEPT
 Move assignment operator. More...
 
PDUOptionoperator= (const PDUOption &rhs)
 Copy assignment operator. More...
 
 ~PDUOption ()
 Destructor.
 
template<typename ForwardIterator >
 PDUOption (option_type opt, ForwardIterator start, ForwardIterator end)
 Constructs a PDUOption from iterators, which indicate the data to be stored in it. More...
 
template<typename ForwardIterator >
 PDUOption (option_type opt, uint16_t length, ForwardIterator start, ForwardIterator end)
 Constructs a PDUOption from iterators, which indicate the data to be stored in it. More...
 
option_type option () const
 
void option (option_type opt)
 
const data_type * data_ptr () const
 
size_t data_size () const
 Retrieves the length of this option's data. More...
 
size_t length_field () const
 Retrieves the data length field. More...
 
template<typename T >
to () const
 Constructs a T from this PDUOption. More...
 

Detailed Description

template<typename OptionType, typename PDUType>
class Tins::PDUOption< OptionType, PDUType >

Represents a PDU option field.

Several PDUs, such as TCP, IP, Dot11 or DHCP contain options. All of them behave exactly the same way. This class represents those options.

The OptionType template parameter indicates the type that will be used to store this option's identifier.

Constructor & Destructor Documentation

template<typename OptionType, typename PDUType>
Tins::PDUOption< OptionType, PDUType >::PDUOption ( option_type  opt = option_type(),
size_t  length = 0,
const data_type *  data = 0 
)
inline

Constructs a PDUOption.

Parameters
optThe option type.
lengthThe option's data length.
dataThe option's data(if any).
template<typename OptionType, typename PDUType>
Tins::PDUOption< OptionType, PDUType >::PDUOption ( const PDUOption< OptionType, PDUType > &  rhs)
inline

Copy constructor.

Parameters
rhsThe PDUOption to be copied.
template<typename OptionType, typename PDUType>
Tins::PDUOption< OptionType, PDUType >::PDUOption ( PDUOption< OptionType, PDUType > &&  rhs)
inline

Move constructor.

Parameters
rhsThe PDUOption to be moved.
template<typename OptionType, typename PDUType>
template<typename ForwardIterator >
Tins::PDUOption< OptionType, PDUType >::PDUOption ( option_type  opt,
ForwardIterator  start,
ForwardIterator  end 
)
inline

Constructs a PDUOption from iterators, which indicate the data to be stored in it.

Parameters
optThe option type.
startThe beginning of the option data.
endThe end of the option data.
template<typename OptionType, typename PDUType>
template<typename ForwardIterator >
Tins::PDUOption< OptionType, PDUType >::PDUOption ( option_type  opt,
uint16_t  length,
ForwardIterator  start,
ForwardIterator  end 
)
inline

Constructs a PDUOption from iterators, which indicate the data to be stored in it.

The length parameter indicates the contents of the length field when this option is serialized. Note that this can be different to std::distance(start, end).

See also
length_field
Parameters
optThe option type.
lengthThe length of this option.
startThe beginning of the option data.
endThe end of the option data.

Member Function Documentation

template<typename OptionType, typename PDUType>
const data_type* Tins::PDUOption< OptionType, PDUType >::data_ptr ( ) const
inline

Retrieves this option's data.

If this method is called when data_size() == 0, dereferencing the returned pointer will result in undefined behaviour.

Returns
const data_type& containing this option's value.
template<typename OptionType, typename PDUType>
size_t Tins::PDUOption< OptionType, PDUType >::data_size ( ) const
inline

Retrieves the length of this option's data.

This is the actual size of the data.

template<typename OptionType, typename PDUType>
size_t Tins::PDUOption< OptionType, PDUType >::length_field ( ) const
inline

Retrieves the data length field.

This is what the size field will contain when this option is serialized. It can differ from the actual data size.

This will be equal to data_size unless the constructor that takes both a data length and two iterators is used.

See also
data_size.
template<typename OptionType, typename PDUType>
PDUOption& Tins::PDUOption< OptionType, PDUType >::operator= ( PDUOption< OptionType, PDUType > &&  rhs)
inline

Move assignment operator.

Parameters
rhsThe PDUOption to be moved.
template<typename OptionType, typename PDUType>
PDUOption& Tins::PDUOption< OptionType, PDUType >::operator= ( const PDUOption< OptionType, PDUType > &  rhs)
inline

Copy assignment operator.

Parameters
rhsThe PDUOption to be copied.
template<typename OptionType, typename PDUType>
option_type Tins::PDUOption< OptionType, PDUType >::option ( ) const
inline

Retrieves this option's type.

Returns
uint8_t containing this option's size.
template<typename OptionType, typename PDUType>
void Tins::PDUOption< OptionType, PDUType >::option ( option_type  opt)
inline

Sets this option's type

Parameters
optThe option type to be set.
template<typename OptionType, typename PDUType>
template<typename T >
T Tins::PDUOption< OptionType, PDUType >::to ( ) const
inline

Constructs a T from this PDUOption.

Use this method to convert a PDUOption to the specific type that represents it. For example, if you know an option is of type PDU::SACK, you could use option.to<TCP::sack_type>().


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