DNStest.c File Reference

Performs a DNS-lookup to get the IP-address from www.dsignt.de. More...

#include <BoardSupport/inc/stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <Libs/NETlib/net.h>
#include <BoardSupport/inc/BoardSpecific.h>
#include <Common/Common.h>
#include <Common/uartio.h>
#include <Common/timer.h>
#include <Common/CPrintf.h>
#include <BoardSupport/config/netconfig.c>

Macros

#define MAX_PING_DATA   100
 
#define HOST_NAME   "www.dsignt.de"
 

Functions

uint32_t resolve_name (char *hostname, int max_retry)
 
int main (void)
 

Variables

char * program_name = "DNS"
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Date
2019-06-04

The main DNS resolution is performed by function resolve_name():

host_address = resolve_name ("www.dsignt.de", 6);

The returned IP-address may be used for informational purpose or for creating a socket:

tcp_socket = socket_open (inet_ntoa (host_address, buffer),
                          ANY_PORT,
                          5031,
                          DATATYPE_CHAR,
                          TCP_INIT_FUNC);
Note
The DNS-lookup is already included with socket_open() function. For the same result as described above you can simply call:
tcp_socket = socket_open ("www.dsignt.de",
                          ANY_PORT,
                          5031,
                          DATATYPE_CHAR,
                          TCP_INIT_FUNC);

Macro Definition Documentation

#define MAX_PING_DATA   100
#define HOST_NAME   "www.dsignt.de"
Examples:
DNSTest.c.

Function Documentation

