Implementation of the WifiPlusClick hardware module.

Dependents:   WifiPlusKlickExample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DnsQuery.h Source File

DnsQuery.h

00001 /* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 #ifndef __DNSQUERY_H__
00019 #define __DNSQUERY_H__
00020 
00021 #include "Wifi.h"
00022 
00023 
00024 /** Class DnsQuery implements DNS over UDP functionality.
00025   * Example as a typical use case :
00026   * @code
00027   * #include "mbed.h"
00028   * #include "DnsQuery.h"
00029   *
00030   * void main(void)
00031   * {
00032   *     IPADDRESS_t ipAddress;  // will receive the ip address of the host
00033   *     IPADDRESS_t dnsIp = { 192, 168, 178, 1 };      // Ip Address of the DNS server
00034   *     
00035   *     DnsQuery dns(Wifi::getInstance(), &dnsIp);
00036   *     if (dns.gethostbyname("mbed.org", ipAddress)) {
00037   *         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);
00038   *     } else {
00039   *         printf("Unable to obtain IP-Address\n");
00040   *     }
00041   * }
00042   * @endcode
00043   */
00044 class DnsQuery
00045 {
00046 public:
00047     /** Constructor to instantiate a DnsQuery object.
00048       * @param wifi : A valid pointer to a Wifi Object, which can be used to obtain a UDP socket object.
00049       * @param dnsip : A valid pointer which holds the IPAddress of the DNS server to query.
00050       */
00051     DnsQuery(Wifi* wifi, IPADDRESS_t* dnsip);
00052     
00053     /** Function gethostbyname implements the functionality to query a domain name server for an IP-Address of a given hostname.
00054       * @param hostname : the hostname of interest as a string.
00055       * @param ipaddress : a reference to a IPADDRESS_t object which will receive the resolved IP Address of the host in question.
00056       * @returns true if successfull, or false otherwise.
00057       */
00058     bool gethostbyname(const char* hostname, IPADDRESS_t &ipaddress);
00059 protected:
00060     bool resolve(char* resp, IPADDRESS_t &ipaddress);
00061     bool parseRR(char *resp, int& c, IPADDRESS_t& adr );
00062 
00063 protected:
00064     Wifi* _wifi;
00065     IPADDRESS_t _dnsip;
00066 };
00067 
00068 #endif // __DNSQUERY_H__