mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-10-04 12:48:20 +00:00
Replaces calls to non-standard dns_hostip() with calls to the standard gethostbyname()
This commit is contained in:
parent
effda16cf5
commit
c7bd1f4186
3 changed files with 121 additions and 21 deletions
|
|
@ -68,7 +68,6 @@
|
|||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/version.h>
|
||||
#include <nuttx/net/dnsclient.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
#include <apps/netutils/webclient.h>
|
||||
|
|
@ -375,6 +374,41 @@ exit:
|
|||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wget_gethostip
|
||||
*
|
||||
* Description:
|
||||
* Call gethostbyname() to get the IPv4 address associated with a hostname.
|
||||
*
|
||||
* Input Parameters
|
||||
* hostname - The host name to use in the nslookup.
|
||||
* ipv4addr - The location to return the IPv4 address.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int wget_gethostip(FAR char *hostname, in_addr_t *ipv4addr)
|
||||
{
|
||||
FAR struct hostent *he;
|
||||
|
||||
he = gethostbyname(hostname);
|
||||
if (he == NULL)
|
||||
{
|
||||
ndbg("gethostbyname failed: %d\n", h_errno);
|
||||
return -ENOENT;
|
||||
}
|
||||
else if (he->h_addrtype != AF_INET)
|
||||
{
|
||||
ndbg("gethostbyname returned an address of type: %d\n", he->h_addrtype);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
memcpy(ipv4addr, he->h_addr, sizeof(in_addr_t));
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wget_base
|
||||
*
|
||||
|
|
@ -477,7 +511,7 @@ static int wget_base(FAR const char *url, FAR char *buffer, int buflen,
|
|||
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(ws.port);
|
||||
ret = dns_gethostip(ws.hostname, &server.sin_addr.s_addr);
|
||||
ret = wget_gethostip(ws.hostname, &server.sin_addr.s_addr);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Could not resolve host (or malformed IP address) */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue