DHCPTest.c

DHCPTest.c example details

This application demonstrates the use of a DHCP client. The terminal- window should print on success:

  DSP IP-address before initializing: 0.0.0.0

  Link status changed: Linked at 100Mbit full duplex
  assigned DSP IP-address:192.168.168.123
  success

  DHCP demo running on address 192.168.168.123

  MAC address: 02-00-c1-31-00-34
  IP address:  192.168.168.123
  Host name:   mydemo
  Domain name: dsignt.net
  DNS Server:  192.168.168.1
  Gateway:     192.168.168.1
  Subnetmask:  255.255.255.0
  now ping the dsp:
 >ping 192.168.168.123    or
 >ping mydemo

The real assigned IP address depends on your DHCP configuration. If the DSP hangs for a while after the first line, your DHCP configuration may be wrong or no DHCP-server is reachable. In this case after about 20-30 seconds (and a few retries) a link-local address is assigned and a warning should appear on the screen:

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!! warning: no DHCP server available           !!!
 !!! assigned IP address is a link-local address !!!
 !!! make sure your host is in the same local    !!!
 !!! subnet: 169.254.x.x                         !!!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
See also
DHCP Dynamic Host Configuration Protocol
/***************************************************************************//**
@file DHCPtest.c
@brief Receiving DSP IP-address from DHCP-server.
@verbatim
_ _ _
__| | ___(_) ____ _ __ | |_
/ _` | / __| |/ _` | '_ \| __|
| (_| | _ \__ \ | (_| | | | | |_
\__,_|(_) ___/_|\__, |_| |_|\__|
Signalprocessing |___/ Technology
@endverbatim
@author D.SignT GmbH & Co. KG, Claus Hermbusche
@date 2019-06-04
@anchor DHCPTESTEX
@details
The terminal-window should print on success:
DSP IP-address before initializing: 0.0.0.0
Link status changed: Linked at 100Mbit full duplex
assigned DSP IP-address:192.168.168.123
success
DHCP demo running on address 192.168.168.123
MAC address: 02-00-c1-31-00-34
IP address: 192.168.168.123
Host name: mydemo
Domain name: dsignt.net
DNS Server: 192.168.168.1
Gateway: 192.168.168.1
Subnetmask: 255.255.255.0
now ping the dsp:
>ping 192.168.168.123 or
>ping mydemo
The real assigned IP address depends on your DHCP configuration. If the
DSP hangs for a while after the first line, your DHCP configuration may be
wrong or no DHCP-server is reachable. In this case after about 20-30
seconds (and a few retries) a link-local address is assigned and a warning
should appear on the screen:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! warning: no DHCP server available !!!
!!! assigned IP address is a link-local address !!!
!!! make sure your host is in the same local !!!
!!! subnet: 169.254.x.x !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@cond Software License Agreement
Copyright (C) 2001-2019 D.SignT GmbH & Co. KG - http://www.dsignt.de
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
Neither the name of D.SignT GmbH & Co. KG nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
Disclaimer
THIS SOFTWARE IS PROVIDED BY D.SIGNT GMBH & CO. KG "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL D.SIGNT GMBH & CO. KG BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@endcond
*******************************************************************************/
/*******************************************************************************
include stdtypes.h to avoid data type mismatch
*******************************************************************************/
/*******************************************************************************
include Runtime Source
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
/*******************************************************************************
network support functions
*******************************************************************************/
#include <Libs/NETlib/net.h> /* D.Module network support */
/*******************************************************************************
board specific functions
*******************************************************************************/
#include <BoardSupport/inc/BoardSpecific.h> /* board support functions */
/*******************************************************************************
common support functions
*******************************************************************************/
#include <Common/Common.h> /* on exit function */
#include <Common/uartio.h> /* UART support */
#include <Common/timer.h> /* timer setting */
#include <Common/CPrintf.h> /* CPrintf defines */
/*******************************************************************************
network configuration
*******************************************************************************/
#define USE_DHCP 1
#include <BoardSupport/config/netconfig.c> /* network configuration */
#ifdef __cplusplus
extern "C" {
#endif /* !__cplusplus */
/*******************************************************************************
local prototypes
*******************************************************************************/
#ifdef __cplusplus
} // extern "C"
#endif
/*******************************************************************************
* *
* DEFINES *
* *
*******************************************************************************/
/*******************************************************************************
MAX_PING_DATA is used to specify the maximum data to be pinged. For normal
operation a value 64 to 100 should be sufficient.
*******************************************************************************/
#define MAX_PING_DATA 100
/*******************************************************************************
* *
* GLOBALS *
* *
*******************************************************************************/
/*******************************************************************************
program name
*******************************************************************************/
char *program_name = "DHCP";
extern far char *host_name;
extern far char *domain_name;
/*******************************************************************************
* *
* FUNCTIONS *
* *
*******************************************************************************/
/*******************************************************************************
@brief Main application
@param -
@return never
*******************************************************************************/
#pragma CODE_SECTION(main , ".commontext");
int main ( void )
{
/***************************************************************************
locals
***************************************************************************/
int main_loop = 1; /* main loop switch, set to 0 to exit */
char buffer[20]; /* small buffer for ip-address conversion */
/***************************************************************************
initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
(ref. \Common\Common.c)
***************************************************************************/
/***************************************************************************
select output device for CPrintf (ref. \Common\cprintf.c)
possible settings:
CPRINTF_UART_OUTPUT -> output to UART
CPRINTF_CCS_OUTPUT -> output to CCS
CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
***************************************************************************/
/***************************************************************************
print a start up message
***************************************************************************/
/**************************************************************************/
// CPrintfProgress (" Heap check ");
// at least 0x2000 bytes required for this app
/**************************************************************************/
// CPrintfProgressSuccess();
/**************************************************************************/
CPrintfProgress (" Setup system time ");
// 1 milli seconds resolution
/**************************************************************************/
CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
/**************************************************************************/
CPrintfProgress (" Enable interrupts ");
/**************************************************************************/
/**************************************************************************/
CPrintfProgress (" Start system timer ");
/**************************************************************************/
CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
/***************************************************************************
print DSP IP address before initializing sockets:
***************************************************************************/
ip = get_ip_address (0);
CPrintf ("\r\n DSP IP-address before initializing: %s\r\n", inet_ntoa (ip, buffer));
/***************************************************************************
initialize network
***************************************************************************/
CPrintfProgress (" Initialize network ");
/***************************************************************************
The default network configuration for all examples are configured in file
\BoardSupport\netconfig.c. eth.ip contains either a fixed local IP address
string or a host name depending on switch USE_DHCP. Fill the eth.ip array
with a string starting with a letter to force InitializeNetwork() to use
DHCP. InitializeNetwork() appends the lower MAC address to form a unique
network name
***************************************************************************/
strcpy (eth.ip, "mydemo"); /* host name */
CPrintf (" Largest free heap block : %"PRIu32" bytes\r\n", GetFreeHeapSize ());
/***************************************************************************
main program loop: set main_loop to 0 to exit loop
***************************************************************************/
CPrintf ("\r\n Entering main loop ...");
while ( main_loop )
{
/***********************************************************************
process net_isq()
***********************************************************************/
net_isq (); // process ISQ
/***********************************************************************
monitor link status
***********************************************************************/
/***********************************************************************
try to detect IP assignment
if DHCP is used, the assigned IP address may change
***********************************************************************/
{
ip = get_ip_address (0);
CPrintf (" now ping the dsp:\r\n>ping %s", inet_ntoa (ip, buffer));
if (!IS_LINKLOCAL(ip))
{
CPrintf (" or\r\n>ping %s", host_name);
{
CPrintf (".%s", domain_name);
}
}
}
/***********************************************************************
show that the program is running, perform symbol animation
***********************************************************************/
}
/***************************************************************************
exit program, shut down peripherals
***************************************************************************/
return (0);
}