Microchip® Advanced Software Framework

dns.h File Reference
#include "lwip/opt.h"

Macros

#define DNS_RRCLASS_CH   3 /* the CHAOS class */
 
#define DNS_RRCLASS_CS   2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */
 
#define DNS_RRCLASS_FLUSH   0x800 /* Flush bit */
 
#define DNS_RRCLASS_HS   4 /* Hesiod [Dyer 87] */
 
#define DNS_RRCLASS_IN   1 /* the Internet */
 DNS field CLASS used for "Resource Records". More...
 
#define DNS_RRTYPE_A   1 /* a host address */
 DNS field TYPE used for "Resource Records". More...
 
#define DNS_RRTYPE_CNAME   5 /* the canonical name for an alias */
 
#define DNS_RRTYPE_HINFO   13 /* host information */
 
#define DNS_RRTYPE_MB   7 /* a mailbox domain name (EXPERIMENTAL) */
 
#define DNS_RRTYPE_MD   3 /* a mail destination (Obsolete - use MX) */
 
#define DNS_RRTYPE_MF   4 /* a mail forwarder (Obsolete - use MX) */
 
#define DNS_RRTYPE_MG   8 /* a mail group member (EXPERIMENTAL) */
 
#define DNS_RRTYPE_MINFO   14 /* mailbox or mail list information */
 
#define DNS_RRTYPE_MR   9 /* a mail rename domain name (EXPERIMENTAL) */
 
#define DNS_RRTYPE_MX   15 /* mail exchange */
 
#define DNS_RRTYPE_NS   2 /* an authoritative name server */
 
#define DNS_RRTYPE_NULL   10 /* a null RR (EXPERIMENTAL) */
 
#define DNS_RRTYPE_PTR   12 /* a domain name pointer */
 
#define DNS_RRTYPE_SOA   6 /* marks the start of a zone of authority */
 
#define DNS_RRTYPE_TXT   16 /* text strings */
 
#define DNS_RRTYPE_WKS   11 /* a well known service description */
 
#define DNS_TMR_INTERVAL   1000
 lwip DNS resolver header file. More...
 

Typedefs

typedef void(* dns_found_callback )(const char *name, ip_addr_t *ipaddr, void *callback_arg)
 Callback which is invoked when a hostname is found. More...
 

Functions

err_t dns_gethostbyname (const char *hostname, ip_addr_t *addr, dns_found_callback found, void *callback_arg)
 Resolve a hostname (string) into an IP address. More...
 
ip_addr_tdns_getserver (u8_t numdns)
 Obtain one of the currently configured DNS server. More...
 
void dns_init (void)
 Initialize the resolver: set up the UDP pcb and configure the default server (DNS_SERVER_ADDRESS). More...
 
void dns_setserver (u8_t numdns, ip_addr_t *dnsserver)
 Initialize one of the DNS servers. More...
 
void dns_tmr (void)
 The DNS resolver client timer - handle retries and timeouts and should be called every DNS_TMR_INTERVAL milliseconds (every second by default). More...
 

#define DNS_RRCLASS_CH   3 /* the CHAOS class */
#define DNS_RRCLASS_CS   2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */
#define DNS_RRCLASS_FLUSH   0x800 /* Flush bit */
#define DNS_RRCLASS_HS   4 /* Hesiod [Dyer 87] */
#define DNS_RRCLASS_IN   1 /* the Internet */

DNS field CLASS used for "Resource Records".

Referenced by dns_recv(), and dns_send().

#define DNS_RRTYPE_A   1 /* a host address */

DNS field TYPE used for "Resource Records".

Referenced by dns_recv(), and dns_send().

