modified by ohneta

Dependents:   HelloESP8266Interface_mine

Fork of DnsQuery by Sarah Marsh

Committer:
sarahmarshy
Date:
Wed Aug 05 21:58:57 2015 +0000
Revision:
2:12d08f0f20cf
Parent:
1:5d978992a518
Child:
3:5705fdae6185
Removed ipAdress struct. Compatible with NetworkSocket API

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 1:5d978992a518 28 DnsQuery(SocketInterface* sock);
sarahmarshy 0:fff4b9055396 29
sarahmarshy 0:fff4b9055396 30
sarahmarshy 0:fff4b9055396 31 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 2:12d08f0f20cf 32 * @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 33 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 34 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 35 */
sarahmarshy 2:12d08f0f20cf 36 bool gethostbyname(const char* hostname, char* ipaddress);
sarahmarshy 0:fff4b9055396 37 /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
sarahmarshy 0:fff4b9055396 38 * @param hostname : the hostname of interest as a string.
sarahmarshy 0:fff4b9055396 39 * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
sarahmarshy 2:12d08f0f20cf 40 * @returns true if successful, or false otherwise.
sarahmarshy 0:fff4b9055396 41 */
sarahmarshy 2:12d08f0f20cf 42 bool getIP(const char* hostname, char* ipaddress);
sarahmarshy 0:fff4b9055396 43 protected:
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:
sarahmarshy 2:12d08f0f20cf 48 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
sarahmarshy 0:fff4b9055396 54 #endif // __DNSQUERY_H__