modified by ohneta

Dependents:   HelloESP8266Interface_mine

Fork of DnsQuery by Sarah Marsh

Revision:
2:12d08f0f20cf
Parent:
1:5d978992a518
Child:
3:5705fdae6185
diff -r 5d978992a518 -r 12d08f0f20cf DnsQuery.h
--- a/DnsQuery.h	Fri Jul 24 22:43:25 2015 +0000
+++ b/DnsQuery.h	Wed Aug 05 21:58:57 2015 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
+/* 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  * and associated documentation files (the "Software"), to deal in the Software without restriction,
@@ -19,70 +19,33 @@
 #define __DNSQUERY_H__
 
 #include "SocketInterface.h"
-
-typedef struct {
-    union {
-        struct {
-            char o1, o2, o3, o4;
-        };
-        char o[4];
-    } sin_addr;
-    operator char* () { return (char*)this; }
-    char* string_format() { 
-        char ip[7];
-        sprintf(ip,"%d.%d.%d.%d", this->sin_addr.o1, this->sin_addr.o2, this->sin_addr.o3, this->sin_addr.o4);
-        return ip;
-    }
-} IPADDRESS_t;
-
-/** Class DnsQuery implements DNS over UDP functionality.
-  * Example as a typical use case :
-  * @code
-  * #include "mbed.h"
-  * #include "DnsQuery.h"
-  *
-  * void main(void)
-  * {
-  *     IPADDRESS_t ipAddress;  // will receive the ip address of the host
-  *     IPADDRESS_t dnsIp = { 192, 168, 178, 1 };      // Ip Address of the DNS server
-  *     
-  *     DnsQuery dns(Wifi::getInstance(), &dnsIp);
-  *     if (dns.gethostbyname("mbed.org", ipAddress)) {
-  *         printf("Ip-Address of mbed.org is %d.%d.%d.%d\n", ipAddress.sin_addr.o1, ipAddress.sin_addr.o2, ipAddress.sin_addr.o3, ipAddress.sin_addr.o4);
-  *     } else {
-  *         printf("Unable to obtain IP-Address\n");
-  *     }
-  * }
-  * @endcode
-  */
 class DnsQuery
 {
 public:
     /** Constructor to instantiate a DnsQuery object.
-      * @param wifi : A valid pointer to a Wifi Object, which can be used to obtain a UDP socket object.
-      * @param dnsip : A valid pointer which holds the IPAddress of the DNS server to query.
+      * @param wifi : A valid pointer to a UDP socket
       */
     DnsQuery(SocketInterface* sock);
     
     
     /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
-      * @param hostname : the hostname of interest as a string.
+      * @param hostname : the hostname of interest as a string - format must be without http:// or www. IE google.com, mbed.org, etc
       * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
-      * @returns true if successfull, or false otherwise.
+      * @returns true if successful, or false otherwise.
       */
-    bool gethostbyname(const char* hostname, IPADDRESS_t &ipaddress);
+    bool gethostbyname(const char* hostname, char* ipaddress);
     /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
       * @param hostname : the hostname of interest as a string.
       * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
-      * @returns true if successfull, or false otherwise.
+      * @returns true if successful, or false otherwise.
       */
-    bool getIP(const char* hostname, IPADDRESS_t &ipaddress);
+    bool getIP(const char* hostname, char* ipaddress);
 protected:
-    bool resolve(char* resp, IPADDRESS_t &ipaddress);
-    bool parseRR(char *resp, int& c, IPADDRESS_t& adr );
+    bool resolve(char* resp, char* ipaddress);
+    bool parseRR(char *resp, int& c, char* adr );
 
 protected:
-    IPADDRESS_t _dnsip;
+    char* _dnsip;
     char* _string_ip;
     SocketInterface* socket;