@@ -573,28 +573,29 @@ void Dns::HandleDnsAddressResponse(otError aError, const otDnsAddressResponse *a
573573
574574void Dns::HandleDnsAddressResponse (otError aError, const otDnsAddressResponse *aResponse)
575575{
576+ otError error;
576577 char hostName[OT_DNS_MAX_NAME_SIZE];
577578 otIp6Address address;
578579 uint32_t ttl;
580+ uint16_t index = 0 ;
579581
580- IgnoreError (otDnsAddressResponseGetHostName (aResponse, hostName, sizeof (hostName)));
581-
582+ SuccessOrExit (error = otDnsAddressResponseGetHostName (aResponse, hostName, sizeof (hostName)));
582583 OutputFormat (" DNS response for %s - " , hostName);
583584
584- if (aError == OT_ERROR_NONE)
585- {
586- uint16_t index = 0 ;
585+ error = aError;
586+ SuccessOrExit (error);
587587
588- while (otDnsAddressResponseGetAddress (aResponse, index, &address, &ttl) == OT_ERROR_NONE)
589- {
590- OutputIp6Address (address);
591- OutputFormat (" TTL:%lu " , ToUlong (ttl));
592- index++;
593- }
588+ while (otDnsAddressResponseGetAddress (aResponse, index, &address, &ttl) == OT_ERROR_NONE)
589+ {
590+ OutputIp6Address (address);
591+ OutputFormat (" TTL:%lu " , ToUlong (ttl));
592+ index++;
594593 }
595594
596595 OutputNewLine ();
597- OutputResult (aError);
596+
597+ exit:
598+ OutputResult (error);
598599}
599600
600601#if OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE
@@ -630,39 +631,39 @@ void Dns::HandleDnsBrowseResponse(otError aError, const otDnsBrowseResponse *aRe
630631
631632void Dns::HandleDnsBrowseResponse (otError aError, const otDnsBrowseResponse *aResponse)
632633{
634+ Error error;
633635 char name[OT_DNS_MAX_NAME_SIZE];
634636 char label[OT_DNS_MAX_LABEL_SIZE];
635637 uint8_t txtBuffer[kMaxTxtDataSize ];
636638 otDnsServiceInfo serviceInfo;
639+ uint16_t index = 0 ;
637640
638- IgnoreError (otDnsBrowseResponseGetServiceName (aResponse, name, sizeof (name)));
639-
641+ SuccessOrExit (error = otDnsBrowseResponseGetServiceName (aResponse, name, sizeof (name)));
640642 OutputLine (" DNS browse response for %s" , name);
641643
642- if (aError == OT_ERROR_NONE)
643- {
644- uint16_t index = 0 ;
645-
646- while (otDnsBrowseResponseGetServiceInstance (aResponse, index, label, sizeof (label)) == OT_ERROR_NONE)
647- {
648- OutputLine (" %s" , label);
649- index++;
644+ error = aError;
645+ SuccessOrExit (error);
650646
651- serviceInfo. mHostNameBuffer = name;
652- serviceInfo. mHostNameBufferSize = sizeof (name);
653- serviceInfo. mTxtData = txtBuffer ;
654- serviceInfo. mTxtDataSize = sizeof (txtBuffer) ;
647+ while ( otDnsBrowseResponseGetServiceInstance (aResponse, index, label, sizeof (label)) == OT_ERROR_NONE)
648+ {
649+ OutputLine ( " %s " , label) ;
650+ index++ ;
655651
656- if ( otDnsBrowseResponseGetServiceInfo (aResponse, label, &serviceInfo) == OT_ERROR_NONE)
657- {
658- OutputDnsServiceInfo ( kIndentSize , serviceInfo) ;
659- }
652+ serviceInfo. mHostNameBuffer = name;
653+ serviceInfo. mHostNameBufferSize = sizeof (name);
654+ serviceInfo. mTxtData = txtBuffer ;
655+ serviceInfo. mTxtDataSize = sizeof (txtBuffer);
660656
661- OutputNewLine ();
657+ if (otDnsBrowseResponseGetServiceInfo (aResponse, label, &serviceInfo) == OT_ERROR_NONE)
658+ {
659+ OutputDnsServiceInfo (kIndentSize , serviceInfo);
662660 }
661+
662+ OutputNewLine ();
663663 }
664664
665- OutputResult (aError);
665+ exit:
666+ OutputResult (error);
666667}
667668
668669void Dns::HandleDnsServiceResponse (otError aError, const otDnsServiceResponse *aResponse, void *aContext)
@@ -672,30 +673,31 @@ void Dns::HandleDnsServiceResponse(otError aError, const otDnsServiceResponse *a
672673
673674void Dns::HandleDnsServiceResponse (otError aError, const otDnsServiceResponse *aResponse)
674675{
676+ otError error;
675677 char name[OT_DNS_MAX_NAME_SIZE];
676678 char label[OT_DNS_MAX_LABEL_SIZE];
677679 uint8_t txtBuffer[kMaxTxtDataSize ];
678680 otDnsServiceInfo serviceInfo;
679681
680- IgnoreError (otDnsServiceResponseGetServiceName (aResponse, label, sizeof (label), name, sizeof (name)));
681-
682+ SuccessOrExit (error = otDnsServiceResponseGetServiceName (aResponse, label, sizeof (label), name, sizeof (name)));
682683 OutputLine (" DNS service resolution response for %s for service %s" , label, name);
683684
684- if (aError == OT_ERROR_NONE)
685- {
686- serviceInfo.mHostNameBuffer = name;
687- serviceInfo.mHostNameBufferSize = sizeof (name);
688- serviceInfo.mTxtData = txtBuffer;
689- serviceInfo.mTxtDataSize = sizeof (txtBuffer);
685+ error = aError;
686+ SuccessOrExit (error);
690687
691- if (otDnsServiceResponseGetServiceInfo (aResponse, &serviceInfo) == OT_ERROR_NONE)
692- {
693- OutputDnsServiceInfo (/* aIndentSize */ 0 , serviceInfo);
694- OutputNewLine ();
695- }
688+ serviceInfo.mHostNameBuffer = name;
689+ serviceInfo.mHostNameBufferSize = sizeof (name);
690+ serviceInfo.mTxtData = txtBuffer;
691+ serviceInfo.mTxtDataSize = sizeof (txtBuffer);
692+
693+ if (otDnsServiceResponseGetServiceInfo (aResponse, &serviceInfo) == OT_ERROR_NONE)
694+ {
695+ OutputDnsServiceInfo (/* aIndentSize */ 0 , serviceInfo);
696+ OutputNewLine ();
696697 }
697698
698- OutputResult (aError);
699+ exit:
700+ OutputResult (error);
699701}
700702
701703#endif // OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE
@@ -708,33 +710,34 @@ void Dns::HandleDnsRecordResponse(otError aError, const otDnsRecordResponse *aRe
708710
709711void Dns::HandleDnsRecordResponse (otError aError, const otDnsRecordResponse *aResponse)
710712{
713+ otError error;
711714 char name[OT_DNS_MAX_NAME_SIZE];
712715 uint8_t data[kMaxRrDataSize ];
713716 otDnsRecordInfo recordInfo;
714717
715- IgnoreError (otDnsRecordResponseGetQueryName (aResponse, name, sizeof (name)));
716-
718+ SuccessOrExit (error = otDnsRecordResponseGetQueryName (aResponse, name, sizeof (name)));
717719 OutputLine (" DNS query response for %s " , name);
718720
719- SuccessOrExit (aError);
721+ error = aError;
722+ SuccessOrExit (error);
720723
721724 for (uint16_t index = 0 ;; index++)
722725 {
723726 ClearAllBytes (recordInfo);
724727 recordInfo.mNameBuffer = name;
725728 recordInfo.mNameBufferSize = sizeof (name);
726729 recordInfo.mDataBuffer = data;
727- recordInfo.mDataBufferSize = sizeof (name );
730+ recordInfo.mDataBufferSize = sizeof (data );
728731
729- aError = otDnsRecordResponseGetRecordInfo (aResponse, index, &recordInfo);
732+ error = otDnsRecordResponseGetRecordInfo (aResponse, index, &recordInfo);
730733
731- if (aError == OT_ERROR_NOT_FOUND)
734+ if (error == OT_ERROR_NOT_FOUND)
732735 {
733- aError = OT_ERROR_NONE;
736+ error = OT_ERROR_NONE;
734737 ExitNow ();
735738 }
736739
737- SuccessOrExit (aError );
740+ SuccessOrExit (error );
738741
739742 OutputLine (" %u)" , index);
740743 OutputLine (kIndentSize , " RecordType:%u, RecordLength:%u, TTL:%lu, Section:%s" , recordInfo.mRecordType ,
@@ -752,7 +755,7 @@ void Dns::HandleDnsRecordResponse(otError aError, const otDnsRecordResponse *aRe
752755 }
753756
754757exit:
755- OutputResult (aError );
758+ OutputResult (error );
756759}
757760
758761const char *Dns::RecordSectionToString (otDnsRecordSection aSection)
0 commit comments