@@ -124,6 +124,7 @@ struct dns_query_data_s
124
124
*
125
125
****************************************************************************/
126
126
127
+ #ifdef CONFIG_NETDB_DNS_STREAM
127
128
static ssize_t stream_send (int fd , FAR const void * buf , size_t len )
128
129
{
129
130
ssize_t total = 0 ;
@@ -292,6 +293,7 @@ static ssize_t stream_recv_record(int fd, FAR void *buf, size_t len)
292
293
293
294
return ret ;
294
295
}
296
+ #endif
295
297
296
298
/****************************************************************************
297
299
* Name: dns_parse_name
@@ -380,11 +382,18 @@ static inline uint16_t dns_alloc_id(void)
380
382
*
381
383
****************************************************************************/
382
384
385
+ #ifndef CONFIG_NETDB_DNS_STREAM
386
+ static int dns_send_query (int sd , FAR const char * name ,
387
+ FAR union dns_addr_u * uaddr , uint16_t rectype ,
388
+ FAR struct dns_query_info_s * qinfo ,
389
+ FAR uint8_t * buffer )
390
+ #else
383
391
static int dns_send_query (int sd , FAR const char * name ,
384
392
FAR union dns_addr_u * uaddr , uint16_t rectype ,
385
393
FAR struct dns_query_info_s * qinfo ,
386
394
FAR uint8_t * buffer ,
387
395
bool stream )
396
+ #endif
388
397
{
389
398
FAR struct dns_header_s * hdr ;
390
399
FAR uint8_t * dest ;
@@ -488,11 +497,13 @@ static int dns_send_query(int sd, FAR const char *name,
488
497
return ret ;
489
498
}
490
499
500
+ #ifdef CONFIG_NETDB_DNS_STREAM
491
501
if (stream )
492
502
{
493
503
ret = stream_send_record (sd , buffer , dest - buffer );
494
504
}
495
505
else
506
+ #endif
496
507
{
497
508
ret = send (sd , buffer , dest - buffer , 0 );
498
509
}
@@ -519,10 +530,16 @@ static int dns_send_query(int sd, FAR const char *name,
519
530
*
520
531
****************************************************************************/
521
532
533
+ #ifndef CONFIG_NETDB_DNS_STREAM
534
+ static int dns_recv_response (int sd , FAR union dns_addr_u * addr , int naddr ,
535
+ FAR struct dns_query_info_s * qinfo ,
536
+ FAR uint32_t * ttl , FAR uint8_t * buffer )
537
+ #else
522
538
static int dns_recv_response (int sd , FAR union dns_addr_u * addr , int naddr ,
523
539
FAR struct dns_query_info_s * qinfo ,
524
540
FAR uint32_t * ttl , FAR uint8_t * buffer ,
525
541
bool stream , bool * should_try_stream )
542
+ #endif
526
543
{
527
544
FAR uint8_t * nameptr ;
528
545
FAR uint8_t * namestart ;
@@ -543,11 +560,13 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
543
560
544
561
/* Receive the response */
545
562
563
+ #ifdef CONFIG_NETDB_DNS_STREAM
546
564
if (stream )
547
565
{
548
566
ret = stream_recv_record (sd , buffer , RECV_BUFFER_SIZE );
549
567
}
550
568
else
569
+ #endif
551
570
{
552
571
ret = recv (sd , buffer , RECV_BUFFER_SIZE , 0 );
553
572
}
@@ -579,6 +598,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
579
598
580
599
/* Check for error */
581
600
601
+ #ifdef CONFIG_NETDB_DNS_STREAM
582
602
if ((hdr -> flags1 & DNS_FLAG1_TRUNC ) != 0 )
583
603
{
584
604
/* RFC 2181
@@ -601,6 +621,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
601
621
* should_try_stream = true;
602
622
return - EAGAIN ;
603
623
}
624
+ #endif
604
625
605
626
if ((hdr -> flags2 & DNS_FLAG2_ERR_MASK ) != 0 )
606
627
{
@@ -851,33 +872,47 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
851
872
int retries ;
852
873
int ret ;
853
874
int sd ;
875
+ #ifdef CONFIG_NETDB_DNS_STREAM
854
876
bool stream = false;
877
+ #endif
855
878
856
879
/* Loop while receive timeout errors occur and there are remaining
857
880
* retries.
858
881
*/
859
882
860
883
for (retries = 0 ; retries < CONFIG_NETDB_DNSCLIENT_RETRIES ; retries ++ )
861
884
{
885
+ #ifdef CONFIG_NETDB_DNS_STREAM
862
886
bool should_try_stream ;
863
887
864
888
try_stream :
889
+ #endif
865
890
#ifdef CONFIG_NET_IPv6
866
891
if (dns_is_queryfamily (AF_INET6 ))
867
892
{
868
893
/* Send the IPv6 query */
869
-
894
+ #ifndef CONFIG_NETDB_DNS_STREAM
895
+ sd = dns_bind (addr -> sa_family );
896
+ #else
870
897
sd = dns_bind (addr -> sa_family , stream );
898
+ #endif
871
899
if (sd < 0 )
872
900
{
873
901
query -> result = sd ;
874
902
return 0 ;
875
903
}
876
904
905
+ #ifndef CONFIG_NETDB_DNS_STREAM
906
+ ret = dns_send_query (sd , query -> hostname ,
907
+ (FAR union dns_addr_u * )addr ,
908
+ DNS_RECTYPE_AAAA , & qdata -> qinfo ,
909
+ qdata -> buffer );
910
+ #else
877
911
ret = dns_send_query (sd , query -> hostname ,
878
912
(FAR union dns_addr_u * )addr ,
879
913
DNS_RECTYPE_AAAA , & qdata -> qinfo ,
880
914
qdata -> buffer , stream );
915
+ #endif
881
916
if (ret < 0 )
882
917
{
883
918
dns_query_error ("ERROR: IPv6 dns_send_query failed" ,
@@ -887,25 +922,33 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
887
922
else
888
923
{
889
924
/* Obtain the IPv6 response */
890
-
925
+ #ifndef CONFIG_NETDB_DNS_STREAM
926
+ ret = dns_recv_response (sd , & query -> addr [next ],
927
+ CONFIG_NETDB_MAX_IPv6ADDR ,
928
+ & qdata -> qinfo ,
929
+ & query -> ttl , qdata -> buffer );
930
+ #else
891
931
should_try_stream = false;
892
932
ret = dns_recv_response (sd , & query -> addr [next ],
893
933
CONFIG_NETDB_MAX_IPv6ADDR ,
894
934
& qdata -> qinfo ,
895
935
& query -> ttl , qdata -> buffer ,
896
936
stream , & should_try_stream );
937
+ #endif
897
938
if (ret >= 0 )
898
939
{
899
940
next += ret ;
900
941
}
901
942
else
902
943
{
944
+ #ifdef CONFIG_NETDB_DNS_STREAM
903
945
if (!stream && should_try_stream )
904
946
{
905
947
stream = true;
906
948
goto try_stream ; /* Don't consume retry count */
907
949
}
908
950
951
+ #endif
909
952
dns_query_error ("ERROR: IPv6 dns_recv_response failed" ,
910
953
ret , (FAR union dns_addr_u * )addr );
911
954
query -> result = ret ;
@@ -914,24 +957,35 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
914
957
915
958
close (sd );
916
959
}
960
+
917
961
#endif
918
962
919
963
#ifdef CONFIG_NET_IPv4
920
964
if (dns_is_queryfamily (AF_INET ))
921
965
{
922
966
/* Send the IPv4 query */
923
967
968
+ #ifndef CONFIG_NETDB_DNS_STREAM
969
+ sd = dns_bind (addr -> sa_family );
970
+ #else
924
971
sd = dns_bind (addr -> sa_family , stream );
972
+ #endif
925
973
if (sd < 0 )
926
974
{
927
975
query -> result = sd ;
928
976
return 0 ;
929
977
}
930
978
979
+ #ifndef CONFIG_NETDB_DNS_STREAM
980
+ ret = dns_send_query (sd , query -> hostname ,
981
+ (FAR union dns_addr_u * )addr ,
982
+ DNS_RECTYPE_A , & qdata -> qinfo , qdata -> buffer );
983
+ #else
931
984
ret = dns_send_query (sd , query -> hostname ,
932
985
(FAR union dns_addr_u * )addr ,
933
986
DNS_RECTYPE_A , & qdata -> qinfo , qdata -> buffer ,
934
987
stream );
988
+ #endif
935
989
if (ret < 0 )
936
990
{
937
991
dns_query_error ("ERROR: IPv4 dns_send_query failed" ,
@@ -947,24 +1001,33 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
947
1001
next = * query -> naddr / 2 ;
948
1002
}
949
1003
1004
+ #ifndef CONFIG_NETDB_DNS_STREAM
1005
+ ret = dns_recv_response (sd , & query -> addr [next ],
1006
+ CONFIG_NETDB_MAX_IPv4ADDR ,
1007
+ & qdata -> qinfo ,
1008
+ & query -> ttl , qdata -> buffer );
1009
+ #else
950
1010
should_try_stream = false;
951
1011
ret = dns_recv_response (sd , & query -> addr [next ],
952
1012
CONFIG_NETDB_MAX_IPv4ADDR ,
953
1013
& qdata -> qinfo ,
954
1014
& query -> ttl , qdata -> buffer ,
955
1015
stream , & should_try_stream );
1016
+ #endif
956
1017
if (ret >= 0 )
957
1018
{
958
1019
next += ret ;
959
1020
}
960
1021
else
961
1022
{
1023
+ #ifdef CONFIG_NETDB_DNS_STREAM
962
1024
if (!stream && should_try_stream )
963
1025
{
964
1026
stream = true;
965
1027
goto try_stream ; /* Don't consume retry count */
966
1028
}
967
1029
1030
+ #endif
968
1031
dns_query_error ("ERROR: IPv4 dns_recv_response failed" ,
969
1032
ret , (FAR union dns_addr_u * )addr );
970
1033
query -> result = ret ;
0 commit comments