Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uIP hostname resolver functions

The uIP DNS resolver functions are used to lookup a hostname and map it to a numerical IP address.

It maintains a list of resolved hostnames that can be queried with the resolv_lookup() function. New hostnames can be resolved using the resolv_query() function.

The event resolv_event_found is posted when a hostname has been resolved. It is up to the receiving process to determine if the correct hostname has been found by calling the resolv_lookup() function with the hostname.

Data Structures

struct  dns_answer
 
struct  dns_hdr
 
struct  dns_question
 
struct  namemap
 

Files

file  mdns.c
 DNS host name to IP address resolver.
 
file  resolv.c
 
    DNS host name to IP address resolver.

 

Macros

#define _DEBUG_   CONTIKI_TARGET_COOJA
 
#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki-"CONTIKI_TARGET_NAME
 
#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki"
 
#define CONTIKI_TARGET_NAME   stringy(BOARD)
 
#define DEBUG_PRINTF(...)   do { } while(0)
 
#define DNS_CLASS_ANY   (255)
 
#define DNS_CLASS_ANY   255
 
#define DNS_CLASS_IN   (1)
 
#define DNS_CLASS_IN   1
 
#define DNS_PORT   (53)
 
#define DNS_PORT   53
 
#define DNS_TYPE_A   (1)
 
#define DNS_TYPE_A   1
 
#define DNS_TYPE_AAAA   (1) /* XXX temporarily fake A records */
 
#define DNS_TYPE_AAAA   28
 
#define DNS_TYPE_ANY   (255)
 
#define DNS_TYPE_ANY   255
 
#define DNS_TYPE_CNAME   (5)
 
#define DNS_TYPE_CNAME   5
 
#define DNS_TYPE_MX   (15)
 
#define DNS_TYPE_MX   15
 
#define DNS_TYPE_NSEC   47
 
#define DNS_TYPE_PTR   (12)
 
#define DNS_TYPE_PTR   12
 
#define DNS_TYPE_SRV   (33)
 
#define DNS_TYPE_SRV   33
 
#define DNS_TYPE_TXT   (16)
 
#define DNS_TYPE_TXT   16
 
#define MDNS_CONF_MAX_DOMAIN_NAME_SIZE   (32)
 
#define MDNS_CONF_MAX_MDNS_RETRIES   (3)
 
#define MDNS_CONF_MAX_RETRIES   (8)
 
#define MDNS_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS   (0)
 
#define MDNS_CONF_MDNS_RESPONDER   0
 
#define MDNS_CONF_SUPPORTS_MDNS   0
 
#define MDNS_DECODE_INDEX(i)   (unsigned char)(uip_ntohs(i) - 61616)
 
#define MDNS_ENCODE_INDEX(i)   (uip_htons(i + 61616))
 
#define MDNS_ENTRIES   4
 
#define MDNS_PORT   (5353)
 
#define MDNS_PORT   5353
 
#define MDNS_RESPONDER_PORT   (5354)
 
#define MDNS_RESPONDER_PORT   5354
 
#define NATIVE_DNS_TYPE   DNS_TYPE_AAAA /* IPv6 */
 
#define PRINTF(...)   do { } while(0)
 
#define RESOLV_AUTO_REMOVE_TRAILING_DOTS   RESOLV_CONF_SUPPORTS_MDNS
 
#define RESOLV_CONF_MAX_DOMAIN_NAME_SIZE   32
 
#define RESOLV_CONF_MAX_MDNS_RETRIES   3
 
#define RESOLV_CONF_MAX_RETRIES   4
 The maximum number of retries when asking for a name. More...
 
#define RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS   0
 
#define RESOLV_DECODE_INDEX(i)   (unsigned char)(uip_ntohs(i-1))
 
#define RESOLV_ENCODE_INDEX(i)   (uip_htons(i+1))
 
#define RESOLV_ENTRIES   4
 
