Add logic misssing from dns_add_server
This commit is contained in:
parent
b112d8fddc
commit
a7acb45ca6
@ -73,7 +73,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
{
|
{
|
||||||
FAR FILE *stream;
|
FAR FILE *stream;
|
||||||
char line[DNS_MAX_LINE];
|
char line[DNS_MAX_LINE];
|
||||||
int ret = OK;
|
int ret;
|
||||||
|
|
||||||
stream = fopen(CONFIG_NETDB_RESOLVCONF, "at");
|
stream = fopen(CONFIG_NETDB_RESOLVCONF, "at");
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
@ -93,6 +93,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
if (socklen < sizeof(struct sockaddr_in))
|
if (socklen < sizeof(struct sockaddr_in))
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto errout;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -100,10 +101,11 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
|
|
||||||
if (inet_ntop(AF_INET, &in4->sin_addr, line, DNS_MAX_LINE) == NULL)
|
if (inet_ntop(AF_INET, &in4->sin_addr, line, DNS_MAX_LINE) == NULL)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
ret = -errno;
|
||||||
ndbg("ERROR: inet_ntop failed: %d\n", errcode);
|
ndbg("ERROR: inet_ntop failed: %d\n", errcode);
|
||||||
DEBUGASSERT(errcode > 0);
|
DEBUGASSERT(errcode < 0);
|
||||||
ret = -errcode;
|
goto errout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -117,6 +119,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
if (socklen < sizeof(struct sockaddr_in6))
|
if (socklen < sizeof(struct sockaddr_in6))
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
goto errout;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -124,10 +127,11 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
|
|
||||||
if (inet_ntop(AF_INET6, &in6->sin6_addr, line, DNS_MAX_LINE) == NULL)
|
if (inet_ntop(AF_INET6, &in6->sin6_addr, line, DNS_MAX_LINE) == NULL)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
ret = -errno;
|
||||||
ndbg("ERROR: inet_ntop failed: %d\n", errcode);
|
ndbg("ERROR: inet_ntop failed: %d\n", errcode);
|
||||||
DEBUGASSERT(errcode > 0);
|
DEBUGASSERT(errcode < 0);
|
||||||
return -errcode;
|
goto errout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -136,8 +140,22 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
nvdbg("ERROR: Unsupported family: %d\n",
|
nvdbg("ERROR: Unsupported family: %d\n",
|
||||||
g_dns_server.addr.sa_family);
|
g_dns_server.addr.sa_family);
|
||||||
ret = -ENOSYS;
|
ret = -ENOSYS;
|
||||||
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Write the new record to the end of the resolv.conf file */
|
||||||
|
|
||||||
|
if (fprintf(stream, "%s %s\n", NETDB_DNS_KEYWORD, line) < 0)
|
||||||
|
{
|
||||||
|
ret = -errno;
|
||||||
|
ndbg("ERROR: fprintf failed: %d\n", errcode);
|
||||||
|
DEBUGASSERT(errcode < 0);
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = OK;
|
||||||
|
|
||||||
|
errout:
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user