1 /* This NetX test concentrates on the basic UDP operation. */
2
3
4 #include "tx_api.h"
5 #include "nx_api.h"
6 #include "nx_udp.h"
7 #include "nxd_dns.h"
8
9 extern void test_control_return(UINT status);
10
11 #if !defined(NX_DISABLE_IPV4)
12
13 #define DEMO_STACK_SIZE 2048
14
15
16 /* Define the ThreadX and NetX object control blocks... */
17
18 static TX_THREAD thread_0;
19 static TX_THREAD thread_1;
20
21 static NX_PACKET_POOL pool_0;
22 static NX_IP client_ip;
23 static NX_IP server_ip;
24
25
26 static NX_UDP_SOCKET server_socket;
27
28 static NX_DNS client_dns;
29
30 #define DNS_SERVER_ADDRESS IP_ADDRESS(10,0,0,1)
31
32 #ifdef __PRODUCT_NETXDUO__
33 static NXD_ADDRESS address_ipv4_0;
34 static NXD_ADDRESS address_ipv4_1;
35 #ifdef FEATURE_NX_IPV6
36 static NXD_ADDRESS address_ipv6_0;
37 static NXD_ADDRESS address_ipv6_1;
38 #endif
39 #endif
40
41 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
42 NX_PACKET_POOL client_pool;
43 #endif
44
45 /* Define the counters used in the demo application... */
46
47 static UINT status;
48 static ULONG error_counter;
49 static ULONG notify_calls = 0;
50
51 static UCHAR record_buffer[500];
52 static UINT record_count;
53
54 /* Define thread prototypes. */
55
56 static void thread_0_entry(ULONG thread_input);
57 static void thread_1_entry(ULONG thread_input);
58 extern void _nx_ram_network_driver_512(struct NX_IP_DRIVER_STRUCT *driver_req);
59 static void receive_packet_function(NX_UDP_SOCKET *socket_ptr);
60
61 /* DNS Tests. */
62 static void dns_test_initialize();
63 static void dns_a_type_test();
64
65 #ifdef __PRODUCT_NETXDUO__
66 static void dns_aaaa_type_test();
67 #endif /* __PRODUCT_NETXDUO__ */
68
69 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
70 static void dns_a_cname_type_test();
71 static void dns_mx_type_test();
72 static void dns_mx_a_type_test();
73 static void dns_cname_type_test();
74 static void dns_ns_a_type_test();
75 static void dns_srv_type_test();
76 static void dns_txt_type_test();
77 static void dns_soa_type_test();
78 #endif
79
80 /* DNS retransmit test. */
81 static void dns_retransmit_test();
82
83 /* Send DNS response. */
84 static UINT nx_dns_response_packet_send(NX_UDP_SOCKET *server_socket, UINT port, USHORT nx_dns_transmit_id, UINT packet_number);
85
86 extern char response_a_google_com_pkt[246];
87 extern int response_a_google_com_pkt_size;
88
89 extern char response_a_berkley_edu_pkt[88];
90 extern int response_a_berkley_edu_pkt_size;
91
92 extern char response_aaaa_berkley_edu_pkt[100];
93 extern int response_aaaa_berkley_edu_pkt_size;
94
95 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
96
97 extern char response_a_cname_www_npr_org_pkt[119];
98 extern int response_a_cname_www_npr_org_pkt_size;
99
100 extern char response_mx_google_com_pkt[178];
101 extern int response_mx_google_com_pkt_size;
102
103 extern char response_mx_a_google_com_pkt[258];
104 extern int response_mx_a_google_com_pkt_size;
105
106 extern char response_mx_a_berkley_edu_pkt[107];
107 extern int response_mx_a_berkley_edu_pkt_size;
108
109 extern char response_cname_www_baidu_com_pkt[100];
110 extern int response_cname_www_baidu_com_pkt_size;
111
112 extern char response_ns_a_ti_com_pkt[349];
113 extern int response_ns_a_ti_com_pkt_size;
114
115 extern char response_srv_google_com_pkt[373];
116 extern int response_srv_google_com_pkt_size;
117
118 extern char response_txt_google_com_pkt[373];
119 extern int response_txt_google_com_pkt_size;
120
121 extern char response_soa_google_com_pkt[120];
122 extern int response_soa_google_com_pkt_size;
123
124 #endif
125
126 typedef struct DNS_TEST_STRUCT
127 {
128 char *dns_test_pkt_data;
129 int dns_test_pkt_size;
130 } DNS_TEST;
131
132 #define test_count 19
133 static DNS_TEST dns_test[test_count];
134
135 extern ULONG test_control_successful_tests;
136 extern ULONG test_control_failed_tests;
137
138 #define DNS_START_OFFSET (14 + 20 + 8)
139
140 /* Define what the initial system looks like. */
141
142 #ifdef CTEST
test_application_define(void * first_unused_memory)143 VOID test_application_define(void *first_unused_memory)
144 #else
145 void netx_dns_function_test_application_define(void *first_unused_memory)
146 #endif
147 {
148
149 CHAR *pointer;
150
151 /* Setup the working pointer. */
152 pointer = (CHAR *) first_unused_memory;
153
154 /* Create the DNS main thread. */
155 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
156 pointer, DEMO_STACK_SIZE,
157 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
158 pointer = pointer + DEMO_STACK_SIZE;
159
160 /* . */
161 tx_thread_create(&thread_1, "thread 1", thread_1_entry, 0,
162 pointer, DEMO_STACK_SIZE,
163 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
164 pointer = pointer + DEMO_STACK_SIZE;
165
166 /* Initialize the NetX system. */
167 nx_system_initialize();
168
169 /* Create a packet pool. */
170 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1500, pointer, 8192);
171 pointer = pointer + 8192;
172
173 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
174
175 /* Create the packet pool for the DNS Client to send packets.
176
177 If the DNS Client is configured for letting the host application create
178 the DNS packet pool, (see NX_DNS_CLIENT_USER_CREATE_PACKET_POOL option), see
179 nx_dns_create() for guidelines on packet payload size and pool size.
180 packet traffic for NetX Duo processes.
181 */
182 status = nx_packet_pool_create(&client_pool, "DNS Client Packet Pool", NX_DNS_PACKET_PAYLOAD, pointer, NX_DNS_PACKET_POOL_SIZE);
183
184 pointer = pointer + NX_DNS_PACKET_POOL_SIZE;
185
186 /* Check for pool creation error. */
187 if (status)
188 return;
189 #endif
190
191 /* Check for pool creation error. */
192 if (status)
193 error_counter++;
194
195 /* Create an IP instance. */
196 status = nx_ip_create(&client_ip, "NetX IP Instance 0", IP_ADDRESS(10, 0, 0, 10), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_512,
197 pointer, 2048, 1);
198 pointer = pointer + 2048;
199
200 /* Create another IP instance. */
201 status += nx_ip_create(&server_ip, "NetX IP Instance 1", IP_ADDRESS(10, 0, 0, 1), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_512,
202 pointer, 2048, 1);
203 pointer = pointer + 2048;
204
205 /* Check for IP create errors. */
206 if (status)
207 error_counter++;
208
209 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
210 status = nx_arp_enable(&client_ip, (void *) pointer, 1024);
211 pointer = pointer + 1024;
212
213 /* Enable ARP and supply ARP cache memory for IP Instance 1. */
214 status += nx_arp_enable(&server_ip, (void *) pointer, 1024);
215 pointer = pointer + 1024;
216
217 /* Check for ARP enable errors. */
218 if (status)
219 error_counter++;
220
221 /* Enable UDP traffic. */
222 status = nx_udp_enable(&client_ip);
223 status += nx_udp_enable(&server_ip);
224
225 /* Check for UDP enable errors. */
226 if (status)
227 error_counter++;
228 }
229
230
231
232 /* Define the test threads. */
233
thread_0_entry(ULONG thread_input)234 static void thread_0_entry(ULONG thread_input)
235 {
236
237 /* Create a DNS instance for the Client. Note this function will create
238 the DNS Client packet pool for creating DNS message packets intended
239 for querying its DNS server. */
240 status = nx_dns_create(&client_dns, &client_ip, (UCHAR *)"DNS Client");
241
242 /* Is the DNS client configured for the host application to create the pecket pool? */
243 #ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
244
245 /* Yes, use the packet pool created above which has appropriate payload size
246 for DNS messages. */
247 status = nx_dns_packet_pool_set(&client_dns, &client_pool);
248
249 /* Check for set DNS packet pool error. */
250 if (status)
251 {
252 error_counter++;
253 }
254
255 #endif /* NX_DNS_CLIENT_USER_CREATE_PACKET_POOL */
256
257 /* Add a then remove ipv4 DNS servers, check for max entries as well */
258 for (int i = 0; i < (NX_DNS_MAX_SERVERS); i++)
259 {
260 status = nx_dns_server_add(&client_dns, IP_ADDRESS(10,1,1,i));
261 if (status)
262 {
263 error_counter++;
264 }
265 }
266
267 status = nx_dns_server_add(&client_dns, IP_ADDRESS(10,1,1,NX_DNS_MAX_SERVERS));
268 if (status != NX_NO_MORE_ENTRIES)
269 {
270 error_counter++;
271 }
272
273 /* check size when we are at max entries. */
274 UINT size = 0;
275 status = nx_dns_get_serverlist_size(&client_dns, &size);
276 if (status != NX_SUCCESS || size != 5)
277 {
278 error_counter++;
279 }
280
281 for (int i = 0; i < (NX_DNS_MAX_SERVERS); i++)
282 {
283 status = nx_dns_server_remove(&client_dns, IP_ADDRESS(10,1,1,i));
284 if (status)
285 {
286 error_counter++;
287 }
288 }
289
290 #ifdef __PRODUCT_NETXDUO__
291 /* Add one IPv4 server address. */
292 address_ipv4_0.nxd_ip_address.v4 = IP_ADDRESS(1,1,1,1);
293 address_ipv4_0.nxd_ip_version = NX_IP_VERSION_V4;
294 status = nxd_dns_server_add(&client_dns,&address_ipv4_0);
295 if (status)
296 {
297 error_counter++;
298 }
299
300 /* Add an other IPv4 server address to the Client list. */
301 address_ipv4_1.nxd_ip_address.v4 = IP_ADDRESS(10,1,1,1);
302 address_ipv4_1.nxd_ip_version = NX_IP_VERSION_V4;
303 status = nxd_dns_server_add(&client_dns, &address_ipv4_1);
304 if (status)
305 {
306 error_counter++;
307 }
308
309 #ifdef FEATURE_NX_IPV6
310 /* Add one IPv6 server address. */
311 address_ipv6_0.nxd_ip_address.v6[0] = 13;
312 address_ipv6_0.nxd_ip_address.v6[1] = 13;
313 address_ipv6_0.nxd_ip_address.v6[2] = 13;
314 address_ipv6_0.nxd_ip_address.v6[3] = 13;
315 address_ipv6_0.nxd_ip_version = NX_IP_VERSION_V6;
316 status = nxd_dns_server_add(&client_dns, &address_ipv6_0);
317 if (status)
318 {
319 error_counter++;
320 }
321
322 /* Add an other IPv6 server address to the Client list. */
323 address_ipv6_1.nxd_ip_address.v6[0] = 14;
324 address_ipv6_1.nxd_ip_address.v6[1] = 14;
325 address_ipv6_1.nxd_ip_address.v6[2] = 14;
326 address_ipv6_1.nxd_ip_address.v6[3] = 14;
327 address_ipv6_1.nxd_ip_version = NX_IP_VERSION_V6;
328 status = nxd_dns_server_add(&client_dns, &address_ipv6_1);
329 if (status)
330 {
331 error_counter++;
332 }
333 #endif
334
335 /* Check duplicate server logic */
336 status = nxd_dns_server_add(&client_dns, &address_ipv4_1);
337 if (status != NX_DNS_DUPLICATE_ENTRY)
338 {
339 error_counter++;
340 }
341
342 #ifdef FEATURE_NX_IPV6
343 status = nxd_dns_server_add(&client_dns, &address_ipv6_1);
344 if (status != NX_DNS_DUPLICATE_ENTRY)
345 {
346 error_counter++;
347 }
348 #endif
349
350 /* check for size less than max entries. */
351 status = nx_dns_get_serverlist_size(&client_dns, &size);
352 #ifdef FEATURE_NX_IPV6
353 if (status != NX_SUCCESS || size != 4)
354 #else
355 if (status != NX_SUCCESS || size != 2)
356 #endif
357 {
358 error_counter++;
359 }
360
361 ULONG get_ipv4_address;
362 #ifdef FEATURE_NX_IPV6
363 /* use nx api for IPv6 address. */
364 status = nx_dns_server_get(&client_dns, 2, &get_ipv4_address);
365 if (status != NX_DNS_INVALID_ADDRESS_TYPE)
366 {
367 error_counter++;
368 }
369 #endif
370
371 /* try getting address outside of bounds. */
372 status = nx_dns_server_get(&client_dns, NX_DNS_MAX_SERVERS, &get_ipv4_address);
373 if (status != NX_DNS_PARAM_ERROR) {
374 error_counter++;
375 }
376
377 /* try getting from index that is not set. */
378 status = nx_dns_server_get(&client_dns, 4, &get_ipv4_address);
379 if (status != NX_DNS_SERVER_NOT_FOUND)
380 {
381 error_counter++;
382 }
383
384 /* these should work. */
385 status = nx_dns_server_get(&client_dns, 0, &get_ipv4_address);
386 if (status != NX_SUCCESS || get_ipv4_address != IP_ADDRESS(1,1,1,1))
387 {
388 error_counter++;
389 }
390
391 status = nx_dns_server_get(&client_dns, 1, &get_ipv4_address);
392 if (status != NX_SUCCESS || get_ipv4_address != IP_ADDRESS(10,1,1,1))
393 {
394 error_counter++;
395 }
396
397 #ifdef FEATURE_NX_IPV6
398 NXD_ADDRESS get_ipv6_address;
399 status = nxd_dns_server_get(&client_dns, 2, &get_ipv6_address);
400 if (status != NX_SUCCESS || !CHECK_IPV6_ADDRESSES_SAME(&get_ipv6_address.nxd_ip_address.v6[0], &address_ipv6_0.nxd_ip_address.v6[0]))
401 {
402 error_counter++;
403 }
404
405 /* Check for an address that does not exist. */
406 address_ipv6_0.nxd_ip_address.v6[0] = 1;
407 address_ipv6_0.nxd_ip_address.v6[1] = 2;
408 address_ipv6_0.nxd_ip_address.v6[2] = 3;
409 address_ipv6_0.nxd_ip_address.v6[3] = 4;
410 status = nxd_dns_server_remove(&client_dns, &address_ipv6_0);
411 if (status != NX_DNS_SERVER_NOT_FOUND)
412 {
413 error_counter++;
414 }
415
416 /* Remove an ipv6 that does exist. */
417 status = nxd_dns_server_remove(&client_dns, &address_ipv6_1);
418 if (status != NX_SUCCESS)
419 {
420 error_counter++;
421 }
422 #endif
423 status = nx_dns_server_remove_all(&client_dns);
424 if (status != NX_SUCCESS)
425 {
426 error_counter++;
427 }
428 #endif
429
430 /* Add an IPv4 server address to the Client list. */
431 status = nx_dns_server_add(&client_dns, DNS_SERVER_ADDRESS);
432 if (status)
433 {
434 error_counter++;
435 }
436
437 status = nx_dns_get_serverlist_size(&client_dns, &size);
438 if (status != NX_SUCCESS || size != 1)
439 {
440 error_counter++;
441 }
442
443 /* The DNS test initialize. */
444 dns_test_initialize();
445
446 /* Test the DNS A type function. */
447 dns_a_type_test();
448
449 /* DNS retransmit test. */
450 dns_retransmit_test();
451
452 #ifdef __PRODUCT_NETXDUO__
453 /* Test the DNS AAAA type function. */
454 dns_aaaa_type_test();
455 #endif
456
457 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
458
459 /* Test the DNS A + CNAME type function. */
460 dns_a_cname_type_test();
461
462 /* Test the DNS MX type function. */
463 dns_mx_type_test();
464
465 /* Test the DNS MX type with addtional A type function. */
466 dns_mx_a_type_test();
467
468 /* Test the DNS CNAME type function. */
469 dns_cname_type_test();
470
471 /* Test the DNS NS type with addtional A type function. */
472 dns_ns_a_type_test();
473
474 /* Test the DNS SRV type. */
475 dns_srv_type_test();
476
477 /* Test the DNS SRV type. */
478 dns_txt_type_test();
479
480 /* Test the DNS SOA type. */
481 dns_soa_type_test();
482
483 #endif
484
485 status = nx_dns_delete(&client_dns);
486
487 if (status)
488 {
489 error_counter++;
490 }
491
492 test_control_return(0xdeadbeef);
493 }
494
495
thread_1_entry(ULONG thread_input)496 static void thread_1_entry(ULONG thread_input)
497 {
498
499 NX_PACKET *my_packet;
500 UINT port;
501 UINT i;
502 USHORT nx_dns_transmit_id;
503 UCHAR *data_ptr;
504
505 /* Create a UDP socket act as the DNS server. */
506 status = nx_udp_socket_create(&server_ip, &server_socket, "Socket 1", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0x80, 5);
507
508 /* Check status. */
509 if (status)
510 {
511 error_counter++;
512 }
513
514 /* Register the receive notify function. */
515 status = nx_udp_socket_receive_notify(&server_socket, receive_packet_function);
516
517 /* Check status. */
518 if (status)
519 {
520 error_counter++;
521 }
522
523 /* Bind the UDP socket to the IP port. */
524 status = nx_udp_socket_bind(&server_socket, 53, TX_WAIT_FOREVER);
525
526 /* Act as the DNS server to receive the DNS query and send the DNS response. */
527 for (i = 0; i < test_count; i++ )
528 {
529
530 /* Receive a UDP packet. */
531 status = nx_udp_socket_receive(&server_socket, &my_packet, 10 * NX_IP_PERIODIC_RATE);
532
533 /* Check status. */
534 if (status)
535 {
536 error_counter++;
537 return;
538 }
539
540 /* If the Test the DNS client retransmission.*/
541 if((i == 4) || (i == 5))
542 {
543 nx_packet_release(my_packet);
544 continue;
545 }
546
547 /* Get the DNS client UDP port. */
548 status = nx_udp_packet_info_extract(my_packet, NX_NULL ,NX_NULL, &port, NX_NULL);
549
550 /* Check status. */
551 if (status)
552 {
553 error_counter++;
554 return;
555 }
556
557 /* Get the DNS transmit ID. */
558 data_ptr = my_packet -> nx_packet_prepend_ptr + NX_DNS_ID_OFFSET;
559 nx_dns_transmit_id = *data_ptr++;
560 nx_dns_transmit_id = (USHORT)((nx_dns_transmit_id << 8) | *data_ptr);
561
562 /* Release the packet. */
563 nx_packet_release(my_packet);
564
565 /* Send the DNS response packet. */
566 status = nx_dns_response_packet_send(&server_socket, port, nx_dns_transmit_id, i);
567
568 /* Check status. */
569 if (status)
570 {
571 error_counter++;
572 return;
573 }
574 }
575
576 /* Unbind the UDP socket. */
577 status = nx_udp_socket_unbind(&server_socket);
578
579 /* Check status. */
580 if (status)
581 {
582 error_counter++;
583 return;
584 }
585
586 /* Delete the UDP socket. */
587 status = nx_udp_socket_delete(&server_socket);
588
589 /* Check status. */
590 if (status)
591 {
592 error_counter++;
593 return;
594 }
595
596 /* Let the DNS threads execute. */
597 tx_thread_relinquish();
598 }
599
receive_packet_function(NX_UDP_SOCKET * socket_ptr)600 static void receive_packet_function(NX_UDP_SOCKET *socket_ptr)
601 {
602
603 if (socket_ptr == &server_socket)
604 notify_calls++;
605 }
606
nx_dns_response_packet_send(NX_UDP_SOCKET * server_socket,UINT port,USHORT nx_dns_transmit_id,UINT packet_number)607 static UINT nx_dns_response_packet_send(NX_UDP_SOCKET *server_socket, UINT port, USHORT nx_dns_transmit_id, UINT packet_number)
608 {
609 UINT status;
610 NX_PACKET *response_packet;
611 UCHAR *data_ptr;
612
613 /* Allocate a response packet. */
614 status = nx_packet_allocate(&pool_0, &response_packet, NX_UDP_PACKET, TX_WAIT_FOREVER);
615
616 /* Check status. */
617 if (status)
618 {
619 error_counter++;
620 }
621
622 /* Write the DNS response messages into the packet payload! */
623 dns_test[packet_number].dns_test_pkt_data += DNS_START_OFFSET;
624 memcpy(response_packet -> nx_packet_prepend_ptr, dns_test[packet_number].dns_test_pkt_data, dns_test[packet_number].dns_test_pkt_size - DNS_START_OFFSET);
625
626 /* Adjust the write pointer. */
627 response_packet -> nx_packet_length = dns_test[packet_number].dns_test_pkt_size - DNS_START_OFFSET;
628 response_packet -> nx_packet_append_ptr = response_packet -> nx_packet_prepend_ptr + response_packet -> nx_packet_length;
629
630 /* Update the DNS transmit ID. */
631 data_ptr = response_packet -> nx_packet_prepend_ptr + NX_DNS_ID_OFFSET;
632 *data_ptr++ = (UCHAR)(nx_dns_transmit_id >> 8);
633 *data_ptr = (UCHAR)nx_dns_transmit_id;
634
635 /* Send the UDP packet with the correct port. */
636 status = nx_udp_socket_send(server_socket, response_packet, IP_ADDRESS(10, 0, 0, 10), port);
637
638 /* Check the status. */
639 if (status)
640 nx_packet_release(response_packet);
641
642 return status;
643 }
644
dns_test_initialize()645 static void dns_test_initialize()
646 {
647
648 /* DNS A type test. */
649 dns_test[0].dns_test_pkt_data = &response_a_google_com_pkt[0];
650 dns_test[0].dns_test_pkt_size = response_a_google_com_pkt_size;
651 dns_test[1].dns_test_pkt_data = &response_a_google_com_pkt[0];
652 dns_test[1].dns_test_pkt_size = response_a_google_com_pkt_size;
653 dns_test[2].dns_test_pkt_data = &response_a_berkley_edu_pkt[0];
654 dns_test[2].dns_test_pkt_size = response_a_berkley_edu_pkt_size;
655 dns_test[3].dns_test_pkt_data = &response_a_berkley_edu_pkt[0];
656 dns_test[3].dns_test_pkt_size = response_a_berkley_edu_pkt_size;
657
658 /* DNS retransmit test. */
659 dns_test[4].dns_test_pkt_data = &response_a_berkley_edu_pkt[0];
660 dns_test[4].dns_test_pkt_size = response_a_berkley_edu_pkt_size;
661 dns_test[5].dns_test_pkt_data = &response_a_berkley_edu_pkt[0];
662 dns_test[5].dns_test_pkt_size = response_a_berkley_edu_pkt_size;
663 dns_test[6].dns_test_pkt_data = &response_a_berkley_edu_pkt[0];
664 dns_test[6].dns_test_pkt_size = response_a_berkley_edu_pkt_size;
665
666 #ifdef __PRODUCT_NETXDUO__
667
668 #ifdef FEATURE_NX_IPV6
669 /* DNS A type test. */
670 dns_test[7].dns_test_pkt_data = &response_aaaa_berkley_edu_pkt[0];
671 dns_test[7].dns_test_pkt_size = response_aaaa_berkley_edu_pkt_size;
672 dns_test[8].dns_test_pkt_data = &response_aaaa_berkley_edu_pkt[0];
673 dns_test[8].dns_test_pkt_size = response_aaaa_berkley_edu_pkt_size;
674
675 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
676
677 /* DNS extended type test. */
678 dns_test[9].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
679 dns_test[9].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
680 dns_test[10].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
681 dns_test[10].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
682 dns_test[11].dns_test_pkt_data = &response_mx_google_com_pkt[0];
683 dns_test[11].dns_test_pkt_size = response_mx_google_com_pkt_size;
684 dns_test[12].dns_test_pkt_data = &response_mx_a_google_com_pkt[0];
685 dns_test[12].dns_test_pkt_size = response_mx_a_google_com_pkt_size;
686 dns_test[13].dns_test_pkt_data = &response_mx_a_berkley_edu_pkt[0];
687 dns_test[13].dns_test_pkt_size = response_mx_a_berkley_edu_pkt_size;
688 dns_test[14].dns_test_pkt_data = &response_cname_www_baidu_com_pkt[0];
689 dns_test[14].dns_test_pkt_size = response_cname_www_baidu_com_pkt_size;
690 dns_test[15].dns_test_pkt_data = &response_ns_a_ti_com_pkt[0];
691 dns_test[15].dns_test_pkt_size = response_ns_a_ti_com_pkt_size;
692 dns_test[16].dns_test_pkt_data = &response_srv_google_com_pkt[0];
693 dns_test[16].dns_test_pkt_size = response_srv_google_com_pkt_size;
694 dns_test[17].dns_test_pkt_data = &response_txt_google_com_pkt[0];
695 dns_test[17].dns_test_pkt_size = response_txt_google_com_pkt_size;
696 dns_test[18].dns_test_pkt_data = &response_soa_google_com_pkt[0];
697 dns_test[18].dns_test_pkt_size = response_soa_google_com_pkt_size;
698 #endif /* NX_DNS_ENABLE_EXTENDED_RR_TYPES */
699
700 #else /* FEATURE_NX_IPV6 */
701
702 /* DNS A type test. */
703 dns_test[7].dns_test_pkt_data = &response_aaaa_berkley_edu_pkt[0];
704 dns_test[7].dns_test_pkt_size = response_aaaa_berkley_edu_pkt_size;
705
706 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
707
708 /* DNS extended type test. */
709 dns_test[8].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
710 dns_test[8].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
711 dns_test[9].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
712 dns_test[9].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
713 dns_test[10].dns_test_pkt_data = &response_mx_google_com_pkt[0];
714 dns_test[10].dns_test_pkt_size = response_mx_google_com_pkt_size;
715 dns_test[11].dns_test_pkt_data = &response_mx_a_google_com_pkt[0];
716 dns_test[11].dns_test_pkt_size = response_mx_a_google_com_pkt_size;
717 dns_test[12].dns_test_pkt_data = &response_mx_a_berkley_edu_pkt[0];
718 dns_test[12].dns_test_pkt_size = response_mx_a_berkley_edu_pkt_size;
719 dns_test[13].dns_test_pkt_data = &response_cname_www_baidu_com_pkt[0];
720 dns_test[13].dns_test_pkt_size = response_cname_www_baidu_com_pkt_size;
721 dns_test[14].dns_test_pkt_data = &response_ns_a_ti_com_pkt[0];
722 dns_test[14].dns_test_pkt_size = response_ns_a_ti_com_pkt_size;
723 dns_test[15].dns_test_pkt_data = &response_srv_google_com_pkt[0];
724 dns_test[15].dns_test_pkt_size = response_srv_google_com_pkt_size;
725 dns_test[16].dns_test_pkt_data = &response_txt_google_com_pkt[0];
726 dns_test[16].dns_test_pkt_size = response_txt_google_com_pkt_size;
727 dns_test[17].dns_test_pkt_data = &response_soa_google_com_pkt[0];
728 dns_test[17].dns_test_pkt_size = response_soa_google_com_pkt_size;
729 #endif /* NX_DNS_ENABLE_EXTENDED_RR_TYPES */
730 #endif /* FEATURE_NX_IPV6 */
731
732 #else /* __PRODUCT_NETXDUO__ */
733
734 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
735
736 /* DNS extended type test. */
737 dns_test[7].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
738 dns_test[7].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
739 dns_test[8].dns_test_pkt_data = &response_a_cname_www_npr_org_pkt[0];
740 dns_test[8].dns_test_pkt_size = response_a_cname_www_npr_org_pkt_size;
741 dns_test[9].dns_test_pkt_data = &response_mx_google_com_pkt[0];
742 dns_test[9].dns_test_pkt_size = response_mx_google_com_pkt_size;
743 dns_test[10].dns_test_pkt_data = &response_mx_a_google_com_pkt[0];
744 dns_test[10].dns_test_pkt_size = response_mx_a_google_com_pkt_size;
745 dns_test[11].dns_test_pkt_data = &response_mx_a_berkley_edu_pkt[0];
746 dns_test[11].dns_test_pkt_size = response_mx_a_berkley_edu_pkt_size;
747 dns_test[12].dns_test_pkt_data = &response_cname_www_baidu_com_pkt[0];
748 dns_test[12].dns_test_pkt_size = response_cname_www_baidu_com_pkt_size;
749 dns_test[13].dns_test_pkt_data = &response_ns_a_ti_com_pkt[0];
750 dns_test[13].dns_test_pkt_size = response_ns_a_ti_com_pkt_size;
751 dns_test[14].dns_test_pkt_data = &response_srv_google_com_pkt[0];
752 dns_test[14].dns_test_pkt_size = response_srv_google_com_pkt_size;
753 dns_test[15].dns_test_pkt_data = &response_txt_google_com_pkt[0];
754 dns_test[15].dns_test_pkt_size = response_txt_google_com_pkt_size;
755 dns_test[16].dns_test_pkt_data = &response_soa_google_com_pkt[0];
756 dns_test[16].dns_test_pkt_size = response_soa_google_com_pkt_size;
757 #endif /* NX_DNS_ENABLE_EXTENDED_RR_TYPES */
758
759 #endif /* __PRODUCT_NETXDUO__ */
760 }
761
dns_a_type_test()762 static void dns_a_type_test()
763 {
764 ULONG host_ip_address;
765 ULONG *ipv4_address_ptr1;
766 ULONG *ipv4_address_ptr2;
767 ULONG *ipv4_address_ptr3;
768 ULONG *ipv4_address_ptr4;
769 ULONG *ipv4_address_ptr5;
770 ULONG *ipv4_address_ptr6;
771 ULONG *ipv4_address_ptr7;
772 ULONG *ipv4_address_ptr8;
773 ULONG *ipv4_address_ptr9;
774 ULONG *ipv4_address_ptr10;
775 ULONG *ipv4_address_ptr11;
776
777 /* Test the A type with the old API,(google.com.) */
778 /* Print out some test information banners. */
779 printf("NetX Test: DNS A Type Google Com Old API Record Singer Addr Test.....");
780
781 /* Secd dns query, and record the single host ip address. */
782 status = nx_dns_host_by_name_get(&client_dns, (UCHAR *)"google.com", &host_ip_address, 4 * NX_IP_PERIODIC_RATE);
783
784 /* Check status and compare the host ip address. */
785 if (status || host_ip_address != IP_ADDRESS(74,125,224,194))
786 {
787 error_counter++;
788 }
789
790 /* Printf the test result. */
791 if (error_counter)
792 {
793 printf("ERROR!\n");
794 test_control_failed_tests++;
795 }
796 else
797 {
798 printf("SUCCESS!\n");
799 test_control_successful_tests++;
800 }
801
802
803 /* Test the A type with the new API,(google.com.) */
804 /* Print out some test information banners. */
805 printf("NetX Test: DNS A Type Google Com New API Record Multi Addr Test......");
806
807 /* Test the A type NetX(new API) to process the multiple address. */
808 status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"google.com", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
809
810 /* Check the record buffer. */
811 ipv4_address_ptr1 = (ULONG *)record_buffer;
812 ipv4_address_ptr2 = (ULONG *)(record_buffer + 4);
813 ipv4_address_ptr3 = (ULONG *)(record_buffer + 8);
814 ipv4_address_ptr4 = (ULONG *)(record_buffer + 12);
815 ipv4_address_ptr5 = (ULONG *)(record_buffer + 16);
816 ipv4_address_ptr6 = (ULONG *)(record_buffer + 20);
817 ipv4_address_ptr7 = (ULONG *)(record_buffer + 24);
818 ipv4_address_ptr8 = (ULONG *)(record_buffer + 28);
819 ipv4_address_ptr9 = (ULONG *)(record_buffer + 32);
820 ipv4_address_ptr10 = (ULONG *)(record_buffer + 36);
821 ipv4_address_ptr11 = (ULONG *)(record_buffer + 40);
822
823 /* Check status and compare the host ip address. */
824 if (status || (record_count != 11) ||
825 (*ipv4_address_ptr1 != IP_ADDRESS(74,125,224,194)) ||
826 (*ipv4_address_ptr2 != IP_ADDRESS(74,125,224,195)) ||
827 (*ipv4_address_ptr3 != IP_ADDRESS(74,125,224,196)) ||
828 (*ipv4_address_ptr4 != IP_ADDRESS(74,125,224,197)) ||
829 (*ipv4_address_ptr5 != IP_ADDRESS(74,125,224,198)) ||
830 (*ipv4_address_ptr6 != IP_ADDRESS(74,125,224,199)) ||
831 (*ipv4_address_ptr7 != IP_ADDRESS(74,125,224,200)) ||
832 (*ipv4_address_ptr8 != IP_ADDRESS(74,125,224,201)) ||
833 (*ipv4_address_ptr9 != IP_ADDRESS(74,125,224,206)) ||
834 (*ipv4_address_ptr10 != IP_ADDRESS(74,125,224,192))||
835 (*ipv4_address_ptr11 != IP_ADDRESS(74,125,224,193)))
836 {
837 error_counter++;
838 }
839
840 /* Printf the test result. */
841 if (error_counter)
842 {
843 printf("ERROR!\n");
844 test_control_failed_tests++;
845 }
846 else
847 {
848 printf("SUCCESS!\n");
849 test_control_successful_tests++;
850 }
851
852
853 /* Test the A type with the old API,(berkeley.edu.) */
854 /* Print out some test information banners. */
855 printf("NetX Test: DNS A Type Berkley Edu Old API Record Singer Addr Test....");
856
857 /* Secd dns query, and record the single host ip address. */
858 status = nx_dns_host_by_name_get(&client_dns, (UCHAR *)"berkeley.edu", &host_ip_address, 4 * NX_IP_PERIODIC_RATE);
859
860 /* Check status and compare the host ip address. */
861 if (status || host_ip_address != IP_ADDRESS(169,229,216,200))
862 {
863 error_counter++;
864 }
865
866 /* Printf the test result. */
867 if (error_counter)
868 {
869 printf("ERROR!\n");
870 test_control_failed_tests++;
871 }
872 else
873 {
874 printf("SUCCESS!\n");
875 test_control_successful_tests++;
876 }
877
878
879 /* Test the A type with the new API,(berkeley.edu.) */
880 /* Print out some test information banners. */
881 printf("NetX Test: DNS A Type Berkley Edu New API Record Multi Addr Test.....");
882
883 /* Test the A type NetX(new API) to process the multiple address. */
884 status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"berkeley.edu", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
885
886 /* Check the record buffer. */
887 ipv4_address_ptr1 = (ULONG *)record_buffer;
888
889 /* Check status and compare the host ip address. */
890 if (status || (record_count != 1) ||
891 (*ipv4_address_ptr1 != IP_ADDRESS(169,229,216,200)))
892 {
893 error_counter++;
894 }
895
896 /* Printf the test result. */
897 if (error_counter)
898 {
899 printf("ERROR!\n");
900 test_control_failed_tests++;
901 }
902 else
903 {
904 printf("SUCCESS!\n");
905 test_control_successful_tests++;
906 }
907
908 }
909
dns_retransmit_test()910 static void dns_retransmit_test()
911 {
912 ULONG *ipv4_address_ptr1;
913
914 /* Test DNS Query retransmission the A type with the new API,(berkeley.edu.) */
915 /* Print out some test information banners. */
916 printf("NetX Test: DNS A Type Berkley Edu New API Retransmission Test........");
917
918 /* Test the A type NetX(new API) to process the multiple address. */
919 status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"berkeley.edu", &record_buffer[0], 500, &record_count, 2 * NX_IP_PERIODIC_RATE);
920
921 /* Check the record buffer. */
922 ipv4_address_ptr1 = (ULONG *)record_buffer;
923
924 /* Check status and compare the host ip address. */
925 if (status || (record_count != 1) ||
926 (*ipv4_address_ptr1 != IP_ADDRESS(169,229,216,200)))
927 {
928 error_counter++;
929 }
930
931 /* Printf the test result. */
932 if (error_counter)
933 {
934 printf("ERROR!\n");
935 test_control_failed_tests++;
936 }
937 else
938 {
939 printf("SUCCESS!\n");
940 test_control_successful_tests++;
941 }
942
943 }
944
945 #ifdef __PRODUCT_NETXDUO__
dns_aaaa_type_test()946 static void dns_aaaa_type_test()
947 {
948
949 NX_DNS_IPV6_ADDRESS *ipv6_address_ptr;
950
951 #ifdef FEATURE_NX_IPV6
952 NXD_ADDRESS host_ipduo_address;
953 #endif
954
955 #ifdef FEATURE_NX_IPV6
956 /* Test the AAAA type with the old API,(berkeley.edu.) */
957 /* Print out some test information banners. */
958 printf("NetX Test: DNS AAAA Type Berkley Edu Old API Record Singer Addr Test.");
959
960 /* Secd DNS AAAA query, and record the single host ip address. */
961 status = nxd_dns_host_by_name_get(&client_dns, (UCHAR *)"berkeley.edu", &host_ipduo_address, 4 * NX_IP_PERIODIC_RATE, NX_IP_VERSION_V6);
962
963 /* Check status and compare the host ip address. */
964 if (status ||
965 host_ipduo_address.nxd_ip_address.v6[0] != 0x2607f140 ||
966 host_ipduo_address.nxd_ip_address.v6[1] != 0x00000081 ||
967 host_ipduo_address.nxd_ip_address.v6[2] != 0x00000000 ||
968 host_ipduo_address.nxd_ip_address.v6[3] != 0x0000000f)
969 {
970 error_counter++;
971 }
972
973 /* Printf the test result. */
974 if (error_counter)
975 {
976 printf("ERROR!\n");
977 test_control_failed_tests++;
978 }
979 else
980 {
981 printf("SUCCESS!\n");
982 test_control_successful_tests++;
983 }
984 #endif
985
986 /* Test the A type with the new API,(berkeley.edu.) */
987 /* Print out some test information banners. */
988 printf("NetX Test: DNS AAAA Type Berkley Edu New API Record Multi Addr Test..");
989
990 /* Test the AAAA type NetX Duo(new API) to process the multiple address. */
991 status = nxd_dns_ipv6_address_by_name_get(&client_dns, (UCHAR *)"berkeley.edu", &record_buffer[0], 200, &record_count, 4 * NX_IP_PERIODIC_RATE);
992
993 ipv6_address_ptr = (NX_DNS_IPV6_ADDRESS *)record_buffer;
994
995 /* Check the record buffer. */
996 /* Check status and compare the host ip address. */
997 if (status || record_count != 1 ||
998 (*ipv6_address_ptr).ipv6_address[0] != 0x2607f140 ||
999 (*ipv6_address_ptr).ipv6_address[1] != 0x00000081 ||
1000 (*ipv6_address_ptr).ipv6_address[2] != 0x00000000 ||
1001 (*ipv6_address_ptr).ipv6_address[3] != 0x0000000f)
1002 {
1003 error_counter++;
1004 }
1005
1006 /* Printf the test result. */
1007 if (error_counter)
1008 {
1009 printf("ERROR!\n");
1010 test_control_failed_tests++;
1011 }
1012 else
1013 {
1014 printf("SUCCESS!\n");
1015 test_control_successful_tests++;
1016 }
1017 }
1018 #endif /* __PRODUCT_NETXDUO__ */
1019
1020
1021 #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES
1022
dns_a_cname_type_test()1023 static void dns_a_cname_type_test()
1024 {
1025 ULONG host_ip_address;
1026 ULONG *ipv4_address_ptr1;
1027
1028 /* Test the A type with the old API,(google.com.) */
1029 /* Print out some test information banners. */
1030 printf("NetX Test: DNS A CNAME Type Www Npr Org Old API Test.................");
1031
1032 /* Secd dns query, and record the single host ip address. */
1033 status = nx_dns_host_by_name_get(&client_dns, (UCHAR *)"www.npr.org", &host_ip_address, 4 * NX_IP_PERIODIC_RATE);
1034
1035 /* Check status and compare the host ip address. */
1036 if (status || host_ip_address != IP_ADDRESS(216,35,221,76))
1037 {
1038 error_counter++;
1039 }
1040
1041 /* Printf the test result. */
1042 if (error_counter)
1043 {
1044 printf("ERROR!\n");
1045 test_control_failed_tests++;
1046 }
1047 else
1048 {
1049 printf("SUCCESS!\n");
1050 test_control_successful_tests++;
1051 }
1052
1053
1054 /* Test the A type with the new API,(google.com.) */
1055 /* Print out some test information banners. */
1056 printf("NetX Test: DNS A CNAME Type Www Npr Org New API Test.................");
1057
1058 /* Test the A type NetX(new API) to process the multiple address. */
1059 status = nx_dns_ipv4_address_by_name_get(&client_dns, (UCHAR *)"www.npr.org", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
1060
1061 /* Check the record buffer. */
1062 ipv4_address_ptr1 = (ULONG *)record_buffer;
1063
1064 /* Check status and compare the host ip address. */
1065 if (status || (record_count != 1) ||
1066 (*ipv4_address_ptr1 != IP_ADDRESS(216,35,221,76)))
1067 {
1068 error_counter++;
1069 }
1070
1071 /* Printf the test result. */
1072 if (error_counter)
1073 {
1074 printf("ERROR!\n");
1075 test_control_failed_tests++;
1076 }
1077 else
1078 {
1079 printf("SUCCESS!\n");
1080 test_control_successful_tests++;
1081 }
1082
1083 }
1084
dns_mx_type_test()1085 static void dns_mx_type_test()
1086 {
1087
1088 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr1;
1089 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr2;
1090 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr3;
1091 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr4;
1092 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr5;
1093
1094 /* Test the MX type (google.com.) */
1095 /* Print out some test information banners. */
1096 printf("NetX Test: DNS MX Type Google Com New API Record Multi MX Test.......");
1097
1098 /* Secd DNS MX query, and record the multiple mail exchange info. */
1099 status = nx_dns_domain_mail_exchange_get(&client_dns, (UCHAR *)"google.com", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
1100
1101
1102 /* Check the record buffer. */
1103 nx_dns_mx_entry_ptr1 = (NX_DNS_MX_ENTRY *)record_buffer;
1104 nx_dns_mx_entry_ptr2 = (NX_DNS_MX_ENTRY *)(record_buffer + sizeof(NX_DNS_MX_ENTRY));
1105 nx_dns_mx_entry_ptr3 = (NX_DNS_MX_ENTRY *)(record_buffer + (2 * sizeof(NX_DNS_MX_ENTRY)));
1106 nx_dns_mx_entry_ptr4 = (NX_DNS_MX_ENTRY *)(record_buffer + (3 * sizeof(NX_DNS_MX_ENTRY)));
1107 nx_dns_mx_entry_ptr5 = (NX_DNS_MX_ENTRY *)(record_buffer + (4 * sizeof(NX_DNS_MX_ENTRY)));
1108
1109 /* Check status and compare the host ip address. */
1110 if (status || record_count != 5)
1111 {
1112 error_counter++;
1113 }
1114
1115 /* Check the all mail exchange info. */
1116 if(nx_dns_mx_entry_ptr1 -> nx_dns_mx_preference != 50 ||
1117 memcmp(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr, "alt4.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr))))
1118 {
1119 error_counter++;
1120 }
1121
1122 /* Check the all mail exchange info. */
1123 if(nx_dns_mx_entry_ptr2 -> nx_dns_mx_preference != 30 ||
1124 memcmp(nx_dns_mx_entry_ptr2 -> nx_dns_mx_hostname_ptr, "alt2.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr2 -> nx_dns_mx_hostname_ptr))))
1125 {
1126 error_counter++;
1127 }
1128
1129 /* Check the all mail exchange info. */
1130 if(nx_dns_mx_entry_ptr3 -> nx_dns_mx_preference != 10 ||
1131 memcmp(nx_dns_mx_entry_ptr3 -> nx_dns_mx_hostname_ptr, "aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr3 -> nx_dns_mx_hostname_ptr))))
1132 {
1133 error_counter++;
1134 }
1135
1136 /* Check the all mail exchange info. */
1137 if(nx_dns_mx_entry_ptr4 -> nx_dns_mx_preference != 20 ||
1138 memcmp(nx_dns_mx_entry_ptr4 -> nx_dns_mx_hostname_ptr, "alt1.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr4 -> nx_dns_mx_hostname_ptr))))
1139 {
1140 error_counter++;
1141 }
1142
1143 /* Check the all mail exchange info. */
1144 if(nx_dns_mx_entry_ptr5 -> nx_dns_mx_preference != 40 ||
1145 memcmp(nx_dns_mx_entry_ptr5 -> nx_dns_mx_hostname_ptr, "alt3.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr5 -> nx_dns_mx_hostname_ptr))))
1146 {
1147 error_counter++;
1148 }
1149
1150 /* Printf the test result. */
1151 if (error_counter)
1152 {
1153 printf("ERROR!\n");
1154 test_control_failed_tests++;
1155 }
1156 else
1157 {
1158 printf("SUCCESS!\n");
1159 test_control_successful_tests++;
1160 }
1161
1162 }
1163
1164
1165
dns_mx_a_type_test()1166 static void dns_mx_a_type_test()
1167 {
1168
1169 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr1;
1170 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr2;
1171 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr3;
1172 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr4;
1173 NX_DNS_MX_ENTRY *nx_dns_mx_entry_ptr5;
1174
1175 /* Test the MX&A type (google.com.) */
1176 /* Print out some test information banners. */
1177 printf("NetX Test: DNS MX&A Type Google Com New API Record Multi MX Test.....");
1178
1179 /* Secd DNS MX query, and record the multiple mail exchange info. */
1180 status = nx_dns_domain_mail_exchange_get(&client_dns, (UCHAR *)"google.com", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
1181
1182
1183 /* Check the record buffer. */
1184 nx_dns_mx_entry_ptr1 = (NX_DNS_MX_ENTRY *)record_buffer;
1185 nx_dns_mx_entry_ptr2 = (NX_DNS_MX_ENTRY *)(record_buffer + sizeof(NX_DNS_MX_ENTRY));
1186 nx_dns_mx_entry_ptr3 = (NX_DNS_MX_ENTRY *)(record_buffer + (2 * sizeof(NX_DNS_MX_ENTRY)));
1187 nx_dns_mx_entry_ptr4 = (NX_DNS_MX_ENTRY *)(record_buffer + (3 * sizeof(NX_DNS_MX_ENTRY)));
1188 nx_dns_mx_entry_ptr5 = (NX_DNS_MX_ENTRY *)(record_buffer + (4 * sizeof(NX_DNS_MX_ENTRY)));
1189
1190 /* Check status and compare the host ip address. */
1191 if (status || record_count != 5)
1192 {
1193 error_counter++;
1194 }
1195
1196 /* Check the all mail exchange info. */
1197 if(nx_dns_mx_entry_ptr1 -> nx_dns_mx_preference != 20 ||
1198 nx_dns_mx_entry_ptr1 -> nx_dns_mx_ipv4_address != IP_ADDRESS(209,85,225,26) ||
1199 memcmp(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr, "alt1.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr))))
1200 {
1201 error_counter++;
1202 }
1203
1204 /* Check the all mail exchange info. */
1205 if(nx_dns_mx_entry_ptr2 -> nx_dns_mx_preference != 30 ||
1206 nx_dns_mx_entry_ptr2 -> nx_dns_mx_ipv4_address != IP_ADDRESS(74,125,130,26) ||
1207 memcmp(nx_dns_mx_entry_ptr2 -> nx_dns_mx_hostname_ptr, "alt2.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr2 -> nx_dns_mx_hostname_ptr))))
1208 {
1209 error_counter++;
1210 }
1211
1212 /* Check the all mail exchange info. */
1213 if(nx_dns_mx_entry_ptr3 -> nx_dns_mx_preference != 40 ||
1214 nx_dns_mx_entry_ptr3 -> nx_dns_mx_ipv4_address != IP_ADDRESS(173,194,76,26) ||
1215 memcmp(nx_dns_mx_entry_ptr3 -> nx_dns_mx_hostname_ptr, "alt3.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr3 -> nx_dns_mx_hostname_ptr))))
1216 {
1217 error_counter++;
1218 }
1219
1220 /* Check the all mail exchange info. */
1221 if(nx_dns_mx_entry_ptr4 -> nx_dns_mx_preference != 50 ||
1222 nx_dns_mx_entry_ptr4 -> nx_dns_mx_ipv4_address != IP_ADDRESS(173,194,73,26) ||
1223 memcmp(nx_dns_mx_entry_ptr4 -> nx_dns_mx_hostname_ptr, "alt4.aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr4 -> nx_dns_mx_hostname_ptr))))
1224 {
1225 error_counter++;
1226 }
1227
1228 /* Check the all mail exchange info. */
1229 if(nx_dns_mx_entry_ptr5 -> nx_dns_mx_preference != 10 ||
1230 nx_dns_mx_entry_ptr5 -> nx_dns_mx_ipv4_address != IP_ADDRESS(173,194,79,26) ||
1231 memcmp(nx_dns_mx_entry_ptr5 -> nx_dns_mx_hostname_ptr, "aspmx.l.google.com", strlen((const char*)(nx_dns_mx_entry_ptr5 -> nx_dns_mx_hostname_ptr))))
1232 {
1233 error_counter++;
1234 }
1235
1236 /* Printf the test result. */
1237 if (error_counter)
1238 {
1239 printf("ERROR!\n");
1240 test_control_failed_tests++;
1241 }
1242 else
1243 {
1244 printf("SUCCESS!\n");
1245 test_control_successful_tests++;
1246 }
1247
1248
1249 /* Test the MX&A type (berkeley.com.) */
1250 /* Print out some test information banners. */
1251 printf("NetX Test: DNS MX&A Type Berkley Com New API Record Multi MX Test....");
1252
1253 /* Secd DNS MX query, and record the multiple mail exchange info. */
1254 status = nx_dns_domain_mail_exchange_get(&client_dns, (UCHAR *)"berkeley.edu", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
1255
1256 /* Check the record buffer. */
1257 nx_dns_mx_entry_ptr1 = (NX_DNS_MX_ENTRY *)record_buffer;
1258
1259 /* Check status and compare the host ip address. */
1260 if (status || record_count != 1)
1261 {
1262 error_counter++;
1263 }
1264
1265 /* Check the all mail exchange info. */
1266 if(nx_dns_mx_entry_ptr1 -> nx_dns_mx_preference != 10 ||
1267 nx_dns_mx_entry_ptr1 -> nx_dns_mx_ipv4_address != IP_ADDRESS(169,229,218,141) ||
1268 memcmp(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr, "mx.berkeley.edu", strlen((const char*)(nx_dns_mx_entry_ptr1 -> nx_dns_mx_hostname_ptr))))
1269 {
1270 error_counter++;
1271 }
1272
1273 /* Printf the test result. */
1274 if (error_counter)
1275 {
1276 printf("ERROR!\n");
1277 test_control_failed_tests++;
1278 }
1279 else
1280 {
1281 printf("SUCCESS!\n");
1282 test_control_successful_tests++;
1283 }
1284
1285 }
1286
1287
dns_cname_type_test()1288 static void dns_cname_type_test()
1289 {
1290
1291 /* Test the CNAME type (mail.baidu.com.) */
1292 /* Print out some test information banners. */
1293 printf("NetX Test: DNS CNAME Type Www Baidu Com New API Record Cname Test....");
1294
1295 /* Secd DNS CNAME query, and record the cname info. */
1296 status = nx_dns_cname_get(&client_dns, (UCHAR *)"www.baidu.com", &record_buffer[0], 500, 4 * NX_IP_PERIODIC_RATE);
1297
1298 /* Check status and compare the host ip address. */
1299 if (status ||
1300 memcmp(record_buffer, "www.a.shifen.com", strlen((const char*)(&record_buffer[0]))))
1301 {
1302 error_counter++;
1303 }
1304
1305 /* Printf the test result. */
1306 if (error_counter)
1307 {
1308 printf("ERROR!\n");
1309 test_control_failed_tests++;
1310 }
1311 else
1312 {
1313 printf("SUCCESS!\n");
1314 test_control_successful_tests++;
1315 }
1316
1317 }
1318
dns_ns_a_type_test()1319 static void dns_ns_a_type_test()
1320 {
1321
1322 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr1;
1323 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr2;
1324 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr3;
1325 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr4;
1326 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr5;
1327 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr6;
1328 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr7;
1329 NX_DNS_NS_ENTRY *nx_dns_ns_entry_ptr8;
1330
1331 /* Test the NS&A type (ti.com.) */
1332 /* Print out some test information banners. */
1333 printf("NetX Test: DNS NS&A Type Ti Com New API Record Multi NS Test.........");
1334
1335 /* Secd DNS NS query, and record the multiple name server info. */
1336 status = nx_dns_domain_name_server_get(&client_dns, (UCHAR *)"ti.com", &record_buffer[0], 200, &record_count, 4 * NX_IP_PERIODIC_RATE);
1337
1338 /* Check the record buffer. */
1339 nx_dns_ns_entry_ptr1 = (NX_DNS_NS_ENTRY *)record_buffer;
1340 nx_dns_ns_entry_ptr2 = (NX_DNS_NS_ENTRY *)(record_buffer + sizeof(NX_DNS_NS_ENTRY));
1341 nx_dns_ns_entry_ptr3 = (NX_DNS_NS_ENTRY *)(record_buffer + (2 * sizeof(NX_DNS_NS_ENTRY)));
1342 nx_dns_ns_entry_ptr4 = (NX_DNS_NS_ENTRY *)(record_buffer + (3 * sizeof(NX_DNS_NS_ENTRY)));
1343 nx_dns_ns_entry_ptr5 = (NX_DNS_NS_ENTRY *)(record_buffer + (4 * sizeof(NX_DNS_NS_ENTRY)));
1344 nx_dns_ns_entry_ptr6 = (NX_DNS_NS_ENTRY *)(record_buffer + (5 * sizeof(NX_DNS_NS_ENTRY)));
1345 nx_dns_ns_entry_ptr7 = (NX_DNS_NS_ENTRY *)(record_buffer + (6 * sizeof(NX_DNS_NS_ENTRY)));
1346 nx_dns_ns_entry_ptr8 = (NX_DNS_NS_ENTRY *)(record_buffer + (7 * sizeof(NX_DNS_NS_ENTRY)));
1347
1348 /* Check status and compare the host ip address. */
1349 if (status || record_count != 8)
1350 {
1351 error_counter++;
1352 }
1353
1354 /* Check the all mail exchange info. */
1355 if(nx_dns_ns_entry_ptr8 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(64,95,61,4) ||
1356 memcmp(nx_dns_ns_entry_ptr8 -> nx_dns_ns_hostname_ptr, "ns-c.pnap.net", strlen((const char*)(nx_dns_ns_entry_ptr8 -> nx_dns_ns_hostname_ptr))))
1357 {
1358 error_counter++;
1359 }
1360
1361 /* Check the all mail exchange info. */
1362 if(nx_dns_ns_entry_ptr7 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(64,94,123,4) ||
1363 memcmp(nx_dns_ns_entry_ptr7 -> nx_dns_ns_hostname_ptr, "ns-a.pnap.net", strlen((const char*)(nx_dns_ns_entry_ptr7 -> nx_dns_ns_hostname_ptr))))
1364 {
1365 error_counter++;
1366 }
1367
1368 /* Check the all mail exchange info. */
1369 if(nx_dns_ns_entry_ptr6 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(192,94,94,43) ||
1370 memcmp(nx_dns_ns_entry_ptr6 -> nx_dns_ns_hostname_ptr, "ns2.ti.com", strlen((const char*)(nx_dns_ns_entry_ptr6 -> nx_dns_ns_hostname_ptr))))
1371 {
1372 error_counter++;
1373 }
1374
1375
1376 /* Check the all mail exchange info. */
1377 if(nx_dns_ns_entry_ptr5 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(192,94,94,42) ||
1378 memcmp(nx_dns_ns_entry_ptr5 -> nx_dns_ns_hostname_ptr, "ns.ti.com", strlen((const char*)(nx_dns_ns_entry_ptr5 -> nx_dns_ns_hostname_ptr))))
1379 {
1380 error_counter++;
1381 }
1382
1383 /* Check the all mail exchange info. */
1384 if(nx_dns_ns_entry_ptr4 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(198,47,26,151) ||
1385 memcmp(nx_dns_ns_entry_ptr4 -> nx_dns_ns_hostname_ptr, "ns4.ti.com", strlen((const char*)(nx_dns_ns_entry_ptr4 -> nx_dns_ns_hostname_ptr))))
1386 {
1387 error_counter++;
1388 }
1389
1390 /* Check the all mail exchange info. */
1391 if(nx_dns_ns_entry_ptr3 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(198,47,26,150) ||
1392 memcmp(nx_dns_ns_entry_ptr3 -> nx_dns_ns_hostname_ptr, "ns3.ti.com", strlen((const char*)(nx_dns_ns_entry_ptr3 -> nx_dns_ns_hostname_ptr))))
1393 {
1394 error_counter++;
1395 }
1396
1397 /* Check the all mail exchange info. */
1398 if(nx_dns_ns_entry_ptr2 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(64,94,123,36) ||
1399 memcmp(nx_dns_ns_entry_ptr2 -> nx_dns_ns_hostname_ptr, "ns-b.pnap.net", strlen((const char*)(nx_dns_ns_entry_ptr2 -> nx_dns_ns_hostname_ptr))))
1400 {
1401 error_counter++;
1402 }
1403
1404 /* Check the all mail exchange info. */
1405 if(nx_dns_ns_entry_ptr1 -> nx_dns_ns_ipv4_address!= IP_ADDRESS(64,95,61,36) ||
1406 memcmp(nx_dns_ns_entry_ptr1 -> nx_dns_ns_hostname_ptr, "ns-d.pnap.net", strlen((const char*)(nx_dns_ns_entry_ptr1 -> nx_dns_ns_hostname_ptr))))
1407 {
1408 error_counter++;
1409 }
1410
1411 /* Printf the test result. */
1412 if (error_counter)
1413 {
1414 printf("ERROR!\n");
1415 test_control_failed_tests++;
1416 }
1417 else
1418 {
1419 printf("SUCCESS!\n");
1420 test_control_successful_tests++;
1421 }
1422 }
1423
1424
dns_srv_type_test()1425 static void dns_srv_type_test()
1426 {
1427
1428 NX_DNS_SRV_ENTRY *nx_dns_srv_entry_ptr1;
1429 NX_DNS_SRV_ENTRY *nx_dns_srv_entry_ptr2;
1430 NX_DNS_SRV_ENTRY *nx_dns_srv_entry_ptr3;
1431 NX_DNS_SRV_ENTRY *nx_dns_srv_entry_ptr4;
1432 NX_DNS_SRV_ENTRY *nx_dns_srv_entry_ptr5;
1433
1434 /* Test the SRV type (google.com.) */
1435 /* Print out some test information banners. */
1436 printf("NetX Test: DNS SRV Type Google Com New API Record Multi service Test.");
1437
1438 /* Secd DNS SRV query, and record the multiple service info. */
1439 status = nx_dns_domain_service_get(&client_dns, (UCHAR *)"_xmpp-client._tcp.google.com", &record_buffer[0], 500, &record_count, 4 * NX_IP_PERIODIC_RATE);
1440
1441 /* Check the record buffer. */
1442 nx_dns_srv_entry_ptr1 = (NX_DNS_SRV_ENTRY *)record_buffer;
1443 nx_dns_srv_entry_ptr2 = (NX_DNS_SRV_ENTRY *)(record_buffer + sizeof(NX_DNS_SRV_ENTRY));
1444 nx_dns_srv_entry_ptr3 = (NX_DNS_SRV_ENTRY *)(record_buffer + (2 * sizeof(NX_DNS_SRV_ENTRY)));
1445 nx_dns_srv_entry_ptr4 = (NX_DNS_SRV_ENTRY *)(record_buffer + (3 * sizeof(NX_DNS_SRV_ENTRY)));
1446 nx_dns_srv_entry_ptr5 = (NX_DNS_SRV_ENTRY *)(record_buffer + (4 * sizeof(NX_DNS_SRV_ENTRY)));
1447
1448 /* Check status and compare the host ip address. */
1449 if (status || record_count != 5)
1450 {
1451 error_counter++;
1452 }
1453
1454 /* Check the all mail exchange info. */
1455 if(nx_dns_srv_entry_ptr1 -> nx_dns_srv_port_number != 5222 ||
1456 nx_dns_srv_entry_ptr1 -> nx_dns_srv_priority != 20 ||
1457 nx_dns_srv_entry_ptr1 -> nx_dns_srv_weight != 0 ||
1458 memcmp(nx_dns_srv_entry_ptr1 -> nx_dns_srv_hostname_ptr, "alt3.xmpp.l.google.com", strlen((const char*)(nx_dns_srv_entry_ptr1 -> nx_dns_srv_hostname_ptr))))
1459 {
1460 error_counter++;
1461 }
1462
1463 /* Check the all mail exchange info. */
1464 if(nx_dns_srv_entry_ptr2 -> nx_dns_srv_port_number != 5222 ||
1465 nx_dns_srv_entry_ptr2 -> nx_dns_srv_priority != 20 ||
1466 nx_dns_srv_entry_ptr2 -> nx_dns_srv_weight != 0 ||
1467 memcmp(nx_dns_srv_entry_ptr2 -> nx_dns_srv_hostname_ptr, "alt1.xmpp.l.google.com", strlen((const char*)(nx_dns_srv_entry_ptr2 -> nx_dns_srv_hostname_ptr))))
1468 {
1469 error_counter++;
1470 }
1471
1472 /* Check the all mail exchange info. */
1473 if(nx_dns_srv_entry_ptr3 -> nx_dns_srv_port_number != 5222 ||
1474 nx_dns_srv_entry_ptr3 -> nx_dns_srv_priority != 20 ||
1475 nx_dns_srv_entry_ptr3 -> nx_dns_srv_weight != 0 ||
1476 memcmp(nx_dns_srv_entry_ptr3 -> nx_dns_srv_hostname_ptr, "alt4.xmpp.l.google.com", strlen((const char*)(nx_dns_srv_entry_ptr3 -> nx_dns_srv_hostname_ptr))))
1477 {
1478 error_counter++;
1479 }
1480
1481 /* Check the all mail exchange info. */
1482 if(nx_dns_srv_entry_ptr4 -> nx_dns_srv_port_number != 5222 ||
1483 nx_dns_srv_entry_ptr4 -> nx_dns_srv_priority != 5 ||
1484 nx_dns_srv_entry_ptr4 -> nx_dns_srv_weight != 0 ||
1485 memcmp(nx_dns_srv_entry_ptr4 -> nx_dns_srv_hostname_ptr, "xmpp.l.google.com", strlen((const char*)(nx_dns_srv_entry_ptr4 -> nx_dns_srv_hostname_ptr))))
1486 {
1487 error_counter++;
1488 }
1489
1490 /* Check the all mail exchange info. */
1491 if(nx_dns_srv_entry_ptr5 -> nx_dns_srv_port_number != 5222 ||
1492 nx_dns_srv_entry_ptr5 -> nx_dns_srv_priority != 20 ||
1493 nx_dns_srv_entry_ptr5 -> nx_dns_srv_weight != 0 ||
1494 memcmp(nx_dns_srv_entry_ptr5 -> nx_dns_srv_hostname_ptr, "alt2.xmpp.l.google.com", strlen((const char*)(nx_dns_srv_entry_ptr5 -> nx_dns_srv_hostname_ptr))))
1495 {
1496 error_counter++;
1497 }
1498
1499 /* Printf the test result. */
1500 if (error_counter)
1501 {
1502 printf("ERROR!\n");
1503 test_control_failed_tests++;
1504 }
1505 else
1506 {
1507 printf("SUCCESS!\n");
1508 test_control_successful_tests++;
1509 }
1510
1511 }
1512
1513
dns_txt_type_test()1514 static void dns_txt_type_test()
1515 {
1516
1517 /* Test the TXT type (google.com.) */
1518 /* Print out some test information banners. */
1519 printf("NetX Test: DNS TXT Type Google Com New API Record Txt Test...........");
1520
1521 /* Secd DNS CNAME query, and record the cname info. */
1522 status = nx_dns_host_text_get(&client_dns, (UCHAR *)"google.com", &record_buffer[0], 500, 4 * NX_IP_PERIODIC_RATE);
1523
1524 /* Check status and compare the host ip address. */
1525 if (status ||
1526 memcmp(record_buffer, "v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all", strlen((const char*)(&record_buffer[0]))))
1527 {
1528 error_counter++;
1529 }
1530
1531 /* Printf the test result. */
1532 if (error_counter)
1533 {
1534 printf("ERROR!\n");
1535 test_control_failed_tests++;
1536 }
1537 else
1538 {
1539 printf("SUCCESS!\n");
1540 test_control_successful_tests++;
1541 }
1542
1543 }
1544
1545
dns_soa_type_test()1546 static void dns_soa_type_test()
1547 {
1548
1549 NX_DNS_SOA_ENTRY *nx_dns_soa_entry_ptr;
1550
1551 /* Test the SOA type (google.com.) */
1552 /* Print out some test information banners. */
1553 printf("NetX Test: DNS SOA Type Google Com New API Record start of zone Test.");
1554
1555 /* Secd DNS SRV query, and record the multiple service info. */
1556 status = nx_dns_authority_zone_start_get(&client_dns, (UCHAR *)"google.com", &record_buffer[0], 100, 4 * NX_IP_PERIODIC_RATE);
1557
1558 /* Check the record buffer. */
1559 nx_dns_soa_entry_ptr = (NX_DNS_SOA_ENTRY *)record_buffer;
1560
1561 /* Check status and compare the host ip address. */
1562 if (status)
1563 {
1564 error_counter++;
1565 }
1566
1567 /* Check the all mail exchange info. */
1568 if(nx_dns_soa_entry_ptr -> nx_dns_soa_serial != 2012090400 ||
1569 nx_dns_soa_entry_ptr -> nx_dns_soa_refresh != 2 * 60 * 60 ||
1570 nx_dns_soa_entry_ptr -> nx_dns_soa_retry != 30 * 60 ||
1571 nx_dns_soa_entry_ptr -> nx_dns_soa_expire != 14 * 24 * 60 * 60 ||
1572 nx_dns_soa_entry_ptr -> nx_dns_soa_minmum != 5 * 60 ||
1573 memcmp( nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr, "ns1.google.com", strlen((const char*)(nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr))) ||
1574 memcmp( nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr, "dns-admin.google.com", strlen((const char*)(nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr))))
1575 {
1576 error_counter++;
1577 }
1578
1579 /* Printf the test result. */
1580 if (error_counter)
1581 {
1582 printf("ERROR!\n");
1583 test_control_failed_tests++;
1584 }
1585 else
1586 {
1587 printf("SUCCESS!\n");
1588 test_control_successful_tests++;
1589 }
1590
1591 }
1592
1593 #endif
1594 #else
1595
1596 #ifdef CTEST
test_application_define(void * first_unused_memory)1597 VOID test_application_define(void *first_unused_memory)
1598 #else
1599 void netx_dns_function_test_application_define(void *first_unused_memory)
1600 #endif
1601 {
1602
1603 /* Print out test information banner. */
1604 printf("NetX Test: DNS Function Test.........................................N/A\n");
1605
1606 test_control_return(3);
1607 }
1608 #endif