drivers: modem: ublox-sara-r4: fix getaddrinfo
The implementation of offload_getaddrinfo in this driver failed when the node it was called with was an IP address. This condition was never detected, and as a consequence a DNS query was done on the IP address instead of returning it directly. Also, the port was set first after running the DNS query. As a consequence, if the IP address would have been returned directly, this would have been done without a port been set. Both errors are fixed in this patch. Signed-off-by: Hans Wilmers <hans@wilmers.no>
This commit is contained in:
parent
cd7a73c20a
commit
2972cdc763
|
@ -1579,10 +1579,24 @@ static int offload_getaddrinfo(const char *node, const char *service,
|
|||
result.ai_canonname = result_canonname;
|
||||
result_canonname[0] = '\0';
|
||||
|
||||
if (service) {
|
||||
port = ATOI(service, 0U, "port");
|
||||
if (port < 1 || port > USHRT_MAX) {
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if (port > 0U) {
|
||||
/* FIXME: DNS is hard-coded to return only IPv4 */
|
||||
if (result.ai_family == AF_INET) {
|
||||
net_sin(&result_addr)->sin_port = htons(port);
|
||||
}
|
||||
}
|
||||
|
||||
/* check to see if node is an IP address */
|
||||
if (net_addr_pton(result.ai_family, node,
|
||||
&((struct sockaddr_in *)&result_addr)->sin_addr)
|
||||
== 1) {
|
||||
== 0) {
|
||||
*res = &result;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1592,13 +1606,6 @@ static int offload_getaddrinfo(const char *node, const char *service,
|
|||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
if (service) {
|
||||
port = ATOI(service, 0U, "port");
|
||||
if (port < 1 || port > USHRT_MAX) {
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
snprintk(sendbuf, sizeof(sendbuf), "AT+UDNSRN=0,\"%s\"", node);
|
||||
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
|
||||
&cmd, 1U, sendbuf, &mdata.sem_response,
|
||||
|
@ -1607,13 +1614,6 @@ static int offload_getaddrinfo(const char *node, const char *service,
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (port > 0U) {
|
||||
/* FIXME: DNS is hard-coded to return only IPv4 */
|
||||
if (result.ai_family == AF_INET) {
|
||||
net_sin(&result_addr)->sin_port = htons(port);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DBG("DNS RESULT: %s",
|
||||
log_strdup(net_addr_ntop(result.ai_family,
|
||||
&net_sin(&result_addr)->sin_addr,
|
||||
|
|
Loading…
Reference in a new issue