1 /* This is a small demo of DNS Client for the high-performance NetX TCP/IP stack.  */
2 
3 #include   "tx_api.h"
4 #include   "nx_api.h"
5 #include   "nx_udp.h"
6 #include   "nxd_dns.h"
7 
8 #ifdef FEATURE_NX_IPV6
9 #include   "nx_ipv6.h"
10 #endif
11 
12 #define     DEMO_STACK_SIZE         4096
13 
14 #define     NX_PACKET_PAYLOAD       1536
15 #define     NX_PACKET_POOL_SIZE     30 * NX_PACKET_PAYLOAD
16 #define     LOCAL_CACHE_SIZE        2048
17 
18 /* Define the ThreadX and NetX object control blocks...  */
19 
20 NX_DNS                  client_dns;
21 TX_THREAD               client_thread;
22 NX_IP                   client_ip;
23 NX_PACKET_POOL          main_pool;
24 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
25 NX_PACKET_POOL          client_pool;
26 #endif
27 UCHAR                   local_cache[LOCAL_CACHE_SIZE];
28 
29 UINT                    error_counter = 0;
30 
31 #ifdef FEATURE_NX_IPV6
32 /* If IPv6 is enabled in NetX Duo, allow DNS Client to try using IPv6
33 #define USE_IPV6
34 */
35 #endif
36 
37 #define CLIENT_ADDRESS      IP_ADDRESS(192,168,0,11)
38 #define DNS_SERVER_ADDRESS  IP_ADDRESS(192,168,0,1)
39 
40 /* Define thread prototypes.  */
41 
42 void    thread_client_entry(ULONG thread_input);
43 
44 /***** Substitute your ethernet driver entry function here *********/
45 extern  VOID _nx_ram_network_driver(NX_IP_DRIVER *driver_req_ptr);
46 
47 
48 /* Define main entry point.  */
49 
main()50 int main()
51 {
52 
53     /* Enter the ThreadX kernel.  */
54     tx_kernel_enter();
55 }
56 
57 
58 /* Define what the initial system looks like.  */
59 
tx_application_define(void * first_unused_memory)60 void    tx_application_define(void *first_unused_memory)
61 {
62 
63 CHAR    *pointer;
64 UINT    status;
65 
66 
67     /* Setup the working pointer.  */
68     pointer =  (CHAR *) first_unused_memory;
69 
70     /* Create the main thread.  */
71     tx_thread_create(&client_thread, "Client thread", thread_client_entry, 0,
72             pointer, DEMO_STACK_SIZE, 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
73 
74     pointer =  pointer + DEMO_STACK_SIZE;
75 
76     /* Initialize the NetX system.  */
77     nx_system_initialize();
78 
79 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
80 
81     /* Create the packet pool for the DNS Client to send packets.
82 
83         If the DNS Client is configured for letting the host application create
84         the DNS packet pool, (see NX_DNS_CLIENT_USER_CREATE_PACKET_POOL option), see
85        nx_dns_create() for guidelines on packet payload size and pool size.
86        packet traffic for NetX processes.
87     */
88     status =  nx_packet_pool_create(&client_pool, "DNS Client Packet Pool", NX_DNS_PACKET_PAYLOAD, pointer, NX_DNS_PACKET_POOL_SIZE);
89 
90     pointer = pointer + NX_DNS_PACKET_POOL_SIZE;
91 
92     /* Check for pool creation error.  */
93     if (status)
94     {
95 
96         error_counter++;
97         return;
98      }
99 #endif
100 
101     /* Create the packet pool which the IP task will use to send packets. Also available to the host
102        application to send packet. */
103     status =  nx_packet_pool_create(&main_pool, "Main Packet Pool", NX_PACKET_PAYLOAD, pointer, NX_PACKET_POOL_SIZE);
104 
105     pointer = pointer + NX_PACKET_POOL_SIZE;
106 
107     /* Check for pool creation error.  */
108     if (status)
109     {
110 
111         error_counter++;
112         return;
113      }
114 
115     /* Create an IP instance for the DNS Client.  */
116     status = nx_ip_create(&client_ip, "DNS Client IP Instance", CLIENT_ADDRESS, 0xFFFFFF00UL,
117                           &main_pool, _nx_ram_network_driver, pointer, 2048, 1);
118 
119     pointer =  pointer + 2048;
120 
121     /* Check for IP create errors.  */
122     if (status)
123     {
124 
125         error_counter++;
126         return;
127      }
128 
129 #ifndef NX_DISABLE_IPV4
130     /* Enable ARP and supply ARP cache memory for the DNS Client IP.  */
131     status =  nx_arp_enable(&client_ip, (void *) pointer, 1024);
132     pointer = pointer + 1024;
133 
134     /* Check for ARP enable errors.  */
135     if (status)
136     {
137 
138         error_counter++;
139         return;
140      }
141 #endif /* NX_DISABLE_IPV4 */
142 
143     /* Enable UDP traffic because DNS is a UDP based protocol.  */
144     status =  nx_udp_enable(&client_ip);
145 
146     /* Check for UDP enable errors.  */
147     if (status)
148     {
149 
150         error_counter++;
151         return;
152      }
153 }
154 
155 #define BUFFER_SIZE     200
156 #define RECORD_COUNT    10
157 
158 /* Define the Client thread.  */
159 
thread_client_entry(ULONG thread_input)160 void    thread_client_entry(ULONG thread_input)
161 {
162 
163 UCHAR           record_buffer[200];
164 UINT            record_count;
165 UINT            status;
166 ULONG           host_ip_address;
167 #ifdef FEATURE_NX_IPV6
168 NXD_ADDRESS     host_ipduo_address;
169 NXD_ADDRESS     test_ipduo_server_address;
170 #ifdef USE_IPV6
171 NXD_ADDRESS     client_ipv6_address;
172 NXD_ADDRESS     dns_ipv6_server_address;
173 UINT            iface_index, address_index;
174 #endif
175 #endif
176 UINT            i;
177 ULONG           *ipv4_address_ptr[RECORD_COUNT];
178 NX_DNS_IPV6_ADDRESS
179                 *ipv6_address_ptr[RECORD_COUNT];
180 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
181 NX_DNS_NS_ENTRY
182                 *nx_dns_ns_entry_ptr[RECORD_COUNT];
183 NX_DNS_MX_ENTRY
184                 *nx_dns_mx_entry_ptr[RECORD_COUNT];
185 NX_DNS_SRV_ENTRY
186                 *nx_dns_srv_entry_ptr[RECORD_COUNT];
187 NX_DNS_SOA_ENTRY
188                 *nx_dns_soa_entry_ptr;
189 ULONG           host_address;
190 USHORT          host_port;
191 #endif
192 
193     NX_PARAMETER_NOT_USED(thread_input);
194 
195     /* Give NetX IP task a chance to get initialized . */
196     tx_thread_sleep(NX_IP_PERIODIC_RATE);
197 
198 #ifdef FEATURE_NX_IPV6
199 #ifdef USE_IPV6
200 
201     /* Make the DNS Client IPv6 enabled. */
202     status = nxd_ipv6_enable(&client_ip);
203 
204     /* Check for enable errors.  */
205     if (status)
206     {
207 
208         error_counter++;
209         return;
210      }
211     status = nxd_icmp_enable(&client_ip);
212 
213     /* Check for enable errors.  */
214     if (status)
215     {
216 
217         error_counter++;
218         return;
219     }
220 
221     client_ipv6_address.nxd_ip_address.v6[3] = 0x101;
222     client_ipv6_address.nxd_ip_address.v6[2] = 0x0;
223     client_ipv6_address.nxd_ip_address.v6[1] = 0x0000f101;
224     client_ipv6_address.nxd_ip_address.v6[0] = 0x20010db8;
225     client_ipv6_address.nxd_ip_version = NX_IP_VERSION_V6;
226 
227 
228      /* Set the link local address with the host MAC address. */
229     iface_index = 0;
230 
231     /* This assumes we are using the primary network interface (index 0). */
232     status = nxd_ipv6_address_set(&client_ip, iface_index, NX_NULL, 10, &address_index);
233 
234     /* Check for link local address set error.  */
235     if (status)
236     {
237 
238         error_counter++;
239         return;
240      }
241 
242     /* Set the host global IP address. We are assuming a 64
243        bit prefix here but this can be any value (< 128). */
244     status = nxd_ipv6_address_set(&client_ip, iface_index, &client_ipv6_address, 64, &address_index);
245 
246     /* Check for global address set error.  */
247     if (status)
248     {
249 
250         error_counter++;
251         return;
252      }
253 
254     /* Wait while NetX Duo validates the link local and global address. */
255     tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
256 #endif
257 #endif
258 
259     /* Create a DNS instance for the Client.  Note this function will create
260        the DNS Client packet pool for creating DNS message packets intended
261        for querying its DNS server. */
262     status =  nx_dns_create(&client_dns, &client_ip, (UCHAR *)"DNS Client");
263 
264     /* Check for DNS create error.  */
265     if (status)
266     {
267 
268         error_counter++;
269         return;
270      }
271 
272 #ifdef NX_DNS_CACHE_ENABLE
273     /* Initialize the cache.  */
274     status = nx_dns_cache_initialize(&client_dns, local_cache, LOCAL_CACHE_SIZE);
275 
276     /* Check for DNS cache error.  */
277     if (status)
278     {
279 
280         error_counter++;
281         return;
282      }
283 #endif
284 
285     /* Is the DNS client configured for the host application to create the pecket pool? */
286 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
287 
288     /* Yes, use the packet pool created above which has appropriate payload size
289        for DNS messages. */
290      status = nx_dns_packet_pool_set(&client_dns, &client_pool);
291 
292      /* Check for set DNS packet pool error.  */
293      if (status)
294      {
295 
296          error_counter++;
297          return;
298       }
299 
300 #endif /* NX_DNS_CLIENT_USER_CREATE_PACKET_POOL */
301 
302 #ifdef FEATURE_NX_IPV6
303 #ifdef USE_IPV6
304 
305     /* Add an IPv6 DNS server to the DNS client.  */
306     dns_ipv6_server_address.nxd_ip_address.v6[3] = 0x106;
307     dns_ipv6_server_address.nxd_ip_address.v6[2] = 0x0;
308     dns_ipv6_server_address.nxd_ip_address.v6[1] = 0x0000f101;
309     dns_ipv6_server_address.nxd_ip_address.v6[0] = 0x20010db8;
310     dns_ipv6_server_address.nxd_ip_version = NX_IP_VERSION_V6;
311 
312     status = nxd_dns_server_add(&client_dns, &dns_ipv6_server_address);
313 
314     /* Check for DNS add server error.  */
315     if (status)
316     {
317 
318         error_counter++;
319         return;
320      }
321 #else
322 
323     /* Add an IPv4 server address to the Client list. */
324     status = nx_dns_server_add(&client_dns, DNS_SERVER_ADDRESS);
325 
326     /* Check for DNS add server error.  */
327     if (status)
328     {
329 
330         error_counter++;
331         return;
332      }
333 #endif
334 #else
335 
336     /* Add an IPv4 server address to the Client list. */
337     status = nx_dns_server_add(&client_dns, DNS_SERVER_ADDRESS);
338 
339     /* Check for DNS add server error.  */
340     if (status)
341     {
342 
343         error_counter++;
344         return;
345      }
346 #endif
347 
348 
349 /********************************************************************************/
350 /*                                  Type AAAA                                   */
351 /*     Send AAAA type DNS Query to its DNS server and get the IPv6 address.     */
352 /********************************************************************************/
353 #ifdef FEATURE_NX_IPV6
354 
355     /* Send a DNS Client name query. Indicate the Client expects an IPv6 address (containing an AAAA record). The DNS
356        Client will send AAAA type query to its DNS server. */
357     status = nxd_dns_host_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &host_ipduo_address, NX_IP_PERIODIC_RATE, NX_IP_VERSION_V6);
358 
359     /* Check for DNS query error.  */
360     if (status != NX_SUCCESS)
361     {
362         error_counter++;
363     }
364 
365     else
366     {
367 
368         printf("------------------------------------------------------\n");
369         printf("Test AAAA: \n");
370 
371         printf("IP address: %x:%x:%x:%x:%x:%x:%x:%x\n",
372             (UINT)host_ipduo_address.nxd_ip_address.v6[0]  >>16 & 0xFFFF,
373             (UINT)host_ipduo_address.nxd_ip_address.v6[0]  & 0xFFFF,
374             (UINT)host_ipduo_address.nxd_ip_address.v6[1]  >>16 & 0xFFFF,
375             (UINT)host_ipduo_address.nxd_ip_address.v6[1]  & 0xFFFF,
376             (UINT)host_ipduo_address.nxd_ip_address.v6[2]  >>16 & 0xFFFF,
377             (UINT)host_ipduo_address.nxd_ip_address.v6[2]  & 0xFFFF,
378             (UINT)host_ipduo_address.nxd_ip_address.v6[3]  >>16 & 0xFFFF,
379             (UINT)host_ipduo_address.nxd_ip_address.v6[3]  & 0xFFFF);
380     }
381 
382 #endif
383 
384     /* Look up IPv6 addresses(AAAA TYPE) to record multiple IPv6 addresses in record_buffer and return the IPv6 address count.  */
385     status = nxd_dns_ipv6_address_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
386 
387     /* Check for DNS add server error.  */
388     if (status != NX_SUCCESS)
389     {
390         error_counter++;
391     }
392 
393     else
394     {
395 
396         printf("------------------------------------------------------\n");
397         printf("Test AAAA: ");
398         printf("record_count = %d \n", record_count);
399     }
400 
401     /* Get the IPv6 addresses of host.  */
402     for(i =0; i< record_count; i++)
403     {
404         ipv6_address_ptr[i] = (NX_DNS_IPV6_ADDRESS *)(record_buffer + i * sizeof(NX_DNS_IPV6_ADDRESS));
405 
406         printf("record %d: IP address: %x:%x:%x:%x:%x:%x:%x:%x\n", i,
407                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[0]  >>16 & 0xFFFF),
408                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[0]  & 0xFFFF),
409                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[1]  >>16 & 0xFFFF),
410                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[1]  & 0xFFFF),
411                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[2]  >>16 & 0xFFFF),
412                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[2]  & 0xFFFF),
413                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[3]  >>16 & 0xFFFF),
414                 (UINT)(ipv6_address_ptr[i] -> ipv6_address[3]  & 0xFFFF));
415     }
416 
417 
418 /********************************************************************************/
419 /*                                  Type A                                      */
420 /*       Send A type DNS Query to its DNS server and get the IPv4 address.      */
421 /********************************************************************************/
422 #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_IPV4)
423     /* Send a DNS Client name query. Indicate the Client expects an IPv4 address (containing an A record). If the DNS client
424        is using an IPv6 DNS server it will send this query over IPv6; otherwise it will be sent over IPv4. */
425     status = nxd_dns_host_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &host_ipduo_address, NX_IP_PERIODIC_RATE, NX_IP_VERSION_V4);
426 
427     /* Check for DNS query error.  */
428     if (status != NX_SUCCESS)
429     {
430         error_counter++;
431     }
432     else
433     {
434 
435         printf("------------------------------------------------------\n");
436         printf("Test A: \n");
437         printf("IP address: %lu.%lu.%lu.%lu\n",
438               host_ipduo_address.nxd_ip_address.v4 >> 24,
439               host_ipduo_address.nxd_ip_address.v4 >> 16 & 0xFF,
440               host_ipduo_address.nxd_ip_address.v4 >> 8 & 0xFF,
441               host_ipduo_address.nxd_ip_address.v4 & 0xFF);
442     }
443 
444 #endif
445 
446     /* Look up an IPv4 address over IPv4. */
447     status = nx_dns_host_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &host_ip_address, NX_IP_PERIODIC_RATE);
448 
449     /* Check for DNS query error.  */
450     if (status != NX_SUCCESS)
451     {
452         error_counter++;
453     }
454 
455     else
456     {
457 
458         printf("------------------------------------------------------\n");
459         printf("Test A: \n");
460         printf("IP address: %lu.%lu.%lu.%lu\n",
461         host_ip_address >> 24,
462         host_ip_address >> 16 & 0xFF,
463         host_ip_address >> 8 & 0xFF,
464         host_ip_address & 0xFF);
465     }
466 
467 
468     /* Look up IPv4 addresses to record multiple IPv4 addresses in record_buffer and return the IPv4 address count.  */
469     status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
470 
471     /* Check for DNS query error.  */
472     if (status != NX_SUCCESS)
473     {
474         error_counter++;
475     }
476 
477     else
478     {
479 
480         printf("------------------------------------------------------\n");
481         printf("Test A: ");
482         printf("record_count = %d \n", record_count);
483     }
484 
485     /* Get the IPv4 addresses of host.  */
486     for(i =0; i< record_count; i++)
487     {
488         ipv4_address_ptr[i] = (ULONG *)(record_buffer + i * sizeof(ULONG));
489         printf("record %d: IP address: %lu.%lu.%lu.%lu\n", i,
490                 *ipv4_address_ptr[i] >> 24,
491                 *ipv4_address_ptr[i] >> 16 & 0xFF,
492                 *ipv4_address_ptr[i] >> 8 & 0xFF,
493                 *ipv4_address_ptr[i] & 0xFF);
494     }
495 
496 
497 /********************************************************************************/
498 /*                                  Type A + CNAME response                     */
499 /*       Send A type DNS Query to its DNS server and get the IPv4 address.      */
500 /********************************************************************************/
501     /* Look up an IPv4 address over IPv4. */
502     status = nx_dns_host_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &host_ip_address, NX_IP_PERIODIC_RATE);
503 
504     /* Check for DNS query error.  */
505     if (status != NX_SUCCESS)
506     {
507         error_counter++;
508     }
509 
510     else
511     {
512 
513         printf("------------------------------------------------------\n");
514         printf("Test A + CNAME response: \n");
515         printf("IP address: %lu.%lu.%lu.%lu\n",
516         host_ip_address >> 24,
517         host_ip_address >> 16 & 0xFF,
518         host_ip_address >> 8 & 0xFF,
519         host_ip_address & 0xFF);
520     }
521 
522 
523     /* Look up IPv4 addresses to record multiple IPv4 addresses in record_buffer and return the IPv4 address count.  */
524     status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
525 
526     /* Check for DNS query error.  */
527     if (status != NX_SUCCESS)
528     {
529         error_counter++;
530     }
531 
532     else
533     {
534 
535         printf("------------------------------------------------------\n");
536         printf("Test Test A + CNAME response: ");
537         printf("record_count = %d \n", record_count);
538     }
539 
540     /* Get the IPv4 addresses of host.  */
541     for(i =0; i< record_count; i++)
542     {
543         ipv4_address_ptr[i] = (ULONG *)(record_buffer + i * sizeof(ULONG));
544         printf("record %d: IP address: %lu.%lu.%lu.%lu\n", i,
545                 *ipv4_address_ptr[i] >> 24,
546                 *ipv4_address_ptr[i] >> 16 & 0xFF,
547                 *ipv4_address_ptr[i] >> 8 & 0xFF,
548                 *ipv4_address_ptr[i] & 0xFF);
549     }
550 
551 
552 /********************************************************************************/
553 /*                                  Type PTR                                    */
554 /*       Send PTR type DNS Query to its DNS server and get the host name.       */
555 /********************************************************************************/
556 
557 #ifdef FEATURE_NX_IPV6
558 
559     /* Look up a host name from an IPv6 address (reverse lookup). */
560 
561     /* Create an IPv6 address for a reverse lookup. */
562     test_ipduo_server_address.nxd_ip_version = NX_IP_VERSION_V6;
563     test_ipduo_server_address.nxd_ip_address.v6[0] = 0x24046800;
564     test_ipduo_server_address.nxd_ip_address.v6[1] = 0x40050c00;
565     test_ipduo_server_address.nxd_ip_address.v6[2] = 0x00000000;
566     test_ipduo_server_address.nxd_ip_address.v6[3] = 0x00000065;
567 
568     /* This will be sent over IPv6 to the DNS server who should return a PTR record if it can find the information. */
569     status = nxd_dns_host_by_address_get(&client_dns, &test_ipduo_server_address, &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
570 
571     /* Check for DNS query error.  */
572     if (status != NX_SUCCESS)
573     {
574         error_counter++;
575     }
576 
577     else
578     {
579 
580         printf("------------------------------------------------------\n");
581         printf("Test PTR: %s\n", record_buffer);
582     }
583 #endif
584 
585 #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_IPV4)
586 
587     /* Create an IPv4 address for the reverse lookup. If the DNS client is IPv6 enabled, it will send this over
588        IPv6 to the DNS server; otherwise it will send it over IPv4. In either case the respective server will
589        return a PTR record if it has the information. */
590     test_ipduo_server_address.nxd_ip_version = NX_IP_VERSION_V4;
591     test_ipduo_server_address.nxd_ip_address.v4 = IP_ADDRESS(74, 125, 71, 106);
592 
593     status = nxd_dns_host_by_address_get(&client_dns, &test_ipduo_server_address, &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
594 
595      /* Check for DNS query error.  */
596      if (status != NX_SUCCESS)
597      {
598          error_counter++;
599      }
600 
601     else
602     {
603 
604         printf("------------------------------------------------------\n");
605         printf("Test PTR: %s\n", record_buffer);
606     }
607 #endif
608 
609      /* Look up host name over IPv4. */
610      host_ip_address = IP_ADDRESS(74, 125, 71, 106);
611      status = nx_dns_host_by_address_get(&client_dns, host_ip_address, &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
612 
613      /* Check for DNS query error.  */
614      if (status != NX_SUCCESS)
615      {
616          error_counter++;
617      }
618 
619     else
620     {
621         printf("------------------------------------------------------\n");
622         printf("Test PTR: %s\n", record_buffer);
623     }
624 
625 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
626 /********************************************************************************/
627 /*                                  Type CNAME                                  */
628 /*   Send CNAME type DNS Query to its DNS server and get the canonical name .   */
629 /********************************************************************************/
630 
631      /* Send CNAME type to record the canonical name of host in record_buffer.  */
632      status = nx_dns_cname_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
633 
634      /* Check for DNS query error.  */
635      if (status != NX_SUCCESS)
636      {
637          error_counter++;
638      }
639 
640     else
641     {
642 
643         printf("------------------------------------------------------\n");
644         printf("Test CNAME: %s\n", record_buffer);
645     }
646 
647 
648 /********************************************************************************/
649 /*                                  Type TXT                                    */
650 /*      Send TXT type DNS Query to its DNS server and get descriptive text.     */
651 /********************************************************************************/
652 
653      /* Send TXT type to record the descriptive test of host in record_buffer.  */
654      status = nx_dns_host_text_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
655 
656      /* Check for DNS query error.  */
657      if (status != NX_SUCCESS)
658      {
659          error_counter++;
660      }
661 
662     else
663     {
664 
665         printf("------------------------------------------------------\n");
666         printf("Test TXT: %s\n", record_buffer);
667     }
668 
669 
670 /********************************************************************************/
671 /*                                  Type NS                                     */
672 /*   Send NS type DNS Query to its DNS server and get the domain name server.   */
673 /********************************************************************************/
674 
675      /* Send NS type to record multiple name servers in record_buffer and return the name server count.
676         If the DNS response includes the IPv4 addresses of name server, record it similarly in record_buffer.  */
677      status = nx_dns_domain_name_server_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
678 
679      /* Check for DNS query error.  */
680      if (status != NX_SUCCESS)
681      {
682          error_counter++;
683      }
684 
685     else
686     {
687 
688         printf("------------------------------------------------------\n");
689         printf("Test NS: ");
690         printf("record_count = %d \n", record_count);
691     }
692 
693     /* Get the name server.  */
694     for(i =0; i< record_count; i++)
695     {
696         nx_dns_ns_entry_ptr[i] = (NX_DNS_NS_ENTRY *)(record_buffer + i * sizeof(NX_DNS_NS_ENTRY));
697 
698         printf("record %d: IP address: %lu.%lu.%lu.%lu\n", i,
699                 nx_dns_ns_entry_ptr[i] -> nx_dns_ns_ipv4_address  >> 24,
700                 nx_dns_ns_entry_ptr[i] -> nx_dns_ns_ipv4_address >> 16 & 0xFF,
701                 nx_dns_ns_entry_ptr[i] -> nx_dns_ns_ipv4_address >> 8 & 0xFF,
702                 nx_dns_ns_entry_ptr[i] -> nx_dns_ns_ipv4_address & 0xFF);
703         if(nx_dns_ns_entry_ptr[i] -> nx_dns_ns_hostname_ptr)
704             printf("hostname = %s\n", nx_dns_ns_entry_ptr[i] -> nx_dns_ns_hostname_ptr);
705         else
706             printf("hostname is not set\n");
707     }
708 
709 /********************************************************************************/
710 /*                                  Type MX                                     */
711 /*   Send MX type DNS Query to its DNS server and get the domain mail exchange. */
712 /********************************************************************************/
713 
714      /* Send MX DNS query type to record multiple mail exchanges in record_buffer and return the mail exchange count.
715         If the DNS response includes the IPv4 addresses of mail exchange, record it similarly in record_buffer.  */
716      status = nx_dns_domain_mail_exchange_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
717 
718      /* Check for DNS query error.  */
719      if (status != NX_SUCCESS)
720      {
721          error_counter++;
722      }
723 
724     else
725     {
726 
727         printf("------------------------------------------------------\n");
728         printf("Test MX: ");
729         printf("record_count = %d \n", record_count);
730     }
731 
732     /* Get the mail exchange.  */
733     for(i =0; i< record_count; i++)
734     {
735         nx_dns_mx_entry_ptr[i] = (NX_DNS_MX_ENTRY *)(record_buffer + i * sizeof(NX_DNS_MX_ENTRY));
736 
737         printf("record %d: IP address: %lu.%lu.%lu.%lu\n", i,
738                 nx_dns_mx_entry_ptr[i] -> nx_dns_mx_ipv4_address >> 24,
739                 nx_dns_mx_entry_ptr[i] -> nx_dns_mx_ipv4_address >> 16 & 0xFF,
740                 nx_dns_mx_entry_ptr[i] -> nx_dns_mx_ipv4_address >> 8 & 0xFF,
741                 nx_dns_mx_entry_ptr[i] -> nx_dns_mx_ipv4_address & 0xFF);
742         printf("preference = %d \n ", nx_dns_mx_entry_ptr[i] -> nx_dns_mx_preference);
743         if(nx_dns_mx_entry_ptr[i] -> nx_dns_mx_hostname_ptr)
744             printf("hostname = %s\n", nx_dns_mx_entry_ptr[i] -> nx_dns_mx_hostname_ptr);
745         else
746             printf("hostname is not set\n");
747     }
748 
749 /********************************************************************************/
750 /*                                  Type SRV                                    */
751 /*  Send SRV type DNS Query to its DNS server and get the location of services. */
752 /********************************************************************************/
753 
754      /* Send SRV DNS query type to record the location of services in record_buffer and return count.
755         If the DNS response includes the IPv4 addresses of service name, record it similarly in record_buffer.  */
756      status = nx_dns_domain_service_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, &record_count, NX_IP_PERIODIC_RATE);
757 
758      /* Check for DNS query error.  */
759      if (status != NX_SUCCESS)
760      {
761          error_counter++;
762      }
763 
764     else
765     {
766 
767         printf("------------------------------------------------------\n");
768         printf("Test SRV: ");
769         printf("record_count = %d \n", record_count);
770     }
771 
772     /* Get the location of services.  */
773     for(i =0; i< record_count; i++)
774     {
775         nx_dns_srv_entry_ptr[i] = (NX_DNS_SRV_ENTRY *)(record_buffer + i * sizeof(NX_DNS_SRV_ENTRY));
776 
777         printf("record %d: IP address: %lu.%lu.%lu.%lu\n", i,
778                 nx_dns_srv_entry_ptr[i] -> nx_dns_srv_ipv4_address >> 24,
779                 nx_dns_srv_entry_ptr[i] -> nx_dns_srv_ipv4_address >> 16 & 0xFF,
780                 nx_dns_srv_entry_ptr[i] -> nx_dns_srv_ipv4_address >> 8 & 0xFF,
781                 nx_dns_srv_entry_ptr[i] -> nx_dns_srv_ipv4_address & 0xFF);
782         printf("port number = %d\n", nx_dns_srv_entry_ptr[i] -> nx_dns_srv_port_number );
783         printf("priority = %d\n", nx_dns_srv_entry_ptr[i] -> nx_dns_srv_priority );
784         printf("weight = %d\n", nx_dns_srv_entry_ptr[i] -> nx_dns_srv_weight );
785         if(nx_dns_srv_entry_ptr[i] -> nx_dns_srv_hostname_ptr)
786             printf("hostname = %s\n", nx_dns_srv_entry_ptr[i] -> nx_dns_srv_hostname_ptr);
787         else
788             printf("hostname is not set\n");
789     }
790 
791     /* Get the service info, NetX old API.*/
792     status = nx_dns_info_by_name_get(&client_dns, (UCHAR *)"www.my_example.com", &host_address, &host_port, NX_IP_PERIODIC_RATE);
793 
794     /* Check for DNS add server error.  */
795      if (status != NX_SUCCESS)
796      {
797          error_counter++;
798      }
799 
800     else
801     {
802 
803         printf("------------------------------------------------------\n");
804         printf("Test SRV: ");
805         printf("IP address: %lu.%lu.%lu.%lu\n",
806                 host_address >> 24,
807                 host_address >> 16 & 0xFF,
808                 host_address >> 8 & 0xFF,
809                 host_address & 0xFF);
810         printf("port number = %d\n", host_port);
811     }
812 
813 /********************************************************************************/
814 /*                                  Type SOA                                    */
815 /* Send SOA type DNS Query to its DNS server and get zone of start of authority.*/
816 /********************************************************************************/
817 
818      /* Send SOA DNS query type to record the zone of start of authority in record_buffer.  */
819      status = nx_dns_authority_zone_start_get(&client_dns, (UCHAR *)"www.my_example.com", &record_buffer[0], BUFFER_SIZE, NX_IP_PERIODIC_RATE);
820 
821      /* Check for DNS query error.  */
822      if (status != NX_SUCCESS)
823      {
824          error_counter++;
825      }
826 
827      /* Get the loc*/
828      nx_dns_soa_entry_ptr = (NX_DNS_SOA_ENTRY *) record_buffer;
829      printf("------------------------------------------------------\n");
830      printf("Test SOA: \n");
831      printf("serial = %lu\n", nx_dns_soa_entry_ptr -> nx_dns_soa_serial );
832      printf("refresh = %lu\n", nx_dns_soa_entry_ptr -> nx_dns_soa_refresh );
833      printf("retry = %lu\n", nx_dns_soa_entry_ptr -> nx_dns_soa_retry );
834      printf("expire = %lu\n", nx_dns_soa_entry_ptr -> nx_dns_soa_expire );
835      printf("minmum = %lu\n", nx_dns_soa_entry_ptr -> nx_dns_soa_minmum );
836      if(nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr)
837          printf("host mname = %s\n", nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr);
838      else
839          printf("host mame is not set\n");
840      if(nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr)
841          printf("host rname = %s\n", nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr);
842      else
843          printf("host rname is not set\n");
844 
845 
846 #endif
847 
848     /* Shutting down...*/
849 
850     /* Terminate the DNS Client thread. */
851     status = nx_dns_delete(&client_dns);
852 
853     return;
854 }
855 
856 
857