mirror of https://github.com/ARMmbed/mbed-os.git
nsapi - Reversed arguments to gethostbyname
Updated to match prior conventions - netconn_gethostbyname - gethostbyname_r - gethostbyname2_r - gethostbyaddr_rpull/2652/head
parent
3858a13b75
commit
d237ee8722
|
@ -273,7 +273,7 @@ static int lwip_err_remap(err_t err) {
|
|||
|
||||
|
||||
/* LWIP network stack implementation */
|
||||
static int lwip_gethostbyname(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host)
|
||||
static int lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr)
|
||||
{
|
||||
err_t err = netconn_gethostbyname(host, (ip_addr_t *)addr->bytes);
|
||||
if (err != ERR_OK) {
|
||||
|
|
|
@ -55,14 +55,14 @@ int NetworkInterface::set_dhcp(bool dhcp)
|
|||
}
|
||||
|
||||
// DNS operations go through the underlying stack by default
|
||||
int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
|
||||
int NetworkInterface::gethostbyname(const char *name, SocketAddress *address)
|
||||
{
|
||||
return get_stack()->gethostbyname(address, name);
|
||||
return get_stack()->gethostbyname(name, address);
|
||||
}
|
||||
|
||||
int NetworkInterface::gethostbyname(SocketAddress *address, const char *name, nsapi_version_t version)
|
||||
int NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
|
||||
{
|
||||
return get_stack()->gethostbyname(address, name, version);
|
||||
return get_stack()->gethostbyname(name, address, version);
|
||||
}
|
||||
|
||||
int NetworkInterface::add_dns_server(const SocketAddress &address)
|
||||
|
|
|
@ -108,11 +108,11 @@ public:
|
|||
* If no stack-specific DNS resolution is provided, the hostname
|
||||
* will be resolve using a UDP socket on the stack.
|
||||
*
|
||||
* @param host Hostname to resolve
|
||||
* @param address Destination for the host SocketAddress
|
||||
* @param host Hostname to resolve
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int gethostbyname(SocketAddress *address, const char *host);
|
||||
virtual int gethostbyname(const char *host, SocketAddress *address);
|
||||
|
||||
/** Translates a hostname to an IP address with specific version
|
||||
*
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
* @param version IP version of address to resolve
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int gethostbyname(SocketAddress *address, const char *host, nsapi_version_t version);
|
||||
virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version);
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
*
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
|
||||
|
||||
// Default NetworkStack operations
|
||||
int NetworkStack::gethostbyname(SocketAddress *address, const char *name)
|
||||
int NetworkStack::gethostbyname(const char *name, SocketAddress *address)
|
||||
{
|
||||
return nsapi_dns_query(this, address, name);
|
||||
return nsapi_dns_query(this, name, address);
|
||||
}
|
||||
|
||||
int NetworkStack::gethostbyname(SocketAddress *address, const char *name, nsapi_version_t version)
|
||||
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
|
||||
{
|
||||
return nsapi_dns_query(this, address, name, version);
|
||||
return nsapi_dns_query(this, name, address, version);
|
||||
}
|
||||
|
||||
int NetworkStack::add_dns_server(const SocketAddress &address)
|
||||
|
@ -86,14 +86,14 @@ public:
|
|||
return address->get_ip_address();
|
||||
}
|
||||
|
||||
virtual int gethostbyname(SocketAddress *address, const char *name)
|
||||
virtual int gethostbyname(const char *name, SocketAddress *address)
|
||||
{
|
||||
if (!_stack_api()->gethostbyname) {
|
||||
return NetworkStack::gethostbyname(address, name);
|
||||
return NetworkStack::gethostbyname(name, address);
|
||||
}
|
||||
|
||||
nsapi_addr_t addr = {NSAPI_IPv4, 0};
|
||||
int err = _stack_api()->gethostbyname(_stack(), &addr, name);
|
||||
int err = _stack_api()->gethostbyname(_stack(), name, &addr);
|
||||
address->set_addr(addr);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -49,11 +49,11 @@ public:
|
|||
* If no stack-specific DNS resolution is provided, the hostname
|
||||
* will be resolve using a UDP socket on the stack.
|
||||
*
|
||||
* @param address Destination for the host SocketAddress
|
||||
* @param host Hostname to resolve
|
||||
* @param address Destination for the host SocketAddress
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int gethostbyname(SocketAddress *address, const char *host);
|
||||
virtual int gethostbyname(const char *host, SocketAddress *address);
|
||||
|
||||
/** Translates a hostname to an IP address with specific version
|
||||
*
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
* @param version IP version of address to resolve
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int gethostbyname(SocketAddress *address, const char *host, nsapi_version_t version);
|
||||
virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version);
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
*
|
||||
|
|
|
@ -292,7 +292,7 @@ void SocketAddress::_SocketAddress(NetworkStack *iface, const char *host, uint16
|
|||
_port = port;
|
||||
} else {
|
||||
// DNS lookup
|
||||
int err = iface->gethostbyname(this, host);
|
||||
int err = iface->gethostbyname(host, this);
|
||||
_port = port;
|
||||
if (err) {
|
||||
_addr = nsapi_addr_t();
|
||||
|
|
|
@ -52,7 +52,7 @@ int TCPSocket::connect(const SocketAddress &address)
|
|||
int TCPSocket::connect(const char *host, uint16_t port)
|
||||
{
|
||||
SocketAddress address;
|
||||
int err = _stack->gethostbyname(&address, host);
|
||||
int err = _stack->gethostbyname(host, &address);
|
||||
if (err) {
|
||||
return NSAPI_ERROR_DNS_FAILURE;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ nsapi_protocol_t UDPSocket::get_proto()
|
|||
int UDPSocket::sendto(const char *host, uint16_t port, const void *data, unsigned size)
|
||||
{
|
||||
SocketAddress address;
|
||||
int err = _stack->gethostbyname(&address, host);
|
||||
int err = _stack->gethostbyname(host, &address);
|
||||
if (err) {
|
||||
return NSAPI_ERROR_DNS_FAILURE;
|
||||
}
|
||||
|
|
|
@ -295,9 +295,8 @@ static int dns_scan_response(const uint8_t **p, nsapi_addr_t *addr, unsigned add
|
|||
}
|
||||
|
||||
// core query function
|
||||
static int nsapi_dns_query_multiple(NetworkStack *stack,
|
||||
nsapi_addr_t *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version)
|
||||
static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
|
||||
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version)
|
||||
{
|
||||
// check for valid host name
|
||||
int host_len = host ? strlen(host) : 0;
|
||||
|
@ -378,20 +377,18 @@ static int nsapi_dns_query_multiple(NetworkStack *stack,
|
|||
}
|
||||
|
||||
// convenience functions for other forms of queries
|
||||
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack,
|
||||
nsapi_addr_t *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version)
|
||||
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version)
|
||||
{
|
||||
NetworkStack *nstack = nsapi_create_stack(stack);
|
||||
return nsapi_dns_query_multiple(nstack, addr, addr_count, host, version);
|
||||
return nsapi_dns_query_multiple(nstack, host, addr, addr_count, version);
|
||||
}
|
||||
|
||||
int nsapi_dns_query_multiple(NetworkStack *stack,
|
||||
SocketAddress *addresses, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version)
|
||||
int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
|
||||
SocketAddress *addresses, unsigned addr_count, nsapi_version_t version)
|
||||
{
|
||||
nsapi_addr_t *addrs = new nsapi_addr_t[addr_count];
|
||||
int result = nsapi_dns_query_multiple(stack, addrs, addr_count, host, version);
|
||||
int result = nsapi_dns_query_multiple(stack, host, addrs, addr_count, version);
|
||||
|
||||
if (result > 0) {
|
||||
for (int i = 0; i < result; i++) {
|
||||
|
@ -403,19 +400,19 @@ int nsapi_dns_query_multiple(NetworkStack *stack,
|
|||
return result;
|
||||
}
|
||||
|
||||
extern "C" int nsapi_dns_query(nsapi_stack_t *stack,
|
||||
nsapi_addr_t *addr, const char *host, nsapi_version_t version)
|
||||
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, nsapi_version_t version)
|
||||
{
|
||||
NetworkStack *nstack = nsapi_create_stack(stack);
|
||||
int result = nsapi_dns_query_multiple(nstack, addr, 1, host, version);
|
||||
int result = nsapi_dns_query_multiple(nstack, host, addr, 1, version);
|
||||
return (result > 0) ? 0 : result;
|
||||
}
|
||||
|
||||
int nsapi_dns_query(NetworkStack *stack,
|
||||
SocketAddress *address, const char *host, nsapi_version_t version)
|
||||
int nsapi_dns_query(NetworkStack *stack, const char *host,
|
||||
SocketAddress *address, nsapi_version_t version)
|
||||
{
|
||||
nsapi_addr_t addr;
|
||||
int result = nsapi_dns_query_multiple(stack, &addr, 1, host, version);
|
||||
int result = nsapi_dns_query_multiple(stack, host, &addr, 1, version);
|
||||
address->set_addr(addr);
|
||||
return (result > 0) ? 0 : result;
|
||||
}
|
||||
|
|
|
@ -28,28 +28,27 @@
|
|||
/** Query a domain name server for an IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param addr Destination for the host address
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Destination for the host address
|
||||
* @param version IP version to resolve
|
||||
* @return 0 on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
int nsapi_dns_query(nsapi_stack_t *stack, nsapi_addr_t *addr,
|
||||
const char *host, nsapi_version_t version);
|
||||
int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, nsapi_version_t version);
|
||||
|
||||
/** Query a domain name server for multiple IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Array for the host addresses
|
||||
* @param addr_count Number of addresses allocated in the array
|
||||
* @param host Hostname to resolve
|
||||
* @param version IP version to resolve
|
||||
* @return Number of addresses found on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
int nsapi_dns_query_multiple(nsapi_stack_t *stack,
|
||||
nsapi_addr_t *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version);
|
||||
int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version);
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
*
|
||||
|
@ -65,88 +64,85 @@ int nsapi_dns_add_server(nsapi_addr_t addr);
|
|||
/** Query a domain name server for an IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param addr Destination for the host address
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Destination for the host address
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return 0 on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
int nsapi_dns_query(NetworkStack *stack, SocketAddress *addr,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4);
|
||||
int nsapi_dns_query(NetworkStack *stack, const char *host,
|
||||
SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4);
|
||||
|
||||
/** Query a domain name server for an IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param addr Destination for the host address
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Destination for the host address
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return 0 on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, nsapi_addr_t *addr,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4);
|
||||
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, nsapi_version_t version = NSAPI_IPv4);
|
||||
|
||||
/** Query a domain name server for an IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param addr Destination for the host address
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Destination for the host address
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return 0 on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
template <typename S>
|
||||
int nsapi_dns_query(S *stack, SocketAddress *addr,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4)
|
||||
int nsapi_dns_query(S *stack, const char *host,
|
||||
SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4)
|
||||
{
|
||||
return nsapi_dns_query(nsapi_create_stack(stack), addr, host, version);
|
||||
return nsapi_dns_query(nsapi_create_stack(stack), host, addr, version);
|
||||
}
|
||||
|
||||
/** Query a domain name server for multiple IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Array for the host addresses
|
||||
* @param addr_count Number of addresses allocated in the array
|
||||
* @param host Hostname to resolve
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return Number of addresses found on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
int nsapi_dns_query_multiple(NetworkStack *stack,
|
||||
SocketAddress *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4);
|
||||
int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
|
||||
SocketAddress *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4);
|
||||
|
||||
/** Query a domain name server for multiple IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Array for the host addresses
|
||||
* @param addr_count Number of addresses allocated in the array
|
||||
* @param host Hostname to resolve
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return Number of addresses found on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack,
|
||||
nsapi_addr_t *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4);
|
||||
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
|
||||
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4);
|
||||
|
||||
/** Query a domain name server for multiple IP address of a given hostname
|
||||
*
|
||||
* @param stack Network stack as target for DNS query
|
||||
* @param host Hostname to resolve
|
||||
* @param addr Array for the host addresses
|
||||
* @param addr_count Number of addresses allocated in the array
|
||||
* @param host Hostname to resolve
|
||||
* @param version IP version to resolve (defaults to NSAPI_IPv4)
|
||||
* @return Number of addresses found on success, negative error code on failure
|
||||
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
|
||||
*/
|
||||
template <typename S>
|
||||
int nsapi_dns_query_multiple(S *stack,
|
||||
SocketAddress *addr, unsigned addr_count,
|
||||
const char *host, nsapi_version_t version = NSAPI_IPv4)
|
||||
int nsapi_dns_query_multiple(S *stack, const char *host,
|
||||
SocketAddress *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4)
|
||||
{
|
||||
return nsapi_dns_query_multiple(nsapi_create_stack(stack),
|
||||
addr, addr_count, host, version);
|
||||
host, addr, addr_count, version);
|
||||
}
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
|
|
|
@ -199,7 +199,7 @@ typedef struct nsapi_stack_api
|
|||
* @param host Hostname to resolve
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
int (*gethostbyname)(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host);
|
||||
int (*gethostbyname)(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr);
|
||||
|
||||
/** Add a domain name server to list of servers to query
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue