COSA
An Object-Oriented Platform for Arduino Programming
DHCP Class Reference

#include <DHCP.hh>

Collaboration diagram for DHCP:
Collaboration graph

Public Member Functions

 DHCP (const char *hostname, const uint8_t *mac)
 
bool begin (Socket *sock)
 
bool end ()
 
int discover ()
 
int request (uint8_t ip[4], uint8_t subnet[4], uint8_t gateway[4])
 
int renew (Socket *sock)
 
int release (Socket *sock)
 
uint32_t lease_obtained () const
 
uint32_t lease_expires () const
 
const uint8_t * dhcp_addr () const
 
const uint8_t * dns_addr () const
 
const uint8_t * gateway_addr () const
 

Static Public Attributes

static const uint16_t PORT = 68
 

Detailed Description

Dynamic Host Configuration Protocol. Supports dynamic assignment of network address. Used with connection-less socket to configure a client with network address and subnet mask. Also provides network addresses for DHCP and DNS server.

Definition at line 33 of file DHCP.hh.

Constructor & Destructor Documentation

DHCP::DHCP ( const char *  hostname,
const uint8_t *  mac 
)

Construct DHCP client access with given hostname and hardware address.

Parameters
[in]hostnamestring in program memory.
[in]machardware address in program memory.

Definition at line 25 of file DHCP.cpp.

Member Function Documentation

bool DHCP::begin ( Socket sock)

Start interaction with DHCP server. Provide UDP socket with DHCP client port. Returns true if successful otherwise false.

Parameters
[in]sockconnection-less socket (UDP/DHCPPORT).
Returns
bool, true if successful otherwise false.

Definition at line 180 of file DHCP.cpp.

const uint8_t* DHCP::dhcp_addr ( ) const
inline

Return network address of DHCP server.

Definition at line 115 of file DHCP.hh.

int DHCP::discover ( )

Discover DHCP servers and receive client network address offer. Return zero if successful otherwise a negative error code; -1 not initiated, -2 discover failed, -3 no response.

Returns
zero if successful otherwise a negative error code.

Definition at line 197 of file DHCP.cpp.

const uint8_t* DHCP::dns_addr ( ) const
inline

Return network address of DNS server.

Definition at line 121 of file DHCP.hh.

bool DHCP::end ( )

Stop interaction with DHCP server. Closes socket. Maintains state so that the client network address lease may be renewed. Returns true if successful otherwise false.

Definition at line 188 of file DHCP.cpp.

const uint8_t* DHCP::gateway_addr ( ) const
inline

Return network address of gateway (router).

Definition at line 127 of file DHCP.hh.

uint32_t DHCP::lease_expires ( ) const
inline

Return time when lease will expire.

Definition at line 109 of file DHCP.hh.

uint32_t DHCP::lease_obtained ( ) const
inline

Return time when lease was obtained.

Definition at line 103 of file DHCP.hh.

int DHCP::release ( Socket sock)

Release the granted network address lease from successful request(). Returns zero if successful otherwise a negative error code; -1 illegal state, -2 request failed, -3 no response. The given socket is closed and the DHCP client handler is put in idle state.

Parameters
[in]sockconnection-less socket to use for release.
Returns
zero if successful otherwise a negative error code.

Definition at line 235 of file DHCP.cpp.

int DHCP::renew ( Socket sock)

Renew the granted network address lease from successful request(). Returns zero if successful otherwise a negative error code; -1 illegal state, -2 request failed, -3 no response.

Parameters
[in]sockconnection-less socket to use for release.
Returns
zero if successful otherwise a negative error code.

Definition at line 220 of file DHCP.cpp.

int DHCP::request ( uint8_t  ip[4],
uint8_t  subnet[4],
uint8_t  gateway[4] 
)

Accept the offer provided by DHCP server on successful discover(). Return zero if successful otherwise a negative error code; -1 not initiated, -2 request failed, -3 no response. Client network address and subnet mask are returned in given reference parameters.

Parameters
[in,out]ipgranted network address.
[in,out]subnetmask.
[in,out]gatewaynetwork address.
Returns
zero if successful otherwise a negative error code.

Definition at line 206 of file DHCP.cpp.

Member Data Documentation

const uint16_t DHCP::PORT = 68
static

DHCP Client port numbers.

Definition at line 36 of file DHCP.hh.


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