|
join 1.0
lightweight network framework library
|
DHCP client. More...
#include <dhcp.hpp>


Classes | |
| struct | PendingRequest |
| message waiting for its answer. More... | |
Public Member Functions | |
| BasicDhcpClient ()=delete | |
| create the BasicDhcpClient instance. | |
| BasicDhcpClient (const std::string &interface, uint16_t maxSize=0, const std::string &hostname={}, Reactor &reactor=ReactorThread::reactor()) | |
| create the instance bound to the given interface. | |
| virtual | ~BasicDhcpClient ()=default |
| destroy the instance. | |
| DhcpPacket | compose (uint8_t type) const |
| build a message carrying what every message a client sends has in common. | |
| DhcpPacket::Ptr | exchange (DhcpPacket &request, const IpAddress &destination, uint8_t expected, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| send a message and wait for its answer. | |
| std::string | reason () const |
| get the reason the server gave for the last refusal. | |
| DhcpPacket::Ptr | discover (const IpAddress &wants=IpAddress::ipv4Wildcard, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| broadcast a DISCOVER message and wait for an OFFER. | |
| DhcpPacket::Ptr | request (const IpAddress &wants, const IpAddress &server, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| broadcast a REQUEST message and wait for an ACK. | |
| DhcpPacket::Ptr | renew (const IpAddress &client, const IpAddress &server, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| send a REQUEST message to the server holding the lease and wait for an ACK. | |
| DhcpPacket::Ptr | inform (const IpAddress &client, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| ask a server for the parameters of an externally configured address. | |
| int | release (const IpAddress &client, const IpAddress &server, std::chrono::milliseconds timeout=std::chrono::seconds(1)) |
| give a lease back to the server holding it. | |
| int | decline (const IpAddress &address, const IpAddress &server, const std::string &message={}) |
| tell the server that the address it offered is already in use. | |
Public Member Functions inherited from join::BasicDhcp< Protocol > | |
| 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 () |
| 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 | |
| void | onMessage (DhcpPacket::Ptr packet) override final |
| hand a received message to the request waiting for it. | |
Protected Member Functions inherited from join::BasicDhcp< Protocol > | |
| struct | __attribute__ ((packed)) Frame |
| link, internet and transport headers a DHCP message is framed with. | |
| struct | __attribute__ ((packed)) Pseudo |
| header the UDP checksum is computed over, RFC 768. | |
| void | onReadable (int fd) override final |
| method called when data are ready to be read. | |
| int | transmit (const DhcpPacket &packet, const IpAddress &source, const IpAddress &destination) |
| frame a message and write it on the wire. | |
| DhcpPacket::Ptr | receive (const char *data, size_t size) const |
| decode a frame received on the wire. | |
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 | 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. | |
Protected Attributes | |
| std::unordered_map< uint32_t, std::unique_ptr< PendingRequest > > | _pending |
| messages waiting for their answer, indexed by transaction identifier. | |
| Mutex | _syncMutex |
| mutex for synchronous operations. | |
| std::string | _reason |
| reason the server gave for the last refusal. | |
| const std::string | _hostname |
| host name to advertise. | |
| const uint16_t | _maxSize |
| biggest message the server may send back. | |
Protected Attributes inherited from join::BasicDhcp< Protocol > | |
| 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. | |
Static Protected Attributes | |
| static const ByteList | _defaultParams |
| options a client asks for by default. | |
Additional Inherited Members | |
Public Types inherited from join::BasicDhcp< Protocol > | |
| using | Socket = typename Protocol::Socket |
Static Protected Member Functions inherited from join::BasicDhcp< Protocol > | |
| static uint16_t | udpChecksum (const Frame &frame, const char *payload, size_t size) |
| compute the checksum of a UDP datagram, RFC 768. | |
DHCP client.
|
delete |
create the BasicDhcpClient instance.
|
inlineexplicit |
create the instance bound to the given interface.
| interface | interface name. |
| maxSize | biggest message the server may send back, zero to leave it unspecified. |
| hostname | host name to advertise, empty to advertise none. |
| reactor | reactor instance. |
| std::system_error | if the interface is unknown, the socket could not be bound to it, or the maximum message size is below what RFC 2132 allows. |
|
virtualdefault |
destroy the instance.
|
inline |
build a message carrying what every message a client sends has in common.
| type | message type. |
|
inline |
tell the server that the address it offered is already in use.
| address | address the client refuses. |
| server | address of the server that offered it. |
| message | human readable reason, empty to give none. |
|
inline |
broadcast a DISCOVER message and wait for an OFFER.
| wants | address the client would like to get, wildcard to let the server choose. |
| timeout | answer timeout. |
|
inline |
send a message and wait for its answer.
| request | message to send. |
| destination | destination address. |
| expected | message type the answer must carry. |
| timeout | answer timeout. |
|
inline |
ask a server for the parameters of an externally configured address.
| client | address the client already owns. |
| timeout | answer timeout. |
|
inlinefinaloverrideprotectedvirtual |
hand a received message to the request waiting for it.
| packet | message received. |
Implements join::BasicDhcp< Protocol >.
|
inline |
get the reason the server gave for the last refusal.
|
inline |
give a lease back to the server holding it.
| client | address the client currently owns. |
| server | address of the server holding the lease. |
| timeout | time allowed to resolve the server hardware address. |
|
inline |
send a REQUEST message to the server holding the lease and wait for an ACK.
| client | address the client currently owns. |
| server | address of the server holding the lease. |
| timeout | answer timeout. |
|
inline |
broadcast a REQUEST message and wait for an ACK.
| wants | address the client asks to be assigned. |
| server | address of the server the offer came from. |
| timeout | answer timeout. |
|
staticprotected |
options a client asks for by default.
|
protected |
host name to advertise.
|
protected |
biggest message the server may send back.
|
protected |
messages waiting for their answer, indexed by transaction identifier.
|
protected |
reason the server gave for the last refusal.
|
mutableprotected |
mutex for synchronous operations.