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