join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::DhcpOption Class Reference

DHCP option list. More...

#include <dhcp_option.hpp>

Classes

struct  Info
 description of an option. More...
 

Public Types

enum  Code : uint8_t {
  Pad = 0 , SubnetMask = 1 , TimeOffset = 2 , Router = 3 ,
  TimeServer = 4 , NameServer = 5 , DomainNameServer = 6 , LogServer = 7 ,
  CookieServer = 8 , LprServer = 9 , ImpressServer = 10 , ResourceLocationServer = 11 ,
  HostName = 12 , BootFileSize = 13 , MeritDumpFile = 14 , DomainName = 15 ,
  SwapServer = 16 , RootPath = 17 , ExtensionsPath = 18 , IpForwarding = 19 ,
  NonLocalSourceRouting = 20 , PolicyFilter = 21 , MaximumDatagramReassemblySize = 22 , DefaultIpTimeToLive = 23 ,
  PathMtuAgingTimeout = 24 , PathMtuPlateauTable = 25 , InterfaceMtu = 26 , AllSubnetsAreLocal = 27 ,
  BroadcastAddress = 28 , PerformMaskDiscovery = 29 , MaskSupplier = 30 , PerformRouterDiscovery = 31 ,
  RouterSolicitationAddress = 32 , StaticRoute = 33 , TrailerEncapsulation = 34 , ArpCacheTimeout = 35 ,
  EthernetEncapsulation = 36 , TcpDefaultTtl = 37 , TcpKeepaliveInterval = 38 , TcpKeepaliveGarbage = 39 ,
  NisDomain = 40 , NetworkInformationServer = 41 , NtpServer = 42 , VendorSpecificInformation = 43 ,
  NetbiosNameServer = 44 , NetbiosDatagramDistributionServer = 45 , NetbiosNodeType = 46 , NetbiosScope = 47 ,
  XWindowFontServer = 48 , XWindowDisplayManager = 49 , RequestedIpAddress = 50 , IpAddressLeaseTime = 51 ,
  OptionOverload = 52 , DhcpMessageType = 53 , ServerIdentifier = 54 , ParameterRequestList = 55 ,
  Message = 56 , MaximumDhcpMessageSize = 57 , RenewalTimeValue = 58 , RebindingTimeValue = 59 ,
  VendorClassIdentifier = 60 , ClientIdentifier = 61 , TftpServerName = 66 , BootFileName = 67 ,
  MobileIpHomeAgent = 68 , SmtpServer = 69 , Pop3Server = 70 , NntpServer = 71 ,
  DefaultWwwServer = 72 , DefaultFingerServer = 73 , DefaultIrcServer = 74 , StreetTalkServer = 75 ,
  StreetTalkDirectoryAssistanceServer = 76 , End = 255
}
 option codes. More...
 
enum  Type {
  Byte , Word , Long , SLong ,
  Text , Ip , Mac , Bytes ,
  Words , Ips
}
 type of the value an option carries on the wire. More...
 
using Options = std::map<uint8_t, DhcpOptionValue>
 option list.
 
using const_iterator = Options::const_iterator
 constant iterator from nested container.
 

Public Member Functions

 DhcpOption ()=default
 create the DhcpOption instance.
 
 DhcpOption (const_iterator first, const_iterator last)
 create the DhcpOption instance with the elements from range.
 
 DhcpOption (const DhcpOption &other)=default
 create instance by copy.
 
DhcpOptionoperator= (const DhcpOption &other)=default
 assign instance by copy.
 
 DhcpOption (DhcpOption &&other)=default
 create instance by move.
 
DhcpOptionoperator= (DhcpOption &&other)=default
 assign instance by move.
 
 ~DhcpOption ()=default
 destroy the DhcpOption instance.
 
const DhcpOptionValueat (uint8_t code) const
 get the value identified by code, with range verification.
 
template<typename T >
const T * getIf (uint8_t code) const
 get the value identified by code if it is present and holds the requested type.
 
const_iterator find (uint8_t code) const
 find the element with the given code.
 
bool contains (uint8_t code) const
 check if there is an element identified by code in the list.
 
const_iterator begin () const
 get an iterator to the first element of the list.
 
const_iterator cbegin () const
 get an iterator to the first element of the list.
 
const_iterator end () const
 get an iterator to the element following the last element of the list.
 
const_iterator cend () const
 get an iterator to the element following the last element of the list.
 
bool empty () const
 check if the list has no element.
 
size_t size () const
 get the number of options in the list.
 
size_t erase (uint8_t code)
 remove the element identified by code.
 
void clear ()
 remove all elements from the list.
 
template<typename T >
bool insert (uint8_t code, T &&value)
 add an option to the list, converting the value to the type the option carries.
 
void insert (const_iterator first, const_iterator last)
 insert elements from range.
 
