25#ifndef JOIN_FABRIC_DHCP_OPTION_HPP
26#define JOIN_FABRIC_DHCP_OPTION_HPP
51 using IpList = std::vector<IpAddress>;
175 using Options = std::map<uint8_t, DhcpOptionValue>;
242 template <
typename T>
246 return (it ==
_options.end ()) ? nullptr : it->second.getIf<T> ();
266 return (
find (code) !=
end ());
347 template <
typename T>
352 if (!
convert (code, std::forward<T> (value), converted))
357 if (!
_options.emplace (code, std::move (converted)).second)
391 std::stringstream stream;
395 stream <<
codeName (option.first) <<
" (" << int (option.first) <<
"): ";
396 write (stream, option.first, option.second);
400 return stream.str ();
409 template <
typename T>
413 return convert (code, std::forward<T> (value), converted);
421 static const Info*
describe (uint8_t code)
noexcept;
429 static const char*
codeName (uint8_t code)
noexcept;
449 return (value < 32) && ((info.mask >> value) & 1u);
454 return (value >= info.min) && (value <= info.max);
465 template <
typename Target,
typename Source>
466 static typename std::enable_if<std::is_signed<Source>::value,
bool>::type
fits (Source value)
noexcept
470 return std::is_signed<Target>::value &&
471 static_cast<int64_t
> (value) >=
static_cast<int64_t
> (std::numeric_limits<Target>::min ());
474 return static_cast<uint64_t
> (value) <=
static_cast<uint64_t
> (std::numeric_limits<Target>::max ());
482 template <
typename Target,
typename Source>
483 static typename std::enable_if<!std::is_signed<Source>::value,
bool>::type
fits (Source value)
noexcept
485 return static_cast<uint64_t
> (value) <=
static_cast<uint64_t
> (std::numeric_limits<Target>::max ());
495 template <
typename Target,
typename Source>
504 out =
static_cast<Target
> (value);
526 template <
typename T>
527 static typename std::enable_if<std::is_integral<typename std::decay<T>::type>::value,
bool>::type
convert (
575 return convert (code, std::string (value), out);
588 if ((info ==
nullptr) || (info->
type !=
Ip) || (value.
family () != AF_INET))
608 if ((info ==
nullptr) || (info->
type !=
Mac))
741 out << options.
dump ();
DHCP option list.
Definition dhcp_option.hpp:61
static bool isValid(uint8_t code, T &&value)
check that a value can be carried by the given option.
Definition dhcp_option.hpp:410
size_t size() const
get the number of options in the list.
Definition dhcp_option.hpp:318
Code
option codes.
Definition dhcp_option.hpp:67
@ Router
Definition dhcp_option.hpp:71
@ Message
Definition dhcp_option.hpp:124
@ BootFileName
Definition dhcp_option.hpp:131
@ DefaultWwwServer
Definition dhcp_option.hpp:136
@ ServerIdentifier
Definition dhcp_option.hpp:122
@ TcpDefaultTtl
Definition dhcp_option.hpp:105
@ NetbiosDatagramDistributionServer
Definition dhcp_option.hpp:113
@ TimeOffset
Definition dhcp_option.hpp:70
@ XWindowFontServer
Definition dhcp_option.hpp:116
@ IpForwarding
Definition dhcp_option.hpp:87
@ RebindingTimeValue
Definition dhcp_option.hpp:127
@ BroadcastAddress
Definition dhcp_option.hpp:96
@ NetworkInformationServer
Definition dhcp_option.hpp:109
@ StreetTalkDirectoryAssistanceServer
Definition dhcp_option.hpp:140
@ MeritDumpFile
Definition dhcp_option.hpp:82
@ XWindowDisplayManager
Definition dhcp_option.hpp:117
@ DomainNameServer
Definition dhcp_option.hpp:74
@ ExtensionsPath
Definition dhcp_option.hpp:86
@ PerformRouterDiscovery
Definition dhcp_option.hpp:99
@ IpAddressLeaseTime
Definition dhcp_option.hpp:119
@ EthernetEncapsulation
Definition dhcp_option.hpp:104
@ DefaultIrcServer
Definition dhcp_option.hpp:138
@ MaskSupplier
Definition dhcp_option.hpp:98
@ NisDomain
Definition dhcp_option.hpp:108
@ RenewalTimeValue
Definition dhcp_option.hpp:126
@ StreetTalkServer
Definition dhcp_option.hpp:139
@ NameServer
Definition dhcp_option.hpp:73
@ PolicyFilter
Definition dhcp_option.hpp:89
@ OptionOverload
Definition dhcp_option.hpp:120
@ SmtpServer
Definition dhcp_option.hpp:133
@ ParameterRequestList
Definition dhcp_option.hpp:123
@ TrailerEncapsulation
Definition dhcp_option.hpp:102
@ LogServer
Definition dhcp_option.hpp:75
@ TcpKeepaliveGarbage
Definition dhcp_option.hpp:107
@ RouterSolicitationAddress
Definition dhcp_option.hpp:100
@ Pad
Definition dhcp_option.hpp:68
@ TftpServerName
Definition dhcp_option.hpp:130
@ RootPath
Definition dhcp_option.hpp:85
@ DefaultFingerServer
Definition dhcp_option.hpp:137
@ NetbiosScope
Definition dhcp_option.hpp:115
@ VendorClassIdentifier
Definition dhcp_option.hpp:128
@ NntpServer
Definition dhcp_option.hpp:135
@ DomainName
Definition dhcp_option.hpp:83
@ SubnetMask
Definition dhcp_option.hpp:69
@ DefaultIpTimeToLive
Definition dhcp_option.hpp:91
@ ImpressServer
Definition dhcp_option.hpp:78
@ LprServer
Definition dhcp_option.hpp:77
@ ClientIdentifier
Definition dhcp_option.hpp:129
@ TimeServer
Definition dhcp_option.hpp:72
@ SwapServer
Definition dhcp_option.hpp:84
@ PathMtuPlateauTable
Definition dhcp_option.hpp:93
@ NetbiosNameServer
Definition dhcp_option.hpp:112
@ ResourceLocationServer
Definition dhcp_option.hpp:79
@ StaticRoute
Definition dhcp_option.hpp:101
@ AllSubnetsAreLocal
Definition dhcp_option.hpp:95
@ Pop3Server
Definition dhcp_option.hpp:134
@ MaximumDhcpMessageSize
Definition dhcp_option.hpp:125
@ End
Definition dhcp_option.hpp:141
@ MaximumDatagramReassemblySize
Definition dhcp_option.hpp:90
@ RequestedIpAddress
Definition dhcp_option.hpp:118
@ VendorSpecificInformation
Definition dhcp_option.hpp:111
@ DhcpMessageType
Definition dhcp_option.hpp:121
@ HostName
Definition dhcp_option.hpp:80
@ PathMtuAgingTimeout
Definition dhcp_option.hpp:92
@ InterfaceMtu
Definition dhcp_option.hpp:94
@ BootFileSize
Definition dhcp_option.hpp:81
@ NetbiosNodeType
Definition dhcp_option.hpp:114
@ ArpCacheTimeout
Definition dhcp_option.hpp:103
@ MobileIpHomeAgent
Definition dhcp_option.hpp:132
@ NonLocalSourceRouting
Definition dhcp_option.hpp:88
@ PerformMaskDiscovery
Definition dhcp_option.hpp:97
@ CookieServer
Definition dhcp_option.hpp:76
@ TcpKeepaliveInterval
Definition dhcp_option.hpp:106
@ NtpServer
Definition dhcp_option.hpp:110
const_iterator end() const
get an iterator to the element following the last element of the list.
Definition dhcp_option.hpp:291
friend bool operator!=(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with not equal operator.
Definition dhcp_option.hpp:684
bool insert(uint8_t code, T &&value)
add an option to the list, converting the value to the type the option carries.
Definition dhcp_option.hpp:348
Options::const_iterator const_iterator
constant iterator from nested container.
Definition dhcp_option.hpp:178
friend bool operator<(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with lower operator.
Definition dhcp_option.hpp:695
static bool store(const Info &info, Source value, DhcpOptionValue &out)
store an integer value as the given target type.
Definition dhcp_option.hpp:496
Type
type of the value an option carries on the wire.
Definition dhcp_option.hpp:148
@ Word
Definition dhcp_option.hpp:150
@ Ip
Definition dhcp_option.hpp:154
@ Mac
Definition dhcp_option.hpp:155
@ Text
Definition dhcp_option.hpp:153
@ Ips
Definition dhcp_option.hpp:158
@ SLong
Definition dhcp_option.hpp:152
@ Bytes
Definition dhcp_option.hpp:156
@ Long
Definition dhcp_option.hpp:151
@ Byte
Definition dhcp_option.hpp:149
@ Words
Definition dhcp_option.hpp:157
DhcpOption(DhcpOption &&other)=default
create instance by move.
const DhcpOptionValue & at(uint8_t code) const
get the value identified by code, with range verification.
Definition dhcp_option.hpp:232
const T * getIf(uint8_t code) const
get the value identified by code if it is present and holds the requested type.
Definition dhcp_option.hpp:243
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.
Definition dhcp_option.hpp:483
const_iterator cend() const
get an iterator to the element following the last element of the list.
Definition dhcp_option.hpp:300
static const char * codeName(uint8_t code) noexcept
get the name of the given option.
Definition dhcp_option.cpp:127
bool contains(uint8_t code) const
check if there is an element identified by code in the list.
Definition dhcp_option.hpp:264
friend bool operator>=(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with greater or equal operator.
Definition dhcp_option.hpp:728
DhcpOption(const DhcpOption &other)=default
create instance by copy.
const_iterator find(uint8_t code) const
find the element with the given code.
Definition dhcp_option.hpp:254
std::map< uint8_t, DhcpOptionValue > Options
option list.
Definition dhcp_option.hpp:175
void swap(DhcpOption &other)
exchange the contents of the list with those of other.
Definition dhcp_option.hpp:380
friend bool operator>(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with greater operator.
Definition dhcp_option.hpp:706
void clear()
remove all elements from the list.
Definition dhcp_option.hpp:336
bool empty() const
check if the list has no element.
Definition dhcp_option.hpp:309
static bool invalid() noexcept
report an invalid option value.
Definition dhcp_option.hpp:513
DhcpOption(const_iterator first, const_iterator last)
create the DhcpOption instance with the elements from range.
Definition dhcp_option.hpp:190
std::string dump() const
dump the options in string format.
Definition dhcp_option.hpp:389
size_t erase(uint8_t code)
remove the element identified by code.
Definition dhcp_option.hpp:328
static bool convert(uint8_t code, const MacAddress &value, DhcpOptionValue &out)
store a hardware address in the given option.
Definition dhcp_option.hpp:605
friend bool operator<=(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with lower or equal operator.
Definition dhcp_option.hpp:717
void insert(const_iterator first, const_iterator last)
insert elements from range.
Definition dhcp_option.hpp:371
static bool convert(uint8_t code, const char *value, DhcpOptionValue &out)
convert a string to the type the given option carries.
Definition dhcp_option.hpp:573
~DhcpOption()=default
destroy the DhcpOption instance.
DhcpOption()=default
create the DhcpOption instance.
Options _options
options.
Definition dhcp_option.hpp:646
static bool convert(uint8_t code, const IpAddress &value, DhcpOptionValue &out)
store an IP address in the given option.
Definition dhcp_option.hpp:585
const_iterator begin() const
get an iterator to the first element of the list.
Definition dhcp_option.hpp:273
static void write(std::ostream &stream, uint8_t code, const DhcpOptionValue &value)
write an option value in string format.
Definition dhcp_option.cpp:137
const_iterator cbegin() const
get an iterator to the first element of the list.
Definition dhcp_option.hpp:282
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.
Definition dhcp_option.hpp:466
static bool accepts(const Info &info, uint32_t value) noexcept
check that a value satisfies the constraints of the given option.
Definition dhcp_option.hpp:445
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.
Definition dhcp_option.hpp:527
static const Info * describe(uint8_t code) noexcept
get the description of the given option.
Definition dhcp_option.cpp:41
DhcpOption & operator=(const DhcpOption &other)=default
assign instance by copy.
friend bool operator==(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with equal operator.
Definition dhcp_option.hpp:673
IPv6, IPv4 address class.
Definition ip_address.hpp:51
int family() const
get address family.
Definition ip_address.cpp:1250
MAC address class.
Definition mac_address.hpp:46
variant class.
Definition variant.hpp:352
Definition acceptor.hpp:32
bool operator<=(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is lower or equal.
Definition endpoint.hpp:234
bool operator==(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:186
std::vector< IpAddress > IpList
list of IP addresses.
Definition dhcp_option.hpp:51
std::vector< uint16_t > WordList
list of 16 bits words.
Definition dhcp_option.hpp:48
bool operator!=(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:198
bool operator>=(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is greater or equal.
Definition endpoint.hpp:246
std::ostream & operator<<(std::ostream &os, const BasicLinkLayerEndpoint< Protocol > &endpoint)
push endpoint representation into a stream.
Definition endpoint.hpp:258
bool operator<(const BasicDatagramSocket< Protocol > &a, const BasicDatagramSocket< Protocol > &b) noexcept
compare if socket handle is inferior.
Definition datagram_socket.hpp:394
std::error_code make_error_code(join::Errc code) noexcept
Create an std::error_code object.
Definition error.cpp:195
bool operator>(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoint is greater.
Definition endpoint.hpp:222
std::vector< uint8_t > ByteList
list of bytes.
Definition dhcp_option.hpp:45
description of an option.
Definition dhcp_option.hpp:165
uint32_t min
Definition dhcp_option.hpp:169
Type type
Definition dhcp_option.hpp:168
uint32_t mask
Definition dhcp_option.hpp:171
const char * name
Definition dhcp_option.hpp:167
uint32_t max
Definition dhcp_option.hpp:170
uint8_t code
Definition dhcp_option.hpp:166