#define RESOLV_SUPPORTS_RECORD_EXPIRATION   1
 
#define RESOLV_VERIFY_ANSWER_NAMES   RESOLV_CONF_SUPPORTS_MDNS
 
#define stringy(x)   stringy2(x)
 
#define stringy2(x)   #x
 
#define UIP_UDP_BUF   ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
 
#define VERBOSE_DEBUG   0
 
#define VERBOSE_DEBUG   0
 
#define WITH_EDNS_LIMIT_UDP_RES_PAYLOAD   1
 

Enumerations

enum  {
  MDNS_STATE_WAIT_BEFORE_PROBE,
  MDNS_STATE_PROBING,
  MDNS_STATE_READY
}
 

Functions

static void check_entries (void)
 
static uint8_t decode_name (const unsigned char *query, char *dest, const unsigned char *packet)
 Decodes a DNS name from the DNS format into the given string. More...
 
static uint8_t dns_name_isequal (const unsigned char *queryptr, const char *name, const unsigned char *packet)
 
static unsigned char * encode_name (unsigned char *query, char *nameptr)
 
static unsigned char * encode_name (unsigned char *query, const char *nameptr)
 
static void mdns_announce_requested (void)
 
void mdns_conf (const uip_ipaddr_t *dnsserver)
 Configure a DNS server. More...
 
static void mdns_found (char *name, uip_ipaddr_t *ipaddr)
 
uip_ipaddr_tmdns_getserver (void)
 Obtain the currently configured DNS server. More...
 
void mdns_init (void)
 
uip_ipaddr_tmdns_lookup (const char *name)
 Look up a hostname in the array of known hostnames. More...
 
static size_t mdns_prep_host_announce_packet (void)
 
void mdns_query (const char *name)
 Queues a name so that a question for the name will be sent out. More...
 
static unsigned char * mdns_write_announce_records (unsigned char *queryptr, uint8_t *count)
 
static void newdata (void)
 
static unsigned char * parse_name (unsigned char *query)
 
 PROCESS (mdns_process,"DNS mdnser")
 
 PROCESS (resolv_process,"DNS resolver")
 
 PROCESS (mdns_probe_process,"mDNS probe")
 
 PROCESS_THREAD (mdns_process, ev, data)
 
 PROCESS_THREAD (mdns_probe_process, ev, data)
 
 PROCESS_THREAD (resolv_process, ev, data)
 
static const char * remove_trailing_dots (const char *name)
 
void resolv_conf (const uip_ipaddr_t *dnsserver)
 Configure a DNS server. More...
 
static void resolv_found (char *name, uip_ipaddr_t *ipaddr)
 
const char * resolv_get_hostname (void)
 Returns the local hostname being advertised via MDNS. More...
 
uip_ipaddr_tresolv_getserver (void)
 Obtain the currently configured DNS server. More...
 
resolv_status_t resolv_lookup (const char *name, uip_ipaddr_t **ipaddr)
 Look up a hostname in the array of known hostnames. More...
 
void resolv_query (const char *name)
 Queues a name so that a question for the name will be sent out. More...
 
void resolv_set_hostname (const char *hostname)
 Changes the local hostname advertised by MDNS. More...
 
static unsigned char * skip_name (unsigned char *query)
 
static void start_name_collision_check (clock_time_t after)
 
int strcasecmp (const char *s1, const char *s2)
 
int strncasecmp (const char *s1, const char *s2, size_t n)
 

Variables

static char dns_name_without_dots [MDNS_CONF_MAX_DOMAIN_NAME_SIZE+1]
 
static uip_ipaddr_t dns_server
 
static uint8_t dns_server_configured = 0
 
static struct uip_udp_connmdns_conn = NULL
 
process_event_t mdns_event_found
 Event that is broadcasted when a DNS name has been resolved. More...
 
static const uip_ipaddr_t mdns_mdns_addr
 
static int mdns_needs_host_announce
 