void swap (DhcpOption &other)
 exchange the contents of the list with those of other.
 
std::string dump () const
 dump the options in string format.
 

Static Public Member Functions

template<typename T >
static bool isValid (uint8_t code, T &&value)
 check that a value can be carried by the given option.
 
static const Infodescribe (uint8_t code) noexcept
 get the description of the given option.
 

Static Protected Member Functions

static const char * codeName (uint8_t code) noexcept
 get the name of the given option.
 
static void write (std::ostream &stream, uint8_t code, const DhcpOptionValue &value)
 write an option value in string format.
 
static bool accepts (const Info &info, uint32_t value) noexcept
 check that a value satisfies the constraints of the given option.
 
template<typename Target , typename Source >
static std::enable_if< std::is_signed< Source >::value, bool >::type fits (Source value) noexcept
 check that a signed value can be represented by the target type.
 
template<typename Target , typename Source >
static std::enable_if<!std::is_signed< Source >::value, bool >::type fits (Source value) noexcept
 check that an unsigned value can be represented by the target type.
 
template<typename Target , typename Source >
static bool store (const Info &info, Source value, DhcpOptionValue &out)
 store an integer value as the given target type.
 
static bool invalid () noexcept
 report an invalid option value.
 
template<typename T >
static std::enable_if< std::is_integral< typenamestd::decay< T >::type >::value, bool >::type convert (uint8_t code, T value, DhcpOptionValue &out)
 convert an integer to the type the given option carries.
 
static bool convert (uint8_t code, const std::string &value, DhcpOptionValue &out)
 convert a string to the type the given option carries.
 
static bool convert (uint8_t code, const char *value, DhcpOptionValue &out)
 convert a string to the type the given option carries.
 
static bool convert (uint8_t code, const IpAddress &value, DhcpOptionValue &out)
 store an IP address in the given option.
 
static bool convert (uint8_t code, const MacAddress &value, DhcpOptionValue &out)
 store a hardware address in the given option.
 
static bool convert (uint8_t code, const ByteList &value, DhcpOptionValue &out)
 store a list of bytes in the given option.
 
static bool convert (uint8_t code, const WordList &value, DhcpOptionValue &out)
 store a list of words in the given option.
 
static bool convert (uint8_t code, const IpList &value, DhcpOptionValue &out)
 store a list of IP addresses in the given option.
 

Protected Attributes

Options _options
 options.
 

Friends

