DNS Domain Name System

Functions

uint32_t gethostbyname (char *hostname, int32_t *timeout)
 Get the ip address of clients specified by name. More...
 

Detailed Description

DNS Domain Name System

To enable the DNS lookup system net_init() must be called with parameter DNS_ENABLE and a DNS server address (ref. Software Initialization):

DNS server = 192.168.1.1

net_init ("192.168.1.100", "255.255.255.0", NULL, NULL, "192.168.1.1", DNS_ENABLE);

A hostname is automatically resolved when specified with socket_open(). E.g.:

tcp_socket = socket_open ("www.dsignt.de",
5031,

Also gethostbyname() can be used to determine the destination IP address:

int32_t timeout = 1000000;
uint32_t host_address;
host_address = gethostbyname ("www.dsignt.de", &timeout);
if (host_address)
{
tcp_socket = socket_open (inet_ntoa (host_address, buffer),
5031,
}
else
{
printf ("www.dsignt.de can not be resolved\r\n");
}

Function Documentation

uint32_t gethostbyname ( char *  hostname,
int32_t timeout 
)
Parameters
hostname- host name string
timeout- maximum loop count for this blocking function
Returns
  • FALSE - address resolution not possible
  • host address on successful name resolution

Get the ip address of clients specified by name

Library:
net.lib
Prototype:
net.h
//****************************************************************************
//
// @brief perform DNS lookup
//
// @param hostname - name to resolve
// @param max_retry - number of retries (useful on dial-up connection)
// @return resolved IP-address on success or zero (0) on error
// @sa gethostbyname() - netlib
//
//****************************************************************************
uint32_t resolve_name ( char *hostname, int max_retry )
{
//**************************************************************************
// locals
//**************************************************************************
uint32_t ret = 0;
int32_t timeout;
int i;
for ( i = 0; i < max_retry ; i++ )
{
CPrintf (".");
//************************************************************************
// configure timeout value to stop the loop if name resolution is not
// possible
//************************************************************************
timeout = 500000;
//************************************************************************
// resolve address:
//************************************************************************
ret = gethostbyname (hostname, &timeout);
if ( ret ) // on success stop loop
{
break;
}
}
return (ret);
}
Examples:
DNSTest.c.