Library to resolve text URLs to IP addresses (IPv4)
Dependents: NetworkSocketAPI NetworkSocketAPI Nucleo-AWS-IoT-mbed
DnsQuery.h@7:cbe1ef566314, 2016-02-23 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Feb 23 01:24:53 2016 -0600
- Branch:
- api-changes
- Revision:
- 7:cbe1ef566314
- Parent:
- 5:d85c1a7e0e9f
- Child:
- 9:16e5208cc4ef
Added check for IP addresses
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 | |
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); |
Christopher Haster |
7:cbe1ef566314 | 40 | /** Checks if string is an IP address |
Christopher Haster |
7:cbe1ef566314 | 41 | * @param hostname String to check |
Christopher Haster |
7:cbe1ef566314 | 42 | * @return True if hostname is an IP addrss |
Christopher Haster |
7:cbe1ef566314 | 43 | */ |
Christopher Haster |
7:cbe1ef566314 | 44 | bool isIP(const char* hostname) const; |
sarahmarshy | 0:fff4b9055396 | 45 | /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname. |
sarahmarshy | 0:fff4b9055396 | 46 | * @param hostname : the hostname of interest as a string. |
sarahmarshy | 0:fff4b9055396 | 47 | * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question. |
sarahmarshy | 2:12d08f0f20cf | 48 | * @returns true if successful, or false otherwise. |
sarahmarshy | 0:fff4b9055396 | 49 | */ |
sarahmarshy | 2:12d08f0f20cf | 50 | bool getIP(const char* hostname, char* ipaddress); |
sarahmarshy | 2:12d08f0f20cf | 51 | bool resolve(char* resp, char* ipaddress); |
sarahmarshy | 2:12d08f0f20cf | 52 | bool parseRR(char *resp, int& c, char* adr ); |
sarahmarshy | 0:fff4b9055396 | 53 | |
sarahmarshy | 0:fff4b9055396 | 54 | protected: |
Christopher Haster |
4:3749346dcd59 | 55 | const char* _dnsip; |
sarahmarshy | 0:fff4b9055396 | 56 | char* _string_ip; |
Christopher Haster |
5:d85c1a7e0e9f | 57 | UDPSocket* socket; |
sarahmarshy | 0:fff4b9055396 | 58 | }; |
sarahmarshy | 0:fff4b9055396 | 59 | |
Christopher Haster |
4:3749346dcd59 | 60 | #endif // __DNSQUERY_H__ |