static uint8_t mdns_state
 
static struct namemap names [MDNS_ENTRIES]
 
static struct namemap names [RESOLV_ENTRIES]
 
static struct uip_udp_connresolv_conn = NULL
 
static uip_ipaddr_t resolv_default_dns_server
 These default values for the DNS server are Google's public DNS: https://developers.google.com/speed/public-dns/docs/using More...
 
process_event_t resolv_event_found
 Event that is broadcasted when a DNS name has been resolved. More...
 
static char resolv_hostname [RESOLV_CONF_MAX_DOMAIN_NAME_SIZE+1]
 
static const uip_ipaddr_t resolv_mdns_addr
 
static struct etimer retry
 
static struct etimer retry
 
static uint8_t seqno
 
static uint8_t seqno
 

#define _DEBUG_   CONTIKI_TARGET_COOJA
#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki-"CONTIKI_TARGET_NAME

Referenced by PROCESS_THREAD().

#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki"
#define CONTIKI_TARGET_NAME   stringy(BOARD)
#define DEBUG_PRINTF (   ...)    do { } while(0)

Referenced by newdata(), resolv_lookup(), and skip_name().

#define DNS_CLASS_ANY   (255)
#define DNS_CLASS_ANY   255
#define DNS_CLASS_IN   (1)

Referenced by check_entries(), and newdata().

#define DNS_PORT   (53)

Referenced by check_entries().

#define DNS_PORT   53

Referenced by check_entries().

#define DNS_TYPE_A   (1)

Referenced by check_entries(), and newdata().

#define DNS_TYPE_A   1
#define DNS_TYPE_AAAA   (1) /* XXX temporarily fake A records */

Referenced by check_entries(), and newdata().

#define DNS_TYPE_AAAA   28
#define DNS_TYPE_ANY   (255)

Referenced by newdata().

#define DNS_TYPE_ANY   255

Referenced by check_entries(), and newdata().

#define DNS_TYPE_CNAME   (5)
#define DNS_TYPE_CNAME   5
#define DNS_TYPE_MX   (15)
#define DNS_TYPE_MX   15
#define DNS_TYPE_NSEC   47
#define DNS_TYPE_PTR   (12)
#define DNS_TYPE_PTR   12
#define DNS_TYPE_SRV   (33)
#define DNS_TYPE_SRV   33
#define DNS_TYPE_TXT   (16)
#define DNS_TYPE_TXT   16
#define MDNS_CONF_MAX_DOMAIN_NAME_SIZE   (32)
#define MDNS_CONF_MAX_MDNS_RETRIES   (3)

Referenced by check_entries().

#define MDNS_CONF_MAX_RETRIES   (8)

The maximum number of retries when asking for a name.

Referenced by check_entries().

#define MDNS_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS   (0)

Referenced by newdata().

#define MDNS_CONF_MDNS_RESPONDER   0
#define MDNS_CONF_SUPPORTS_MDNS   0

Referenced by check_entries().

#define MDNS_DECODE_INDEX (   i)    (unsigned char)(uip_ntohs(i) - 61616)

Referenced by newdata().

#define MDNS_ENCODE_INDEX (   i)    (uip_htons(i + 61616))

Referenced by check_entries().

#define MDNS_ENTRIES   4
#define MDNS_PORT   (5353)
#define MDNS_PORT   5353
#define MDNS_RESPONDER_PORT   (5354)
#define MDNS_RESPONDER_PORT   5354
#define NATIVE_DNS_TYPE   DNS_TYPE_AAAA /* IPv6 */
#define RESOLV_AUTO_REMOVE_TRAILING_DOTS   RESOLV_CONF_SUPPORTS_MDNS
#define RESOLV_CONF_MAX_DOMAIN_NAME_SIZE   32
#define RESOLV_CONF_MAX_MDNS_RETRIES   3

Referenced by check_entries().

#define RESOLV_CONF_MAX_RETRIES   4

