Library to resolve text URLs to IP addresses (IPv4)

Dependents:   NetworkSocketAPI NetworkSocketAPI Nucleo-AWS-IoT-mbed

Committer:
Christopher Haster
Date:
Mon Feb 22 19:38:10 2016 -0600
Branch:
api-changes
Revision:
5:d85c1a7e0e9f
Parent:
4:3749346dcd59
Child:
7:cbe1ef566314
Matched changes to NetworkSocketAPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 2:12d08f0f20cf 1 /*
sarahmarshy 0:fff4b9055396 2 *
sarahmarshy 0:fff4b9055396 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
sarahmarshy 0:fff4b9055396 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
sarahmarshy 0:fff4b9055396 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
sarahmarshy 0:fff4b9055396 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
sarahmarshy 0:fff4b9055396 7 * furnished to do so, subject to the following conditions:
sarahmarshy 0:fff4b9055396 8 *
sarahmarshy 0:fff4b9055396 9 * The above copyright notice and this permission notice shall be included in all copies or
sarahmarshy 0:fff4b9055396 10 * substantial portions of the Software.
sarahmarshy 0:fff4b9055396 11 *
sarahmarshy 0:fff4b9055396 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
sarahmarshy 0:fff4b9055396 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
sarahmarshy 0:fff4b9055396 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
sarahmarshy 0:fff4b9055396 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sarahmarshy 0:fff4b9055396 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sarahmarshy 0:fff4b9055396 17 */
sarahmarshy 0:fff4b9055396 18 #ifndef __DNSQUERY_H__
sarahmarshy 0:fff4b9055396 19 #define __DNSQUERY_H__
sarahmarshy 0:fff4b9055396 20
Christopher Haster 5:d85c1a7e0e9f 21 #include "UDPSocket.h"
Christopher Haster 5:d85c1a7e0e9f 22
Christopher Haster 5:d85c1a7e0e9f 23
sarahmarshy 0:fff4b9055396 24 class DnsQuery
sarahmarshy 0:fff4b9055396 25 {
sarahmarshy 0:fff4b9055396 26 public:
sarahmarshy 0:fff4b9055396 27 /** Constructor to instantiate a DnsQuery object.
sarahmarshy 2:12d08f0f20cf 28 * @param wifi : A valid pointer to a UDP socket
sarahmarshy 0:fff4b9055396 29 */
Christopher Haster 5:d85c1a7e0e9f 30 DnsQuery(UDPSocket* sock,const char* hostname, char* ipaddress);
sarahmarshy 3:5705fdae6185 31
sarahmarshy 3:5705fdae6185 32
sarahmarshy 3:5705fdae6185 33 private:
sarahmarshy 0:fff4b9055396 34 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 2:12d08f0f20cf 35 * @param hostname : the hostname of interest as a string - format must be without http:// or www. IE google.com, mbed.org, etc
sarahmarshy 0:fff4b9055396 36 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 37 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 38 */
sarahmarshy 3:5705fdae6185 39 bool getHostByName(const char* hostname, char* ipaddress);
sarahmarshy 0:fff4b9055396 40 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 0:fff4b9055396 41 * @param hostname : the hostname of interest as a string.
sarahmarshy 0:fff4b9055396 42 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 43 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 44 */
sarahmarshy 2:12d08f0f20cf 45 bool getIP(const char* hostname, char* ipaddress);
sarahmarshy 2:12d08f0f20cf 46 bool resolve(char* resp, char* ipaddress);
sarahmarshy 2:12d08f0f20cf 47 bool parseRR(char *resp, int& c, char* adr );
sarahmarshy 0:fff4b9055396 48
sarahmarshy 0:fff4b9055396 49 protected:
Christopher Haster 4:3749346dcd59 50 const char* _dnsip;
sarahmarshy 0:fff4b9055396 51 char* _string_ip;
Christopher Haster 5:d85c1a7e0e9f 52 UDPSocket* socket;
sarahmarshy 0:fff4b9055396 53 };
sarahmarshy 0:fff4b9055396 54
Christopher Haster 4:3749346dcd59 55 #endif // __DNSQUERY_H__