mirror of https://github.com/ARMmbed/mbed-os.git
Move to SocketAddress in gethostbyname
parent
62bb777c1f
commit
d488f02f5e
|
@ -17,7 +17,14 @@
|
||||||
#include "DnsQuery.h"
|
#include "DnsQuery.h"
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
|
|
||||||
int NetworkInterface::gethostbyname(const char *name, char *dest)
|
int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
|
||||||
{
|
{
|
||||||
return dnsQuery(this, name, dest);
|
char buffer[NSAPI_IP_SIZE];
|
||||||
|
int err = dnsQuery(this, name, buffer);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
address->set_ip_address(buffer);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,11 +87,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Looks up the specified host's IP address
|
/** Looks up the specified host's IP address
|
||||||
|
* @param address Destination for the host SocketAddress
|
||||||
* @param name Hostname to lookup
|
* @param name Hostname to lookup
|
||||||
* @param dest Destination for IP address, must have space for SocketAddress::IP_SIZE
|
|
||||||
* @return 0 on success, negative on failure
|
* @return 0 on success, negative on failure
|
||||||
*/
|
*/
|
||||||
virtual int gethostbyname(const char *name, char *dest);
|
virtual int gethostbyname(SocketAddress *address, const char *name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Socket;
|
friend class Socket;
|
||||||
|
|
|
@ -98,10 +98,8 @@ SocketAddress::SocketAddress(NetworkInterface *iface, const char *host, uint16_t
|
||||||
address_to_ipv4(_ip_bytes, host);
|
address_to_ipv4(_ip_bytes, host);
|
||||||
} else {
|
} else {
|
||||||
// DNS lookup
|
// DNS lookup
|
||||||
char addr[NSAPI_IP_SIZE];
|
int err = iface->gethostbyname(this, host);
|
||||||
int err = iface->gethostbyname(host, addr);
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
set_ip_address(addr);
|
|
||||||
set_port(port);
|
set_port(port);
|
||||||
} else {
|
} else {
|
||||||
_ip_version = NSAPI_IPv4;
|
_ip_version = NSAPI_IPv4;
|
||||||
|
|
Loading…
Reference in New Issue