The maximum number of retries when asking for a name.

Referenced by check_entries().

#define RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS   0
#define RESOLV_DECODE_INDEX (   i)    (unsigned char)(uip_ntohs(i-1))

Referenced by newdata().

#define RESOLV_ENCODE_INDEX (   i)    (uip_htons(i+1))

Referenced by check_entries().

#define RESOLV_ENTRIES   4
#define RESOLV_SUPPORTS_RECORD_EXPIRATION   1

Referenced by newdata(), and resolv_query().

#define RESOLV_VERIFY_ANSWER_NAMES   RESOLV_CONF_SUPPORTS_MDNS
#define stringy (   x)    stringy2(x)
#define stringy2 (   x)    #x
#define UIP_UDP_BUF   ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])

Referenced by newdata().

#define VERBOSE_DEBUG   0
#define VERBOSE_DEBUG   0
#define WITH_EDNS_LIMIT_UDP_RES_PAYLOAD   1

anonymous enum
Enumerator
MDNS_STATE_WAIT_BEFORE_PROBE 
MDNS_STATE_PROBING 
MDNS_STATE_READY 

static uint8_t decode_name ( const unsigned char *  query,
char *  dest,
const unsigned char *  packet 
)
static

Decodes a DNS name from the DNS format into the given string.

Returns
1 upon success, 0 if the size of the name would be too large.
Note
dest must point to a buffer with at least RESOLV_CONF_MAX_DOMAIN_NAME_SIZE+1 bytes large.

References len, n, and RESOLV_CONF_MAX_DOMAIN_NAME_SIZE.

Referenced by newdata().

static uint8_t dns_name_isequal ( const unsigned char *  queryptr,
const char *  name,
const unsigned char *  packet 
)
static

References n.

Referenced by newdata().

static unsigned char* encode_name ( unsigned char *  query,
char *  nameptr 
)
static

References n.

Referenced by check_entries(), and newdata().

static unsigned char* encode_name ( unsigned char *  query,
const char *  nameptr 
)
static
static void mdns_announce_requested ( void  )
static

References mdns_needs_host_announce.

Referenced by newdata(), and PROCESS_THREAD().

void mdns_conf ( const uip_ipaddr_t dnsserver)

Configure a DNS server.

Parameters
dnsserverA pointer to a 4-byte representation of the IP address of the DNS server to be configured.

References NULL.

Referenced by PROCESS_THREAD().

static void mdns_found ( char *  name,
uip_ipaddr_t ipaddr 
)
static

Callback function which is called when a hostname is found.

References printf, PROCESS_BROADCAST, and process_post().

Referenced by check_entries(), and newdata().

uip_ipaddr_t* mdns_getserver ( void  )

Obtain the currently configured DNS server.

Returns
A pointer to a 4-byte representation of the IP address of the currently configured DNS server or NULL if no DNS server has been configured.

References dns_server, and NULL.

void mdns_init ( void  )

References NULL, and process_start().

Referenced by PROCESS_THREAD().

uip_ipaddr_t* mdns_lookup ( const char *  name)

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 mdns_query() can be used to send a query for a hostname.
Returns
A pointer to a 4-byte representation of the hostname's IP address, or NULL if the hostname was not found in the array of hostnames.

References addr, dns_name_without_dots, i, namemap::ipaddr, len, MDNS_ENTRIES, namemap::name, names, NULL, printf, namemap::state, STATE_DONE, and uip_ip6addr_t::u8.

static size_t mdns_prep_host_announce_packet ( void  )
static
void mdns_query ( const char *  name)

Queues a name so that a question for the name will be sent out.

Parameters
nameThe hostname that is to be queried.

References dns_name_without_dots, i, namemap::is_mdns, len, MDNS_ENTRIES, namemap::name, names, printf, PROCESS_EVENT_TIMER, process_post(), seqno, namemap::seqno, namemap::state, STATE_NEW, and STATE_UNUSED.

