NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Revision 31:7f15b95f2a1d, committed 2016-02-22
- Comitter:
- geky
- Date:
- Mon Feb 22 22:51:03 2016 +0000
- Branch:
- api-changes
- Parent:
- 30:3cc78f5db99d
- Child:
- 32:2c5fc105fc50
- Commit message:
- Added dependency on DnsQuery accessible through getHostByName
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DnsQuery.lib Mon Feb 22 22:51:03 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/geky/code/DnsQuery/#0ce2e91ddc93
--- a/NetworkInterface.cpp Mon Feb 22 21:03:38 2016 +0000 +++ b/NetworkInterface.cpp Mon Feb 22 22:51:03 2016 +0000 @@ -15,6 +15,8 @@ */ #include "NetworkInterface.h" +#include "UDPSocket.h" +#include "DnsQuery.h" #include <string.h> NetworkInterface::NetworkInterface() @@ -59,3 +61,9 @@ return getIPAddress() != 0; } +int32_t NetworkInterface::getHostByName(const char *name, char *ip) +{ + UDPSocket sock(this); + DnsQuery dns(&sock, name, ip); + return 0; +}
--- a/NetworkInterface.h Mon Feb 22 21:03:38 2016 +0000 +++ b/NetworkInterface.h Mon Feb 22 22:51:03 2016 +0000 @@ -72,9 +72,16 @@ virtual const char *getMACAddress() = 0; /** Get the current status of the interface - @return true if connected + * @return true if connected */ virtual bool isConnected(void); + + /** Looks up the specified host's IP address + * @param name URL of host + * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE + * @return 0 on success + */ + int32_t getHostByName(const char *name, char *ip); protected: NetworkInterface();
--- a/Socket.cpp Mon Feb 22 21:03:38 2016 +0000 +++ b/Socket.cpp Mon Feb 22 22:51:03 2016 +0000 @@ -56,8 +56,12 @@ SocketInterface *s = _get_socket(); if (!s) return -2; - int32_t error = s->setURL(url); - if (error < 0) return error; + int32_t err = _iface->getHostByName(url, _ip_address); + if (err < 0) return err; + + if (_socket) { + _socket->setIPAddress(_ip_address); + } if (port) { setPort(port); @@ -71,7 +75,7 @@ strcpy(_ip_address, ip); if (_socket) { - _socket->setIPAddress(ip); + _socket->setIPAddress(_ip_address); } if (port) { @@ -84,7 +88,7 @@ _port = port; if (_socket) { - _socket->setPort(port); + _socket->setPort(_port); } }
--- a/SocketInterface.cpp Mon Feb 22 21:03:38 2016 +0000 +++ b/SocketInterface.cpp Mon Feb 22 22:51:03 2016 +0000 @@ -15,7 +15,7 @@ */ #include "SocketInterface.h" - + void SocketInterface::setIPAddress(const char *ip) {} void SocketInterface::setPort(uint16_t port) {}
--- a/SocketInterface.h Mon Feb 22 21:03:38 2016 +0000 +++ b/SocketInterface.h Mon Feb 22 22:51:03 2016 +0000 @@ -36,13 +36,6 @@ class SocketInterface { public: - /** Set the URL of the socket - * Performs DNS lookup if necessary - * @param url URL to connect to - * @return 0 on success - */ - virtual int32_t setURL(const char *url) = 0; - /** Set the IP address of the socket * @param ip IP address to connect to, copied internally */