join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicDhcp< Protocol > Class Template Reference

carries DHCP messages over a packet socket. More...

#include <dhcp.hpp>

Inheritance diagram for join::BasicDhcp< Protocol >:
Collaboration diagram for join::BasicDhcp< Protocol >:

Public Types

using Socket = typename Protocol::Socket
 

Public Member Functions

 BasicDhcp ()=delete
 create the BasicDhcp instance.
 
 BasicDhcp (const std::string &interface, Reactor &reactor=ReactorThread::reactor())
 create the instance bound to the given interface.
 
 BasicDhcp (const BasicDhcp &other)=delete
 create instance by copy.
 
BasicDhcp & operator= (const BasicDhcp &other)=delete
 assign instance by copy.
 
 BasicDhcp (BasicDhcp &&other)=delete
 create instance by move.
 
BasicDhcp & operator= (BasicDhcp &&other)=delete
 assign instance by move.
 
virtual ~BasicDhcp ()=default
 destroy the instance.
 
const std::string & interface () const noexcept
 get the name of the interface the instance is bound to.
 
const MacAddress & hardware () const noexcept
 get the hardware address of the interface the instance is bound to.
 
- Public Member Functions inherited from join::EventHandler
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandler & operator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandler & operator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Protected Member Functions

struct __attribute__ ((packed, aligned(2))) Frame
 link, internet and transport headers a DHCP message is framed with.
 
struct __attribute__ ((packed, aligned(2))) Pseudo
 header the UDP checksum is computed over, RFC 768.
 
void attach ()
 register with the reactor, to be called by the final class once fully constructed.
 
void detach () noexcept
 unregister from the reactor, to be called by the final class before destruction starts.
 
int send (const char *data, size_t size, const MacAddress &to, const IpAddress &source, const IpAddress &destination) noexcept
 frame a message and write it on the wire.
 
ssize_t receive (char *data, size_t maxSize, MacAddress &from, MacAddress &to) noexcept
 read a message that passed the link, internet and transport checks.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onEvent (int fd, uint32_t revents)
 method called when events are reported on handle.
 
virtual void onReadable (int fd)
 method called when data are ready to be read on handle.
 
virtual void onWriteable (int fd)
 method called when data are ready to be written on handle.
 
virtual void onClose (int fd)
 method called when handle was closed by the peer.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 

Static Protected Member Functions

static uint16_t udpChecksum (const Frame &frame, const char *payload, size_t size) noexcept
 compute the checksum of a UDP datagram, RFC 768.
 

Protected Attributes

Socket _socket
 underlying socket.
 
DhcpMessage _message
 DHCP message codec.
 
std::unique_ptr< char[]> _buffer
 receive buffer.
 
const std::string _interface
 interface name.
 
const MacAddress _hardware
 hardware address of the interface.
 
Reactor & _reactor
 event loop reactor.
 

Detailed Description

template<class Protocol>
class join::BasicDhcp< Protocol >

carries DHCP messages over a packet socket.

Member Typedef Documentation

◆ Socket

template<class Protocol >
using join::BasicDhcp< Protocol >::Socket = typename Protocol::Socket

Constructor & Destructor Documentation

◆ BasicDhcp() [1/4]

template<class Protocol >
join::BasicDhcp< Protocol >::BasicDhcp ( )
delete

create the BasicDhcp instance.

◆ BasicDhcp() [2/4]

template<class Protocol >
join::BasicDhcp< Protocol >::BasicDhcp ( const std::string & interface,
Reactor & reactor = ReactorThread::reactor () )
inlineexplicit

create the instance bound to the given interface.

Parameters
interfaceinterface name.
reactorreactor instance.
Exceptions
std::system_errorif the interface is unknown or the socket could not be bound to it.

◆ BasicDhcp() [3/4]

template<class Protocol >
join::BasicDhcp< Protocol >::BasicDhcp ( const BasicDhcp< Protocol > & other)
delete

create instance by copy.

Parameters
otherother object to copy.

◆ BasicDhcp() [4/4]

template<class Protocol >
join::BasicDhcp< Protocol >::BasicDhcp ( BasicDhcp< Protocol > && other)
delete

