DNSTest.c example details
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);
- See also
- DNS Domain Name System
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#pragma CODE_SECTION(resolve_name , ".commontext")
#ifdef __cplusplus
}
#endif
#define MAX_PING_DATA 100
#define HOST_NAME "www.dsignt.de"
{
int i;
for ( i = 0; i < max_retry ; i++ )
{
timeout = 500000;
if ( ret )
{
break;
}
}
return (ret);
}
#pragma CODE_SECTION(main , ".commontext");
{
int main_loop = 1;
CPrintf (
" *** timer %d mapped to CPU int %d ***\r\n",
CPuts (
" network startup time [sec]: ");
"%"PRId32".%03"PRId32"\r\n"
{
}
if ( host_address == 0L )
{
CPuts (
" address can not be resolved\r\n");
}
else
{
CPrintf (
" resolved IP-address for %s: %s\r\n",
}
while ( main_loop )
{
}
return (0);
}