Library to resolve text URLs to IP addresses (IPv4)

Dependents:   NetworkSocketAPI NetworkSocketAPI Nucleo-AWS-IoT-mbed

Committer:
Christopher Haster
Date:
Mon Feb 22 19:31:19 2016 -0600
Revision:
4:3749346dcd59
Parent:
3:5705fdae6185
Child:
5:d85c1a7e0e9f
Removed dependency on mbed

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
sarahmarshy 1:5d978992a518 21 #include "SocketInterface.h"
sarahmarshy 0:fff4b9055396 22 class DnsQuery
sarahmarshy 0:fff4b9055396 23 {
sarahmarshy 0:fff4b9055396 24 public:
sarahmarshy 0:fff4b9055396 25 /** Constructor to instantiate a DnsQuery object.
sarahmarshy 2:12d08f0f20cf 26 * @param wifi : A valid pointer to a UDP socket
sarahmarshy 0:fff4b9055396 27 */
sarahmarshy 3:5705fdae6185 28 DnsQuery(SocketInterface* sock,const char* hostname, char* ipaddress);
sarahmarshy 3:5705fdae6185 29
sarahmarshy 3:5705fdae6185 30
sarahmarshy 3:5705fdae6185 31 private:
sarahmarshy 0:fff4b9055396 32 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 2:12d08f0f20cf 33 * @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 34 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 35 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 36 */
sarahmarshy 3:5705fdae6185 37 bool getHostByName(const char* hostname, char* ipaddress);
sarahmarshy 0:fff4b9055396 38 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 0:fff4b9055396 39 * @param hostname : the hostname of interest as a string.
sarahmarshy 0:fff4b9055396 40 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 41 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 42 */
sarahmarshy 2:12d08f0f20cf 43 bool getIP(const char* hostname, char* ipaddress);
sarahmarshy 2:12d08f0f20cf 44 bool resolve(char* resp, char* ipaddress);
sarahmarshy 2:12d08f0f20cf 45 bool parseRR(char *resp, int& c, char* adr );
sarahmarshy 0:fff4b9055396 46
sarahmarshy 0:fff4b9055396 47 protected:
Christopher Haster 4:3749346dcd59 48 const char* _dnsip;
sarahmarshy 0:fff4b9055396 49 char* _string_ip;
sarahmarshy 1:5d978992a518 50 SocketInterface* socket;
sarahmarshy 1:5d978992a518 51
sarahmarshy 0:fff4b9055396 52 };
sarahmarshy 0:fff4b9055396 53
Christopher Haster 4:3749346dcd59 54 #endif // __DNSQUERY_H__