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

DHCP message codec. More...

#include <dhcp_message.hpp>

Public Types

enum  MessageType : uint8_t {
  Discover = 1 , Offer = 2 , Request = 3 , Decline = 4 ,
  Ack = 5 , Nak = 6 , Release = 7 , Inform = 8
}
 DHCP message types, RFC 2132 section 9.6. More...
 
enum  Operation : uint8_t { BootRequest = 1 , BootReply = 2 }
 DHCP operation codes. More...
 
enum  Flag : uint16_t { BroadcastFlag = 0x8000 }
 message flags. More...
 
enum  Overload : uint8_t { FileOverload = 1 , SnameOverload = 2 }
 option overload values. More...
 

Public Member Functions

int serialize (const DhcpPacket &packet, std::stringstream &data) const
 serialize a DHCP message into a byte stream.
 
int deserialize (DhcpPacket &packet, std::stringstream &data) const
 deserialize a DHCP message from a byte stream.
 

Static Public Attributes

static constexpr uint32_t magicCookie = 0x63825363
 magic cookie introducing the option field.
 
static constexpr size_t headerSize = 240
 size of the fixed part of a DHCP message, magic cookie included.
 
static constexpr size_t minMsgSize = 300
 smallest message a BOOTP implementation accepts, RFC 951 and RFC 1542 section 2.1.
 
static constexpr size_t maxOptionSize = 255
 biggest payload a single option can carry, its length field is one octet.
 

Protected Member Functions

int serialize (const DhcpOption &options, std::stringstream &data) const
 serialize an option list into a byte stream.
 
int deserialize (DhcpOption &options, std::stringstream &data) const
 deserialize an option list from a byte stream.
 
bool deserialize (DhcpOption &options, const char *field, size_t size) const
 deserialize an option list from an overloaded field.
 

Static Protected Member Functions

static bool writeHead (std::ostream &data, uint8_t code, size_t size)
 write an option header into a byte stream.
 
static void writeAddress (std::ostream &data, const IpAddress &address)
 write an IPv4 address into a byte stream.
 
static bool readAddress (std::istream &data, IpAddress &address)
 read an IPv4 address from a byte stream.
 
static bool extract (std::istream &data, void *out, size_t size)
 read a fixed amount of bytes from a byte stream.
 

Static Protected Attributes

static constexpr uint8_t _ethernet = 1
 hardware address type of an Ethernet link.
 
static constexpr size_t _chaddrSize = 16
 size of the client hardware address field.
 
static constexpr size_t _snameSize = 64
 size of the server name field.
 
static constexpr size_t _fileSize = 128
 size of the boot file name field.
 

Detailed Description

DHCP message codec.

Member Enumeration Documentation

◆ Flag

enum join::DhcpMessage::Flag : uint16_t

message flags.

Enumerator
BroadcastFlag 

the client asks to be answered by broadcast.

◆ MessageType

DHCP message types, RFC 2132 section 9.6.

Enumerator
Discover 

a client looking for a server.

Offer 

a server proposing an address.

Request 

a client asking for an address.

Decline 

a client refusing an address already in use.

Ack 

a server confirming an address.

Nak 

a server refusing a request.

Release 

a client giving an address back.

Inform 

a client asking for parameters only.

◆ Operation

DHCP operation codes.

Enumerator
BootRequest 

message sent by a client.

BootReply 

message sent by a server.

◆ Overload

option overload values.

Enumerator
FileOverload 

the file field carries options.

SnameOverload 

the sname field carries options.

Member Function Documentation

◆ deserialize() [1/3]

bool join::DhcpMessage::deserialize ( DhcpOption & options,
const char * field,
size_t size ) const
inlineprotected

deserialize an option list from an overloaded field.

Parameters
optionsoption list to deserialize into.
fieldfield holding the options to deserialize.
sizefield size.
Returns
true on success, false on failure.

◆ deserialize() [2/3]

int DhcpMessage::deserialize ( DhcpOption & options,
std::stringstream & data ) const
protected

deserialize an option list from a byte stream.

Parameters
optionsoption list to deserialize into.
databyte stream holding the options to deserialize.
Returns
0 on success, -1 on failure.

◆ deserialize() [3/3]

int join::DhcpMessage::deserialize ( DhcpPacket & packet,
std::stringstream & data ) const
inline

deserialize a DHCP message from a byte stream.

Parameters
packetDHCP message to deserialize into.
databyte stream holding the message to deserialize.
Returns
0 on success, -1 on failure.

◆ extract()

static bool join::DhcpMessage::extract ( std::istream & data,
void * out,
size_t size )
inlinestaticprotected

read a fixed amount of bytes from a byte stream.

Parameters
databyte stream to read from.
outbuffer to read into.
sizenumber of bytes to read.
Returns
true if every byte was read, false otherwise.

◆ readAddress()

static bool join::DhcpMessage::readAddress ( std::istream & data,
IpAddress & address )
inlinestaticprotected

read an IPv4 address from a byte stream.

Parameters
databyte stream to read from.
addressaddress read.
Returns
true on success, false on failure.

◆ serialize() [1/2]

int DhcpMessage::serialize ( const DhcpOption & options,
std::stringstream & data ) const
protected

serialize an option list into a byte stream.

Parameters
optionsoptions to serialize.
databyte stream to serialize the options into.
Returns
0 on success, -1 on failure.

◆ serialize() [2/2]

int join::DhcpMessage::serialize ( const DhcpPacket & packet,
std::stringstream & data ) const
inline

serialize a DHCP message into a byte stream.

Parameters
packetDHCP message to serialize.
databyte stream to serialize the message into.
Returns
0 on success, -1 on failure.

◆ writeAddress()

static void join::DhcpMessage::writeAddress ( std::ostream & data,
const IpAddress & address )
inlinestaticprotected

write an IPv4 address into a byte stream.

Parameters
databyte stream to write to.
addressaddress to write.

◆ writeHead()

bool DhcpMessage::writeHead ( std::ostream & data,
uint8_t code,
size_t size )
staticprotected

write an option header into a byte stream.

Parameters
databyte stream to write to.
codeoption code.
sizeoption payload size.
Returns
true if the payload fits in an option, false otherwise.

Member Data Documentation

◆ _chaddrSize

size_t join::DhcpMessage::_chaddrSize = 16
staticconstexprprotected

size of the client hardware address field.

◆ _ethernet

uint8_t join::DhcpMessage::_ethernet = 1
staticconstexprprotected

hardware address type of an Ethernet link.

◆ _fileSize

size_t join::DhcpMessage::_fileSize = 128
staticconstexprprotected

size of the boot file name field.

◆ _snameSize

size_t join::DhcpMessage::_snameSize = 64
staticconstexprprotected

size of the server name field.

◆ headerSize

size_t join::DhcpMessage::headerSize = 240
staticconstexpr

size of the fixed part of a DHCP message, magic cookie included.

◆ magicCookie

uint32_t join::DhcpMessage::magicCookie = 0x63825363
staticconstexpr

magic cookie introducing the option field.

◆ maxOptionSize

size_t join::DhcpMessage::maxOptionSize = 255
staticconstexpr

biggest payload a single option can carry, its length field is one octet.

◆ minMsgSize

size_t join::DhcpMessage::minMsgSize = 300
staticconstexpr

smallest message a BOOTP implementation accepts, RFC 951 and RFC 1542 section 2.1.


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