NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

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, ip_addr_t *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, ip_addr_t *dnsserver)
 Initialize one of the DNS servers.
ip_addr_t 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).
static u32_t dns_lookup_local (const char *hostname)
 Scans the local host-list for a hostname.
int dns_local_removehost (const char *hostname, const ip_addr_t *addr)
 Remove all entries from the local host-list for a specific hostname and/or IP addess.
err_t dns_local_addhost (const char *hostname, const ip_addr_t *addr)
 Add a hostname/IP address pair to the local host-list.
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, ip_addr_t *addr, dns_found_callback found, void *callback_arg)
 Resolve a hostname (string) into an IP address.

Variables

static struct
local_hostlist_entry
local_hostlist_dynamic
 Local host-list.
static u8_t dns_payload_buffer [LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)]
 Contiguous buffer for processing responses.

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 718 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 636 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 493 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 860 of file dns.c.

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

Definition at line 935 of file dns.c.

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.

Definition at line 289 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 232 of file dns.c.

err_t dns_local_addhost ( const char *  hostname,
const ip_addr_t *  addr 
)

Add a hostname/IP address pair to the local host-list.

Duplicates are not checked.

Parameters:
hostnamehostname of the new entry
addrIP address of the new entry
Returns:
ERR_OK if succeeded or ERR_MEM on memory error

Definition at line 414 of file dns.c.

int dns_local_removehost ( const char *  hostname,
const ip_addr_t *  addr 
)

Remove all entries from the local host-list for a specific hostname and/or IP addess.

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

Definition at line 379 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 ip_addr_t to better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname was not found in the cached dns_table.

Definition at line 450 of file dns.c.

static u32_t dns_lookup_local ( const char *  hostname ) [static]

Scans the local host-list for a hostname.

Parameters:
hostnameHostname to look for in the local host-list
Returns:
The first IP address for the hostname in the local host-list or IPADDR_NONE if not found.

Definition at line 348 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 528 of file dns.c.

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

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

see udp.h

Definition at line 733 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 560 of file dns.c.

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

Definition at line 273 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 303 of file dns.c.


Variable Documentation

u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)] [static]

Contiguous buffer for processing responses.

Definition at line 224 of file dns.c.

Local host-list.

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

Definition at line 188 of file dns.c.