Skip to content

Commit eac7d30

Browse files
authored
Merge pull request #12114 from AriParkkila/cell-dns-zero
Cellular: Fix to not use all zero address for DNS
2 parents 3091834 + 50ab644 commit eac7d30

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,26 @@ nsapi_error_t AT_CellularContext::activate_ip_context()
486486
while (pdp) {
487487
SocketAddress addr;
488488
if (addr.set_ip_address(pdp->dns_secondary_addr)) {
489-
tr_info("DNS secondary %s", pdp->dns_secondary_addr);
490-
char ifn[5]; // "ce" + two digit _cid + zero
491-
add_dns_server(addr, get_interface_name(ifn));
489+
nsapi_addr_t taddr = addr.get_addr();
490+
for (int i = 0; i < ((taddr.version == NSAPI_IPv6) ? NSAPI_IPv6_BYTES : NSAPI_IPv4_BYTES); i++) {
491+
if (taddr.bytes[i] != 0) { // check the address is not all zero
492+
tr_info("DNS secondary %s", pdp->dns_secondary_addr);
493+
char ifn[5]; // "ce" + two digit _cid + zero
494+
add_dns_server(addr, get_interface_name(ifn));
495+
break;
496+
}
497+
}
492498
}
493499
if (addr.set_ip_address(pdp->dns_primary_addr)) {
494-
tr_info("DNS primary %s", pdp->dns_primary_addr);
495-
char ifn[5]; // "ce" + two digit _cid + zero
496-
add_dns_server(addr, get_interface_name(ifn));
500+
nsapi_addr_t taddr = addr.get_addr();
501+
for (int i = 0; i < ((taddr.version == NSAPI_IPv6) ? NSAPI_IPv6_BYTES : NSAPI_IPv4_BYTES); i++) {
502+
if (taddr.bytes[i] != 0) { // check the address is not all zero
503+
tr_info("DNS primary %s", pdp->dns_primary_addr);
504+
char ifn[5]; // "ce" + two digit _cid + zero
505+
add_dns_server(addr, get_interface_name(ifn));
506+
break;
507+
}
508+
}
497509
}
498510
pdp = pdp->next;
499511
}

0 commit comments

Comments
 (0)