create instance by move.

Parameters
otherother object to move.

◆ ~BasicDhcp()

template<class Protocol >
virtual join::BasicDhcp< Protocol >::~BasicDhcp ( )
virtualdefault

destroy the instance.

Member Function Documentation

◆ __attribute__() [1/2]

template<class Protocol >
struct join::BasicDhcp< Protocol >::__attribute__ ( (packed, aligned(2)) )
inlineprotected

link, internet and transport headers a DHCP message is framed with.

◆ __attribute__() [2/2]

template<class Protocol >
struct join::BasicDhcp< Protocol >::__attribute__ ( (packed, aligned(2)) )
inlineprotected

header the UDP checksum is computed over, RFC 768.

◆ attach()

template<class Protocol >
void join::BasicDhcp< Protocol >::attach ( )
inlineprotected

register with the reactor, to be called by the final class once fully constructed.

Exceptions
std::system_errorif the registration failed.

◆ detach()

template<class Protocol >
void join::BasicDhcp< Protocol >::detach ( )
inlineprotectednoexcept

unregister from the reactor, to be called by the final class before destruction starts.

◆ hardware()

template<class Protocol >
const MacAddress & join::BasicDhcp< Protocol >::hardware ( ) const
inlinenoexcept

get the hardware address of the interface the instance is bound to.

Returns
the hardware address.

◆ interface()

template<class Protocol >
const std::string & join::BasicDhcp< Protocol >::interface ( ) const
inlinenoexcept

get the name of the interface the instance is bound to.

Returns
the interface name.

◆ operator=() [1/2]

template<class Protocol >
BasicDhcp & join::BasicDhcp< Protocol >::operator= ( BasicDhcp< Protocol > && other)
delete

assign instance by move.

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

◆ operator=() [2/2]

template<class Protocol >
BasicDhcp & join::BasicDhcp< Protocol >::operator= ( const BasicDhcp< Protocol > & other)
delete

assign instance by copy.

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

◆ receive()

template<class Protocol >
ssize_t join::BasicDhcp< Protocol >::receive ( char * data,
size_t maxSize,
MacAddress & from,
MacAddress & to )
inlineprotectednoexcept

read a message that passed the link, internet and transport checks.

Parameters
databuffer used to store the message.
maxSizemaximum number of bytes to read.
fromlink layer address the message came from.
tolink layer address the message was sent to.
Returns
the message size, -1 if nothing valid was read.

◆ send()

template<class Protocol >
int join::BasicDhcp< Protocol >::send ( const char * data,
size_t size,
const MacAddress & to,
const IpAddress & source,
const IpAddress & destination )
inlineprotectednoexcept

frame a message and write it on the wire.

Parameters
datamessage to write.
sizemessage size.
tolink layer destination address.
sourcesource address.
destinationdestination address.
Returns
0 on success, -1 on failure.

◆ udpChecksum()

template<class Protocol >
static uint16_t join::BasicDhcp< Protocol >::udpChecksum ( const Frame & frame,
const char * payload,
size_t size )
inlinestaticprotectednoexcept

compute the checksum of a UDP datagram, RFC 768.

Parameters
frameframe carrying the datagram, its checksum field must be zero.
payloaddatagram payload.
sizepayload size.
Returns
the checksum.

Member Data Documentation

◆ _buffer

template<class Protocol >
std::unique_ptr<char[]> join::BasicDhcp< Protocol >::_buffer
protected

receive buffer.

◆ _hardware

template<class Protocol >
const MacAddress join::BasicDhcp< Protocol >::_hardware
protected

hardware address of the interface.

◆ _interface

template<class Protocol >
const std::string join::BasicDhcp< Protocol >::_interface
protected

interface name.

◆ _message

template<class Protocol >
DhcpMessage join::BasicDhcp< Protocol >::_message
protected

DHCP message codec.

◆ _reactor

template<class Protocol >
Reactor& join::BasicDhcp< Protocol >::_reactor
protected

event loop reactor.

◆ _socket

template<class Protocol >
Socket join::BasicDhcp< Protocol >::_socket
protected

underlying socket.


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