Embedded TCP/IP stack  4.7.0
DHCPv4/BOOTP client API

Detailed Description

The user application can use the DHCP-client service to retrieve various network parameters (IP address, gateway address, subnet mask) from a DHCP server.
The DHCP client code keeps the IP address parameters updated by renewing it automatically, without user application intervention.

After the DHCP client is initialized by calling the fnet_dhcp_cln_init() function, the user application should call the main service-polling function fnet_service_poll() periodically in background.

The DHCP client will be released automatically if an application sets any of the IP-related parameters directly by the fnet_netif_set_ip4_addr() or fnet_netif_set_ip4_gateway() calls.

For example:

...
// Get current net interface.
if((netif = fnet_netif_get_default()) == 0)
{
fnet_printf("ERROR: Network Interface is not configurated!");
}
else
{
fnet_memset_zero(&dhcp_params, sizeof(dhcp_params));
dhcp_params.netif = netif;
// Enable DHCP client.
if(fnet_dhcp_cln_init(&dhcp_params))
{
// Register DHCP event handler callbacks.
fnet_dhcp_cln_set_callback_updated(fapp_dhcp_cln_callback_updated_boottime, shl);
fnet_dhcp_cln_set_callback_discover(fapp_dhcp_cln_callback_discover, shl);
}
else
{
fnet_printf("ERROR: DHCP initialization is failed!");
}
}
...


Configuration parameters:

Data Structures

struct  fnet_dhcp_cln_params_t
 Initialization parameters for the fnet_dhcp_cln_init() function. More...
 
struct  fnet_dhcp_cln_options
 DHCP options are retrieved from a DHCP server. More...
 

Macros

#define FNET_DHCP_CLN_LEASE_INFINITY   (0xFFFFFFFFU)
 Infinite lease time.
The lease-option value, when a client acquires a lease for a network address for infinite time.

. More...

 
#define FNET_DHCP_CLN_LEASE_MIN
 Minimum lease-time value in seconds.
If a client-acquired lease time is less than the FNET_DHCP_CLN_LEASE_MIN, the lease time will be pushed to the FNET_DHCP_CLN_LEASE_MIN value. More...
 

Typedefs

typedef void * fnet_dhcp_cln_desc_t
 DHCPv4 client descriptor. More...
 
typedef void(* fnet_dhcp_cln_callback_t) (fnet_dhcp_cln_desc_t desc, fnet_netif_desc_t netif, void *cookie)
 DHCP client event handler callback function prototype, that is called when the DHCP client has updated the IPv4 parameters (in BOUND state) or sends the DHCP discover message. More...
 

Functions

fnet_dhcp_cln_desc_t fnet_dhcp_cln_init (fnet_dhcp_cln_params_t *params)
 Initialize the DHCPv4 client service. More...
 
void fnet_dhcp_cln_release (fnet_dhcp_cln_desc_t desc)
 Release the DHCPv4 client service. More...
 
void fnet_dhcp_cln_get_options (fnet_dhcp_cln_desc_t desc, struct fnet_dhcp_cln_options *options)
 Retrieve the current DHCPv4 client options retrieved from a DHCP server. More...
 
void fnet_dhcp_cln_set_callback_updated (fnet_dhcp_cln_desc_t desc, fnet_dhcp_cln_callback_t callback_updated, void *cookie)
 Register the "IP parameters updated" DHCP event handler callback. More...
 
void fnet_dhcp_cln_set_callback_discover (fnet_dhcp_cln_desc_t desc, fnet_dhcp_cln_callback_t callback_discover, void *cookie)
 Register the "Discover message sent" DHCP event handler callback. More...
 
void fnet_dhcp_cln_set_response_timeout (fnet_dhcp_cln_desc_t desc, fnet_time_t response_timout_ms)
 Change timeout for a DHCP server response. More...
 
fnet_bool_t fnet_dhcp_cln_is_enabled (fnet_dhcp_cln_desc_t desc)
 Detect if the DHCP Client service is enabled or disabled. More...
 
fnet_dhcp_cln_desc_t fnet_dhcp_cln_get_by_netif (fnet_netif_desc_t netif)
 Look for a DHCP Client assigned to the specified network interface. More...
 

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net