modified by ohneta
Dependents: HelloESP8266Interface_mine
Fork of DnsQuery by
DnsQuery.h@5:7555d509b568, 2015-11-11 (annotated)
- Committer:
- ohneta
- Date:
- Wed Nov 11 03:39:26 2015 +0000
- Revision:
- 5:7555d509b568
- Parent:
- 4:7e64d099f63e
added timeout=1000ms on "Receive the answer from DNS?
Who changed what in which revision?
User | Revision | Line number | New 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 | */ |
ohneta | 5:7555d509b568 | 28 | DnsQuery(SocketInterface* sock,const char* hostname, char* ipaddress, const char *preferreddnsIp = NULL); |
sarahmarshy | 3:5705fdae6185 | 29 | |
ohneta | 5:7555d509b568 | 30 | void setPreferredDNSServerIP(const char *preferreddnsIp); |
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: |
ohneta | 4:7e64d099f63e | 48 | const char* _preferred_dnsip; |
sarahmarshy | 2:12d08f0f20cf | 49 | char* _dnsip; |
sarahmarshy | 0:fff4b9055396 | 50 | char* _string_ip; |
sarahmarshy | 1:5d978992a518 | 51 | SocketInterface* socket; |
sarahmarshy | 1:5d978992a518 | 52 | |
ohneta | 4:7e64d099f63e | 53 | |
ohneta | 4:7e64d099f63e | 54 | |
sarahmarshy | 0:fff4b9055396 | 55 | }; |
sarahmarshy | 0:fff4b9055396 | 56 | |
sarahmarshy | 0:fff4b9055396 | 57 | #endif // __DNSQUERY_H__ |