#define DNS_RRTYPE_CNAME   5 /* the canonical name for an alias */
#define DNS_RRTYPE_HINFO   13 /* host information */
#define DNS_RRTYPE_MB   7 /* a mailbox domain name (EXPERIMENTAL) */
#define DNS_RRTYPE_MD   3 /* a mail destination (Obsolete - use MX) */
#define DNS_RRTYPE_MF   4 /* a mail forwarder (Obsolete - use MX) */
#define DNS_RRTYPE_MG   8 /* a mail group member (EXPERIMENTAL) */
#define DNS_RRTYPE_MINFO   14 /* mailbox or mail list information */
#define DNS_RRTYPE_MR   9 /* a mail rename domain name (EXPERIMENTAL) */
#define DNS_RRTYPE_MX   15 /* mail exchange */
#define DNS_RRTYPE_NS   2 /* an authoritative name server */
#define DNS_RRTYPE_NULL   10 /* a null RR (EXPERIMENTAL) */
#define DNS_RRTYPE_PTR   12 /* a domain name pointer */
#define DNS_RRTYPE_SOA   6 /* marks the start of a zone of authority */
#define DNS_RRTYPE_TXT   16 /* text strings */
#define DNS_RRTYPE_WKS   11 /* a well known service description */
#define DNS_TMR_INTERVAL   1000

lwip DNS resolver header file.

Author: Jim Pettinato April 2007

ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.DNS timer period

Referenced by dns_timer(), and sys_timeouts_init().

typedef void(* dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg)

Callback which is invoked when a hostname is found.

A function of this type must be implemented by the application using the DNS resolver.

Parameters
namepointer to the name that was looked up.
ipaddrpointer to an ip_addr_t containing the IP address of the hostname, or NULL if the name could not be found (or on any other error).
callback_arga user-specified callback argument passed to dns_gethostbyname

err_t dns_gethostbyname ( const char *  hostname,
ip_addr_t addr,
dns_found_callback  found,
void callback_arg 
)

Resolve a hostname (string) into an IP address.

NON-BLOCKING callback version for use with raw API!!!

Returns immediately with one of err_t return codes:

  • ERR_OK if hostname is a valid IP address string or the host name is already in the local names table.
  • ERR_INPROGRESS enqueue a request to be sent to the DNS server for resolution if no errors are present.
  • ERR_ARG: dns client not initialized or invalid hostname
Parameters
hostnamethe hostname that is to be queried
addrpointer to a ip_addr_t where to store the address if it is already cached in the dns_table (only valid if ERR_OK is returned!)
founda callback function to be called on success, failure or timeout (only if ERR_INPROGRESS is returned!)
callback_argargument to pass to the callback function
Returns
a err_t return code.

References DNS_DEBUG, dns_enqueue(), dns_lookup(), ERR_ARG, ERR_OK, ip4_addr_set_u32, ip_addr_set_loopback, ipaddr_addr(), IPADDR_NONE, LWIP_DEBUGF, and NULL.

Referenced by lwip_netconn_do_gethostbyname().

ip_addr_t* dns_getserver ( u8_t  numdns)

Obtain one of the currently configured DNS server.

Parameters
numdnsthe index of the DNS server
Returns
IP address of the indexed DNS server or "ip_addr_any" if the DNS server has not been configured.

References dns_servers, and IP_ADDR_ANY.

void dns_init ( void  )

Initialize the resolver: set up the UDP pcb and configure the default server (DNS_SERVER_ADDRESS).

References DNS_DEBUG, dns_recv(), DNS_SERVER_ADDRESS, dns_setserver(), DNS_STATE_UNUSED, IP_ADDR_ANY, LWIP_ASSERT, LWIP_DEBUGF, NULL, SIZEOF_DNS_ANSWER_ASSERT, SIZEOF_DNS_QUERY, udp_bind(), udp_new(), and udp_recv().

Referenced by lwip_init().

void dns_setserver ( u8_t  numdns,
ip_addr_t dnsserver 
)

Initialize one of the DNS servers.

Parameters
numdnsthe index of the DNS server to set must be < DNS_MAX_SERVERS
dnsserverIP address of the DNS server to set

References dns_servers, IP_ADDR_ANY, and NULL.

Referenced by dhcp_handle_ack(), and dns_init().

void dns_tmr ( void  )

The DNS resolver client timer - handle retries and timeouts and should be called every DNS_TMR_INTERVAL milliseconds (every second by default).

References dns_check_entries(), DNS_DEBUG, and LWIP_DEBUGF.

Referenced by dns_timer().