DHCP Dynamic Host Configuration Protocol

Macros

#define IS_LINKLOCAL(a)   ((a & 0xffff0000) == 0xfea90000 )
 

Detailed Description

DHCP Dynamic Host Configuration Protocol

A DHCP server will automatically supply all the required address settings. DHCP requires the use of symbolic hostnames, since the IP address of a machine may change if restarted after the DHCP lease time is expired. Hence, a DHCP-based network always requires a DNS server for name resolution. The DNS server IP address however is provided by DHCP and must not be specified manually. The net_init() call with enabled DHCP is:

net_init ("dsk.company.net", NULL, NULL, DHCP_ENABLE, NULL, DNS_ENABLE);

Parameter DHCP_ENABLE makes net_init() a blocking call. It blocks until a new local IP address was assigned by a DHCP server or a timeout occurred when no DHCP server was available. In case of timeout the device automatically selects a free link-local address within subnet 169.254.x.x.

The netconfig.c settings for DHCP are:

static char dsp_ip_addr[] = "dsk.company.net";
static char dns_server_ip[] = NULL;
uint32_t (*dns_setting)(void) = DNS_ENABLE;
uint32_t (*dhcp_setting)(char *, uint32_t)= DHCP_ENABLE;

Replace dsk.company.net with the host name for your device. You must specify the "fully qualified hostname", including the domain name (company.net in this example). If you are not sure about the domain name, ask your network administrator or execute the Windows PC program winipcfg.exe or ipconfig.exe. Host Information will display the fully qualified hostname of your PC.

Since DHCP also provides the local subnet mask and the default gateway, calling net_set_gateway() to set these parameters is obsolete and not required in this configuration.

Use macro IS_LINKLOCAL(ip) to determine if a DHCP server was available or not.

if ( !net_init (dsp_ip_addr, NULL, NULL, dhcp_setting, dns_server_ip, dns_setting))
{
prg_exit ("net_init() failed"); // out of memory, try to increase heap
}
CPrintf (" assigned DSP IP-address:%s\r\n", inet_ntoa (ip, buffer));
if (IS_LINKLOCAL(ip))
{
CPrintf (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n");
CPrintf (" !!! warning: no DHCP server available !!!\r\n");
CPrintf (" !!! assigned IP address is a link-local address !!!\r\n");
CPrintf (" !!! make sure your host is in the same local !!!\r\n");
CPrintf (" !!! subnet: 169.254.x.x !!!\r\n");
CPrintf (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n");
}

Refer to Software Initialization for further initialization details

Macro Definition Documentation

#define IS_LINKLOCAL (   a)    ((a & 0xffff0000) == 0xfea90000 )

Macro for testing link-local addresses

Examples:
BoardSpecific.c, and DHCPTest.c.