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

ssize_t serialize (const DhcpPacket &packet, char *data, size_t maxSize) const
 serialize a DHCP message into a buffer.
 
int deserialize (DhcpPacket &packet, const char *data, size_t size) const
 deserialize a DHCP message from a buffer.
 

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, char *&cur, const char *end) const
 serialize an option list into a buffer.
 
int deserialize (DhcpOption &options, const char *cur, const char *end) const
 deserialize an option list from a buffer.
 

Static Protected Member Functions

static bool writeHead (char *&cur, const char *end, uint8_t code, size_t size)
 write an option header into a buffer.
 
static bool writeAddress (char *&cur, const char *end, const IpAddress &address)
 write an IPv4 address into a buffer.
 
static bool readAddress (const char *&cur, const char *end, IpAddress &address)
 read an IPv4 address from a buffer.
 

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/2]

int DhcpMessage::deserialize ( DhcpOption & options,
const char * cur,
const char * end ) const
protected

deserialize an option list from a buffer.

Parameters
optionsoption list to deserialize into.
curbeginning of the options.
endend of the options.
Returns
0 on success, -1 on failure.

◆ deserialize() [2/2]

int join::DhcpMessage::deserialize ( DhcpPacket & packet,
const char * data,
size_t size ) const
inline

deserialize a DHCP message from a buffer.

Parameters
packetDHCP message to deserialize into.
databuffer holding the message to deserialize.
sizemessage size.
Returns
0 on success, -1 on failure.

◆ readAddress()

static bool join::DhcpMessage::readAddress ( const char *& cur,
const char * end,
IpAddress & address )
inlinestaticprotected

read an IPv4 address from a buffer.

Parameters
curcurrent position in the buffer, advanced on success.
endend of the buffer.
addressaddress read.
Returns
true on success, false on failure.

◆ serialize() [1/2]

int DhcpMessage::serialize ( const DhcpOption & options,
char *& cur,
const char * end ) const
protected

serialize an option list into a buffer.

Parameters
optionsoptions to serialize.
curcurrent position in the buffer, advanced on success.
endend of the buffer.
Returns
0 on success, -1 on failure.

◆ serialize() [2/2]

ssize_t join::DhcpMessage::serialize ( const DhcpPacket & packet,
char * data,
size_t maxSize ) const
inline

serialize a DHCP message into a buffer.

Parameters
packetDHCP message to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
Returns
the message size, -1 on failure.

◆ writeAddress()

static bool join::DhcpMessage::writeAddress ( char *& cur,
const char * end,
const IpAddress & address )
inlinestaticprotected

write an IPv4 address into a buffer.

Parameters
curcurrent position in the buffer, advanced on success.
endend of the buffer.
addressaddress to write.
Returns
true on success, false if the buffer is too small.

◆ writeHead()

bool DhcpMessage::writeHead ( char *& cur,
const char * end,
uint8_t code,
size_t size )
staticprotected

write an option header into a buffer.

Parameters
curcurrent position in the buffer, advanced on success.
endend of the buffer.
codeoption code.
sizeoption payload size.
Returns
true on success, false if the payload does not fit in an option or the header in the buffer.

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: