Embedded TCP/IP stack  3.9.4

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_init() function, the user application should call the main service-polling function fnet_poll_service() 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:

struct fnet_dhcp_params dhcp_params;
// Get current net interface.
if((netif = fnet_netif_get_default()) == 0)
fnet_printf("ERROR: Network Interface is not configurated!");
fnet_memset_zero(&dhcp_params, sizeof(struct fnet_dhcp_params));
// Enable DHCP client.
if(fnet_dhcp_init(netif, &dhcp_params))
// Register DHCP event handler callbacks.
fnet_dhcp_set_callback_updated(fapp_dhcp_callback_updated, shl);
fnet_dhcp_set_callback_discover(fapp_dhcp_callback_discover, shl);
fnet_printf("ERROR: DHCP initialization is failed!");

Configuration parameters:

Data Structures

struct  fnet_dhcp_params
 Initialization parameters for the fnet_dhcp_init() function. More...
struct  fnet_dhcp_options
 DHCP options are retrieved from a DHCP server. More...


 Infinite lease time.
The lease-option value, when a client acquires a lease for a network address for infinite time.

. More...

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


typedef fnet_int32_t fnet_dhcp_desc_t
 DHCP client descriptor. More...
typedef void(* fnet_dhcp_callback_t) (fnet_dhcp_desc_t desc, fnet_netif_desc_t netif, void *param)
 DHCP event handler callback function prototype, that is called when the DHCP client has updated the IP parameters (in BOUND state) or sends the DHCP discover message.. More...


fnet_dhcp_desc_t fnet_dhcp_init (fnet_netif_desc_t netif, struct fnet_dhcp_params *params)
 Initializes the DHCP client service. More...
void fnet_dhcp_release (fnet_dhcp_desc_t desc)
 Releases the DHCP client service. More...
void fnet_dhcp_get_options (fnet_dhcp_desc_t desc, struct fnet_dhcp_options *options)
 Retrieves the current DHCP client options retrieved from a DHCP server. More...
void fnet_dhcp_set_callback_updated (fnet_dhcp_desc_t desc, fnet_dhcp_callback_t callback_updated, void *param)
 Registers the "IP parameters updated" DHCP event handler callback. More...
void fnet_dhcp_set_callback_discover (fnet_dhcp_desc_t desc, fnet_dhcp_callback_t callback_discover, void *param)
 Registers the "Discover message sent" DHCP event handler callback. More...
fnet_bool_t fnet_dhcp_is_enabled (fnet_dhcp_desc_t desc)
 Detects if the DHCP Client service is enabled or disabled. More...

© 2005-2017 by Andrey Butok. http://fnet.sourceforge.net