Referenced by PROCESS_THREAD().

static unsigned char* parse_name ( unsigned char *  query)
static

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

Returns
The end of the name.

References n, and printf.

Referenced by newdata().

PROCESS ( mdns_process  ,
"DNS mdnser"   
)
PROCESS ( resolv_process  ,
"DNS resolver"   
)
PROCESS ( mdns_probe_process  ,
"mDNS probe"   
)
static const char* remove_trailing_dots ( const char *  name)
static
void resolv_conf ( const uip_ipaddr_t dnsserver)

Configure a DNS server.

Parameters
dnsserverA pointer to a 4-byte representation of the IP address of the DNS server to be configured.
const char* resolv_get_hostname ( void  )

Returns the local hostname being advertised via MDNS.

Returns
C-string containing the local hostname.

References resolv_hostname.

uip_ipaddr_t* resolv_getserver ( void  )

Obtain the currently configured DNS server.

Returns
A pointer to a 4-byte representation of the IP address of the currently configured DNS server or NULL if no DNS server has been configured.

References resolv_default_dns_server.

resolv_status_t resolv_lookup ( const char *  name,
uip_ipaddr_t **  ipaddr 
)

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 resolv_query() can be used to send a query for a hostname.

References addr, clock_seconds(), DEBUG_PRINTF, namemap::expiration, i, ipaddr, namemap::ipaddr, namemap::name, names, PRINTF, remove_trailing_dots(), RESOLV_ENTRIES, RESOLV_STATUS_CACHED, RESOLV_STATUS_EXPIRED, RESOLV_STATUS_NOT_FOUND, RESOLV_STATUS_RESOLVING, RESOLV_STATUS_UNCACHED, namemap::state, STATE_ASKING, STATE_DONE, STATE_ERROR, STATE_NEW, and strcasecmp().

void resolv_query ( const char *  name)
void resolv_set_hostname ( const char *  hostname)

Changes the local hostname advertised by MDNS.

Parameters
hostnameThe new hostname to advertise.

References PRINTF, RESOLV_CONF_MAX_DOMAIN_NAME_SIZE, resolv_hostname, start_name_collision_check(), and strcasecmp().

Referenced by PROCESS_THREAD().

static unsigned char* skip_name ( unsigned char *  query)
static

References DEBUG_PRINTF, and n.

Referenced by newdata().

static void start_name_collision_check ( clock_time_t  after)
static
int strcasecmp ( const char *  s1,
const char *  s2 
)
int strncasecmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Referenced by newdata(), and resolv_found().

char dns_name_without_dots[MDNS_CONF_MAX_DOMAIN_NAME_SIZE+1]
static
uip_ipaddr_t dns_server
static

Referenced by mdns_getserver().

uint8_t dns_server_configured = 0
static
struct uip_udp_conn* mdns_conn = NULL
static
process_event_t mdns_event_found

Event that is broadcasted when a DNS name has been resolved.

const uip_ipaddr_t mdns_mdns_addr
static
Initial value:
= {
.u8 = {
0xff, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfb,
}
}
int mdns_needs_host_announce
static
uint8_t mdns_state
static
struct uip_udp_conn* resolv_conn = NULL
static
uip_ipaddr_t resolv_default_dns_server
static
Initial value:
=
{ { 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88 } }

These default values for the DNS server are Google's public DNS: https://developers.google.com/speed/public-dns/docs/using

Referenced by resolv_getserver().

process_event_t resolv_event_found

Event that is broadcasted when a DNS name has been resolved.

Referenced by PROCESS_THREAD(), and resolv_found().

const uip_ipaddr_t resolv_mdns_addr
static
Initial value:
=
{ { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb } }
struct etimer retry
static

Referenced by check_entries().

struct etimer retry
static

Referenced by check_entries().

uint8_t seqno
static

Referenced by mdns_query().

uint8_t seqno
static