My fork of the HTTPServer (working)

Dependents:   DGWWebServer LAN2

Embed: (wiki syntax)

« Back to documentation index

dns.c File Reference

dns.c File Reference

DNS - host name to IP address resolver. More...

Go to the source code of this file.

Functions

static void dns_recv (void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
 Receive input function for DNS response packets arriving for the dns UDP pcb.
static void dns_check_entries (void)
 Call dns_check_entry for each entry in dns_table - check all entries.
void dns_init ()
 Initialize the resolver: set up the UDP pcb and configure the default server (DNS_SERVER_ADDRESS).
void dns_setserver (u8_t numdns, struct ip_addr *dnsserver)
 Initialize one of the DNS servers.
struct ip_addr dns_getserver (u8_t numdns)
 Obtain one of the currently configured DNS server.
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).
int dns_local_removehostname (const char *hostname)
 Remove all entries from the local host-list for a specific hostname.
int dns_local_removehostaddr (const struct ip_addr *addr)
 Remove all entries from the local host-list for a specific address.
static u32_t dns_lookup (const char *name)
 Look up a hostname in the array of known hostnames.
static u8_t dns_compare_name (unsigned char *query, unsigned char *response)
 Compare the "dotted" name "query" with the encoded name "response" to make sure an answer from the DNS server matches the current dns_table entry (otherwise, answers might arrive late for hostname not on the list any more).
static unsigned char * dns_parse_name (unsigned char *query)
 Walk through a compact encoded DNS name and return the end of the name.
static err_t dns_send (u8_t numdns, const char *name, u8_t id)
 Send a DNS query packet.
static void dns_check_entry (u8_t i)
 dns_check_entry() - see if pEntry has not yet been queried and, if so, sends out a query.
static err_t dns_enqueue (const char *name, dns_found_callback found, void *callback_arg)
 Queues a new hostname to resolve and sends out a DNS query for that hostname.
err_t dns_gethostbyname (const char *hostname, struct ip_addr *addr, dns_found_callback found, void *callback_arg)
 Resolve a hostname (string) into an IP address.

Variables

static struct
local_hostlist_entry * 
local_hostlist
 Local host-list.

Detailed Description

DNS - host name to IP address resolver.

Definition in file dns.c.


Function Documentation

static void dns_check_entries ( void   ) [static]

Call dns_check_entry for each entry in dns_table - check all entries.

Definition at line 712 of file dns.c.

static void dns_check_entry ( u8_t  i ) [static]

dns_check_entry() - see if pEntry has not yet been queried and, if so, sends out a query.

Check an entry in the dns_table:

  • send out query for new entries
  • retry old pending entries on timeout (also with different servers)
  • remove completed entries from the table if their TTL has expired
Parameters:
iindex of the dns_table entry to check

Definition at line 639 of file dns.c.

static u8_t dns_compare_name ( unsigned char *  query,
unsigned char *  response 
) [static]

Compare the "dotted" name "query" with the encoded name "response" to make sure an answer from the DNS server matches the current dns_table entry (otherwise, answers might arrive late for hostname not on the list any more).

Parameters:
queryhostname (not encoded) from the dns_table
responseencoded hostname in the DNS response
Returns:
0: names equal; 1: names differ

See also:
RFC 1035 - 4.1.4. Message compression

Definition at line 496 of file dns.c.

static err_t dns_enqueue ( const char *  name,
dns_found_callback  found,
void *  callback_arg 
) [static]

Queues a new hostname to resolve and sends out a DNS query for that hostname.

Parameters:
namethe hostname that is to be queried
founda callback founction to be called on success, failure or timeout
callback_argargument to pass to the callback function
Returns:
a err_t return code.

Definition at line 874 of file dns.c.

err_t dns_gethostbyname ( const char *  hostname,
struct ip_addr *  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.
Parameters:
hostnamethe hostname that is to be queried
addrpointer to a struct ip_addr 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.

Definition at line 946 of file dns.c.

struct ip_addr dns_getserver ( u8_t  numdns ) [read]

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.

Definition at line 300 of file dns.c.

void dns_init ( void   )

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

Definition at line 245 of file dns.c.

int dns_local_removehostaddr ( const struct ip_addr *  addr )

Remove all entries from the local host-list for a specific address.

Parameters:
addraddress for which entries shall be removed from the local host-list
Returns:
the number of removed entries

Definition at line 404 of file dns.c.

int dns_local_removehostname ( const char *  hostname )

Remove all entries from the local host-list for a specific hostname.

Parameters:
hostnamehostname for which entries shall be removed from the local host-list
Returns:
the number of removed entries

Definition at line 376 of file dns.c.

static u32_t dns_lookup ( const char *  name ) [static]

Look up a hostname in the array of known hostnames.

Note:
This function only looks in the internal array of known hostnames, it does not send out a query for the hostname if none was found. The function dns_enqueue() can be used to send a query for a hostname.
Parameters:
namethe hostname to look up
Returns:
the hostname's IP address, as u32_t (instead of struct ip_addr to better check for failure: != INADDR_NONE) or INADDR_NONE if the hostname was not found in the cached dns_table.

Definition at line 459 of file dns.c.

static unsigned char* dns_parse_name ( unsigned char *  query ) [static]

Walk through a compact encoded DNS name and return the end of the name.

Parameters:
queryencoded DNS name in the DNS server response
Returns:
end of the name

See also:
RFC 1035 - 4.1.4. Message compression

Definition at line 531 of file dns.c.

static void dns_recv ( void *  arg,
struct udp_pcb *  pcb,
struct pbuf *  p,
struct ip_addr *  addr,
u16_t  port 
) [static]

Receive input function for DNS response packets arriving for the dns UDP pcb.

see udp.h

Definition at line 727 of file dns.c.

static err_t dns_send ( u8_t  numdns,
const char *  name,
u8_t  id 
) [static]

Send a DNS query packet.

Parameters:
numdnsindex of the DNS server in the dns_servers table
namehostname to query
idindex of the hostname in dns_table, used as transaction ID in the DNS query packet
Returns:
ERR_OK if packet is sent; an err_t indicating the problem otherwise

Definition at line 563 of file dns.c.

void dns_setserver ( u8_t  numdns,
struct ip_addr *  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

Definition at line 284 of file dns.c.

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).

Definition at line 314 of file dns.c.


Variable Documentation

struct local_hostlist_entry* local_hostlist [static]

Local host-list.

For hostnames in this list, no external name resolution is performed

Definition at line 216 of file dns.c.