Skip to content

DNS: Fix return value for successful name resolutions #2963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions features/netsocket/nsapi_dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
return NSAPI_ERROR_NO_MEMORY;
}

int result = NSAPI_ERROR_DNS_FAILURE;
int result = NSAPI_ERROR_OK;

// check against each dns server
for (unsigned i = 0; i < DNS_SERVERS_SIZE; i++) {
Expand All @@ -243,8 +243,11 @@ static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
}

const uint8_t *response = packet;
dns_scan_response(&response, addr, addr_count);
break;
if (!dns_scan_response(&response, addr, addr_count)) {
Copy link
Contributor

@kjbracey kjbracey Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like using "!" for non-boolean values. "== 0" would have been clearer.

Also, you end up querying every DNS server when the destination doesn't exist (like 5.1 did). The point of extra DNS servers is to provide a backup if one goes down, not to get second opinions.

And you return "OK" if no servers respond.

Better fix is:

 if (dns_scan_response(&response, addr, addr_count) > 0) {
      result = NSAPI_ERROR_OK;
 }
break;

result = NSAPI_ERROR_DNS_FAILURE;
} else {
break;
}
}

// clean up packet
Expand Down