bool operator== (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with equal operator.
 
bool operator!= (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with not equal operator.
 
bool operator< (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with lower operator.
 
bool operator> (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with greater operator.
 
bool operator<= (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with lower or equal operator.
 
bool operator>= (const DhcpOption &lhs, const DhcpOption &rhs)
 friendship with greater or equal operator.
 

Detailed Description

DHCP option list.

Member Typedef Documentation

◆ const_iterator

using join::DhcpOption::const_iterator = Options::const_iterator

constant iterator from nested container.

◆ Options

using join::DhcpOption::Options = std::map<uint8_t, DhcpOptionValue>

option list.

Member Enumeration Documentation

◆ Code

enum join::DhcpOption::Code : uint8_t

option codes.

Enumerator
Pad 
SubnetMask 
TimeOffset 
Router 
TimeServer 
NameServer 
DomainNameServer 
LogServer 
CookieServer 
LprServer 
ImpressServer 
ResourceLocationServer 
HostName 
BootFileSize 
MeritDumpFile 
DomainName 
SwapServer 
RootPath 
ExtensionsPath 
IpForwarding 
NonLocalSourceRouting 
PolicyFilter 
MaximumDatagramReassemblySize 
DefaultIpTimeToLive 
PathMtuAgingTimeout 
PathMtuPlateauTable 
InterfaceMtu 
AllSubnetsAreLocal 
BroadcastAddress 
PerformMaskDiscovery 
MaskSupplier 
PerformRouterDiscovery 
RouterSolicitationAddress 
StaticRoute 
TrailerEncapsulation 
ArpCacheTimeout 
EthernetEncapsulation 
TcpDefaultTtl 
TcpKeepaliveInterval 
TcpKeepaliveGarbage 
NisDomain 
NetworkInformationServer 
NtpServer 
VendorSpecificInformation 
NetbiosNameServer 
NetbiosDatagramDistributionServer 
NetbiosNodeType 
NetbiosScope 
XWindowFontServer 
XWindowDisplayManager 
RequestedIpAddress 
IpAddressLeaseTime 
OptionOverload 
DhcpMessageType 
ServerIdentifier 
ParameterRequestList 
Message 
MaximumDhcpMessageSize 
RenewalTimeValue 
RebindingTimeValue 
VendorClassIdentifier 
ClientIdentifier 
TftpServerName 
BootFileName 
MobileIpHomeAgent 
SmtpServer 
Pop3Server 
NntpServer 
DefaultWwwServer 
DefaultFingerServer 
DefaultIrcServer 
StreetTalkServer 
StreetTalkDirectoryAssistanceServer 
End 

◆ Type

type of the value an option carries on the wire.

Enumerator
Byte 

8 bits unsigned integer.

Word 

16 bits unsigned integer.

Long 

32 bits unsigned integer.

SLong 

32 bits signed integer.

Text 

character string.

Ip 

IPv4 address.

Mac 

hardware address.

Bytes 

list of 8 bits unsigned integers.

Words 

list of 16 bits unsigned integers.

Ips 

list of IPv4 addresses.

Constructor & Destructor Documentation

◆ DhcpOption() [1/4]

join::DhcpOption::DhcpOption ( )
default

create the DhcpOption instance.

◆ DhcpOption() [2/4]

join::DhcpOption::DhcpOption ( const_iterator first,
const_iterator last )
inline

create the DhcpOption instance with the elements from range.

Parameters
firstfirst element to insert.
lastlast element to insert.

◆ DhcpOption() [3/4]

join::DhcpOption::DhcpOption ( const DhcpOption & other)
default

create instance by copy.

Parameters
otherother object to copy.

◆ DhcpOption() [4/4]

join::DhcpOption::DhcpOption ( DhcpOption && other)
default

create instance by move.

Parameters
otherother object to move.

◆ ~DhcpOption()

join::DhcpOption::~DhcpOption ( )
default

destroy the DhcpOption instance.

Member Function Documentation

◆ accepts()

static bool join::DhcpOption::accepts ( const Info & info,
uint32_t value )
inlinestaticprotectednoexcept

check that a value satisfies the constraints of the given option.

Parameters
infooption description.
valuevalue to check.
Returns
true if the value is accepted, false otherwise.

◆ at()

const DhcpOptionValue & join::DhcpOption::at ( uint8_t code) const
inline

get the value identified by code, with range verification.

Parameters
codecode used to locate the value.
Returns
a reference to the mapped value.
Exceptions
std::out_of_rangeif the option is not in the list.

◆ begin()

const_iterator join::DhcpOption::begin ( ) const
inline

get an iterator to the first element of the list.

Returns
iterator to the first element.

◆ cbegin()

const_iterator join::DhcpOption::cbegin ( ) const
inline

get an iterator to the first element of the list.

Returns
iterator to the first element.

◆ cend()

const_iterator join::DhcpOption::cend ( ) const
inline

get an iterator to the element following the last element of the list.

Returns
iterator to the element following the last element.

◆ clear()

void join::DhcpOption::clear ( )
inline

remove all elements from the list.

◆ codeName()

const char * DhcpOption::codeName ( uint8_t code)
staticprotectednoexcept

get the name of the given option.

Parameters
codeoption code.
Returns
option name.

◆ contains()

bool join::DhcpOption::contains ( uint8_t code) const
inline

check if there is an element identified by code in the list.

Parameters
codecode of the element to search for.
Returns
true if there is an element identified by code, false otherwise.

◆ convert() [1/8]

bool DhcpOption::convert ( uint8_t code,
const ByteList & value,
DhcpOptionValue & out )
staticprotected

store a list of bytes in the given option.

Parameters
codeoption code.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [2/8]

static bool join::DhcpOption::convert ( uint8_t code,
const char * value,
DhcpOptionValue & out )
inlinestaticprotected

convert a string to the type the given option carries.

Parameters
codeoption code.
valuevalue to convert.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [3/8]

static bool join::DhcpOption::convert ( uint8_t code,
const IpAddress & value,
DhcpOptionValue & out )
inlinestaticprotected

store an IP address in the given option.

Parameters
codeoption code.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [4/8]

bool DhcpOption::convert ( uint8_t code,
const IpList & value,
DhcpOptionValue & out )
staticprotected

store a list of IP addresses in the given option.

Parameters
codeoption code.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [5/8]

static bool join::DhcpOption::convert ( uint8_t code,
const MacAddress & value,
DhcpOptionValue & out )
inlinestaticprotected

store a hardware address in the given option.

Parameters
codeoption code.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [6/8]

bool DhcpOption::convert ( uint8_t code,
const std::string & value,
DhcpOptionValue & out )
staticprotected

convert a string to the type the given option carries.

Parameters
codeoption code.
valuevalue to convert.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [7/8]

bool DhcpOption::convert ( uint8_t code,
const WordList & value,
DhcpOptionValue & out )
staticprotected

store a list of words in the given option.

Parameters
codeoption code.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ convert() [8/8]

template<typename T >
static std::enable_if< std::is_integral< typenamestd::decay< T >::type >::value, bool >::type join::DhcpOption::convert ( uint8_t code,
T value,
DhcpOptionValue & out )
inlinestaticprotected

convert an integer to the type the given option carries.

Parameters
codeoption code.
valuevalue to convert.
outconverted value.
Returns
true on success, false otherwise.

◆ describe()

const DhcpOption::Info * DhcpOption::describe ( uint8_t code)
staticnoexcept

get the description of the given option.

Parameters
codeoption code.
Returns
the option description, nullptr if the option is unknown.

◆ dump()

std::string join::DhcpOption::dump ( ) const
inline

dump the options in string format.

Returns
the options in string format.

◆ empty()

bool join::DhcpOption::empty ( ) const
inline

check if the list has no element.

Returns
true if the list is empty, false otherwise.

◆ end()

const_iterator join::DhcpOption::end ( ) const
inline

get an iterator to the element following the last element of the list.

Returns
iterator to the element following the last element.

◆ erase()

size_t join::DhcpOption::erase ( uint8_t code)
inline

remove the element identified by code.

Parameters
codecode to compare to.
Returns
number of elements removed.

◆ find()

const_iterator join::DhcpOption::find ( uint8_t code) const
inline

find the element with the given code.

Parameters
codecode of the element to search for.
Returns
iterator to the element, end () if absent.

◆ fits() [1/2]

template<typename Target , typename Source >
static std::enable_if< std::is_signed< Source >::value, bool >::type join::DhcpOption::fits ( Source value)
inlinestaticprotectednoexcept

check that a signed value can be represented by the target type.

Parameters
valuevalue to check.
Returns
true if the value fits, false otherwise.

◆ fits() [2/2]

template<typename Target , typename Source >
static std::enable_if<!std::is_signed< Source >::value, bool >::type join::DhcpOption::fits ( Source value)
inlinestaticprotectednoexcept

check that an unsigned value can be represented by the target type.

Parameters
valuevalue to check.
Returns
true if the value fits, false otherwise.

◆ getIf()

template<typename T >
const T * join::DhcpOption::getIf ( uint8_t code) const
inline

get the value identified by code if it is present and holds the requested type.

Parameters
codecode used to locate the value.
Returns
the value address, nullptr if absent or of another type.

◆ insert() [1/2]

void join::DhcpOption::insert ( const_iterator first,
const_iterator last )
inline

insert elements from range.

Parameters
firstfirst element to insert.
lastlast element to insert.

◆ insert() [2/2]

template<typename T >
bool join::DhcpOption::insert ( uint8_t code,
T && value )
inline

add an option to the list, converting the value to the type the option carries.

Parameters
codeoption code.
valueoption value.
Returns
true if the option was added to the list, false otherwise.

◆ invalid()

static bool join::DhcpOption::invalid ( )
inlinestaticprotectednoexcept

report an invalid option value.

Returns
false.

◆ isValid()

template<typename T >
static bool join::DhcpOption::isValid ( uint8_t code,
T && value )
inlinestatic

check that a value can be carried by the given option.

Parameters
codeoption code.
valueoption value.
Returns
true if valid, false otherwise.

◆ operator=() [1/2]

DhcpOption & join::DhcpOption::operator= ( const DhcpOption & other)
default

assign instance by copy.

Parameters
otherother object to copy.
Returns
a reference of the current object.

◆ operator=() [2/2]

DhcpOption & join::DhcpOption::operator= ( DhcpOption && other)
default

assign instance by move.

Parameters
otherother object to move.
Returns
a reference of the current object.

◆ size()

size_t join::DhcpOption::size ( ) const
inline

get the number of options in the list.

Returns
the number of options in the list.

◆ store()

template<typename Target , typename Source >
static bool join::DhcpOption::store ( const Info & info,
Source value,
DhcpOptionValue & out )
inlinestaticprotected

store an integer value as the given target type.

Parameters
infooption description.
valuevalue to store.
outconverted value.
Returns
true on success, false otherwise.

◆ swap()

void join::DhcpOption::swap ( DhcpOption & other)
inline

exchange the contents of the list with those of other.

Parameters
otherlist to exchange the contents with.

◆ write()

void DhcpOption::write ( std::ostream & stream,
uint8_t code,
const DhcpOptionValue & value )
staticprotected

write an option value in string format.

Parameters
streamstream to write to.
codeoption code.
valueoption value.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with not equal operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if not equal.

◆ operator<

bool operator< ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with lower operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if lower.

◆ operator<=

bool operator<= ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with lower or equal operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if lower or equal.

◆ operator==

bool operator== ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with equal operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if equal.

◆ operator>

bool operator> ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with greater operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if greater.

◆ operator>=

bool operator>= ( const DhcpOption & lhs,
const DhcpOption & rhs )
friend

friendship with greater or equal operator.

Parameters
lhsoptions to compare.
rhsoptions to compare to.
Returns
true if greater or equal.

Member Data Documentation

◆ _options

Options join::DhcpOption::_options
protected

options.


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