uint32_t resolve_name ( char *  hostname,
int  max_retry 
)
Examples:
DNSTest.c.
175 {
176  /***************************************************************************
177  locals
178  ***************************************************************************/
179  uint32_t ret = UINT32_C(0);
180  int32_t timeout;
181  int i;
182 
183  for ( i = 0; i < max_retry ; i++ )
184  {
185  CPrintChar ('.', 1);
186 
187  /***********************************************************************
188  configure timeout value to break the action if name resolution is not
189  possible
190  ***********************************************************************/
191  timeout = 500000;
192 
193  /***********************************************************************
194  resolve address:
195  ***********************************************************************/
196  ret = gethostbyname (hostname, &timeout);
197 
198  if ( ret ) // on success stop loop
199  {
200  break;
201  }
202  }
203 
204  return (ret);
205 }
void CPrintChar(const char symbol, size_t count)
Custom print char function.
Definition: cprintf.c:773
#define UINT32_C(value)
Definition: stdint.h:210
unsigned int uint32_t
Definition: stdint.h:47
uint32_t gethostbyname(char *hostname, int32_t *timeout)
Get the ip address of clients specified by name.
int int32_t
Definition: stdint.h:46
int main ( void  )
216 {
217  /***************************************************************************
218  locals
219  ***************************************************************************/
220  int main_loop = 1; /* main loop switch, set to 0 to exit */
221  timeval stamp1, stamp2, delta; /* used to determine startup time */
222  uint32_t host_address;
223  char buffer[20];
224 
225  /***************************************************************************
226  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
227  (ref. \Common\Common.c)
228  ***************************************************************************/
229  AppInit (GET_CLOCK);
230 
231  /***************************************************************************
232  select output device for CPrintf (ref. \Common\cprintf.c)
233  possible settings:
234  CPRINTF_UART_OUTPUT -> output to UART
235  CPRINTF_CCS_OUTPUT -> output to CCS
236  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
237  ***************************************************************************/
238  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
239 
240  /***************************************************************************
241  print a start up message
242  ***************************************************************************/
243  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
244 
245  /**************************************************************************/
246  // CPrintfProgress (" Heap check ");
247  // at least 0x2000 bytes required for this app
248  /**************************************************************************/
249  ASSERT_HEAP (initial_heap_size, 0x2000);
250  // CPrintfProgressSuccess();
251 
252  /**************************************************************************/
253  CPrintfProgress (" Setup system time ");
254  // 1 milli seconds resolution
255  /**************************************************************************/
258  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
260 
261  /**************************************************************************/
262  CPrintfProgress (" Enable interrupts ");
263  /**************************************************************************/
266 
267  /**************************************************************************/
268  CPrintfProgress (" Start system timer ");
269  /**************************************************************************/
270  StartSystemTimer ();
272  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
273 
274  /***************************************************************************
275  measure network initialization time
276  ***************************************************************************/
277  stamp1 = GetTimeStamp();
278 
279  /**************************************************************************/
280  CPrintfProgress (" Initialize network ");
281  /**************************************************************************/
282  InitializeNetwork ( MAX_PING_DATA); // MAX_PING_DATA bytes for ping
284 
285  stamp2 = GetTimeStamp();
286 
287  tv_interval (&delta, &stamp1, &stamp2);
288  CPuts (" network startup time [sec]: ");
290  "%"PRId32".%03"PRId32"\r\n"
292  delta.tv_sec,
293  delta.tv_usec/1000);
294 
295 
296  /***************************************************************************
297  wait for link and IP address
298  ***************************************************************************/
299  while ((_link == 0) || (get_ip_address (0) == UINT32_C(0)))
300  {
301  /***********************************************************************
302  perform progress bar animation each 200 milli second
303  ***********************************************************************/
304  CPrintProgressBarText ('.', 200000, 16, " waiting for link");
305 
306  net_isq ();
307 
308  /***********************************************************************
309  monitor link status
310  ***********************************************************************/
312  }
313 
314  CPrintf ("success\r\n try to resolve %s...\r\n", HOST_NAME);
315 
316  /***************************************************************************
317  resolve DSignT's IP
318  ***************************************************************************/
319  host_address = resolve_name (HOST_NAME, 6);
320 
321  if ( host_address == 0L )
322  {
323  CPuts (" address can not be resolved\r\n");
324  }
325  else
326  {
327  CPrintf (" resolved IP-address for %s: %s\r\n",
328  HOST_NAME,
329  inet_ntoa (host_address, buffer));
330  }
331 
332  /***************************************************************************
333  main program loop: set main_loop to 0 to exit loop
334  ***************************************************************************/
335  while ( main_loop )
336  {
337  net_isq ();
338 
339  /***********************************************************************
340  show that the program is running, perform symbol animation
341  ***********************************************************************/
343  }
344 
345  /***************************************************************************
346  exit program, shut down peripherals
347  ***************************************************************************/
348  return (0);
349 }
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
#define ANIMATE_SYMBOLS_COUNT
Definition: BoardSpecific.h:268
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
volatile uint16_t _link
Definition: BoardSpecific.c:143
#define RES_MSECONDS
Definition: timer.h:67
char * inet_ntoa(uint32_t i_addr, char *s)
Convert IP-address from 0xbbaaddcc to "aaa.bbb.ccc.ddd".
uint16_t CPrintf_select_output(uint16_t device)
Definition: cprintf.c:206
#define ASSERT_HEAP(i, h)
Definition: Common.h:262
uint32_t resolve_name(char *hostname, int max_retry)
Definition: DNStest.c:174
time_t GetSystemTimerRes(void)
Definition: timer.c:160
#define UINT32_C(value)
Definition: stdint.h:210
#define GET_CLOCK
Definition: BoardSpecific.h:258
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
#define VT100_DEFAULT
Definition: cprintf.h:150
void SetupSystemTime(int32_t cpuint, int port, time_t resolution)
Setup System Time.
Definition: timer.c:392
void AppInit(uint32_t dsp_clock)
Initialize application.
Definition: Common.c:230
uint32_t initial_heap_size
Definition: Common.c:140
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
#define VT100_RED
Definition: cprintf.h:143
uint16_t CPrintAnimatedSymbol(char *c, time_t period, size_t size)
Definition: cprintf.c:816
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
unsigned int uint32_t
Definition: stdint.h:47
static char buffer[100]
Definition: blocksend.c:158
char sym_animate[]
Definition: BoardSpecific.c:129
Definition: timer.h:75
#define GetTimeStamp()
Definition: timer.h:81
void tv_interval(timeval *e, timeval *t1, timeval *t2)
compute elapsed time
Definition: timer.c:336
#define SYSTEM_TIMER_INT
Definition: BoardSpecific.h:174
#define SYSTEM_TIMER
Definition: BoardSpecific.h:167
uint32_t get_ip_address(uint16_t dev_nr)
Get configured IP address.
void net_isq(void)
The main polling function for processing sockets, must be periodically called in the main application...
#define BLANK_REV
Definition: BoardSpecific.h:191
Uint16 SystemTimerDev
int32_t CPrintProgressBarText(char c, time_t period, size_t length, char *text)
Definition: cprintf.c:902
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
#define MAX_PING_DATA
Definition: DNStest.c:139
#define HOST_NAME
Definition: DNStest.c:144
#define RES_SECONDS
Definition: timer.h:70
uint16_t monitor_link_status(tpOutputFunc pLog)
monitor link status change
Definition: BoardSpecific.c:497
int CPuts(const char *_ptr)
Definition: cprintf.c:399
time_t tv_sec
Definition: timer.h:77
#define CPrintfProgress(s)
Definition: cprintf.h:230
time_t tv_usec
Definition: timer.h:78
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "DNS"