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. | |
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_t * | mdns_getserver (void) |
Obtain the currently configured DNS server. More... | |
void | mdns_init (void) |
uip_ipaddr_t * | mdns_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_t * | resolv_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) |
#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) |
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_CLASS_IN 1 |
Referenced by check_entries(), mdns_prep_host_announce_packet(), mdns_write_announce_records(), 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 |
Referenced by mdns_prep_host_announce_packet().
#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().
Referenced by check_entries().
#define MDNS_ENTRIES 4 |
Referenced by check_entries(), mdns_lookup(), mdns_query(), and newdata().
#define MDNS_PORT (5353) |
Referenced by check_entries(), newdata(), and PROCESS_THREAD().
#define MDNS_PORT 5353 |
Referenced by check_entries(), newdata(), and PROCESS_THREAD().
#define MDNS_RESPONDER_PORT (5354) |
#define MDNS_RESPONDER_PORT 5354 |
#define NATIVE_DNS_TYPE DNS_TYPE_AAAA /* IPv6 */ |
Referenced by check_entries(), mdns_write_announce_records(), and newdata().
Referenced by check_entries(), newdata(), PROCESS_THREAD(), resolv_found(), resolv_lookup(), resolv_query(), and resolv_set_hostname().
#define RESOLV_AUTO_REMOVE_TRAILING_DOTS RESOLV_CONF_SUPPORTS_MDNS |
#define RESOLV_CONF_MAX_DOMAIN_NAME_SIZE 32 |
Referenced by decode_name(), remove_trailing_dots(), resolv_found(), and resolv_set_hostname().
#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 |
Referenced by mdns_write_announce_records().
Referenced by check_entries().
#define RESOLV_ENTRIES 4 |
Referenced by check_entries(), newdata(), resolv_lookup(), and resolv_query().
#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 |
|
static |
Runs through the list of names to see if there are any that have not yet been queried and, if so, sends out a query.
References CLOCK_SECOND, clock_seconds(), DNS_CLASS_IN, DNS_FLAG1_RD, DNS_PORT, DNS_TYPE_ANY, encode_name(), etimer_set(), namemap::expiration, dns_hdr::flags1, i, dns_hdr::id, namemap::is_mdns, namemap::is_probe, MDNS_PORT, mdns_write_announce_records(), namemap::name, names, NATIVE_DNS_TYPE, NULL, dns_hdr::numauthrr, dns_hdr::numquestions, PRINTF, RESOLV_CONF_MAX_MDNS_RETRIES, RESOLV_CONF_MAX_RETRIES, RESOLV_ENCODE_INDEX, RESOLV_ENTRIES, resolv_found(), namemap::retries, retry, namemap::state, STATE_ASKING, STATE_ERROR, STATE_NEW, namemap::tmr, uip_appdata, and uip_udp_packet_sendto().
Referenced by PROCESS_THREAD().
|
static |
Decodes a DNS name from the DNS format into the given string.
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 |
|
static |
References n.
Referenced by check_entries(), and newdata().
|
static |
References n.
Referenced by check_entries(), mdns_prep_host_announce_packet(), and mdns_write_announce_records().
|
static |
References mdns_needs_host_announce.
Referenced by newdata(), and PROCESS_THREAD().
void mdns_conf | ( | const uip_ipaddr_t * | dnsserver | ) |
Configure a DNS server.
dnsserver | A pointer to a 4-byte representation of the IP address of the DNS server to be configured. |
References NULL.
Referenced by PROCESS_THREAD().
|
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.
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.
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 |
Called when we need to announce ourselves
References DNS_CLASS_IN, DNS_FLAG1_AUTHORATIVE, DNS_FLAG1_RESPONSE, DNS_TYPE_NSEC, encode_name(), dns_hdr::flags1, dns_answer::len, mdns_write_announce_records(), dns_hdr::numanswers, dns_hdr::numextrarr, resolv_hostname, dns_answer::ttl, dns_answer::type, and uip_appdata.
Referenced by newdata(), and PROCESS_THREAD().
void mdns_query | ( | const char * | name | ) |
Queues a name so that a question for the name will be sent out.
name | The 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 |
References uip_ds6_netif::addr_list, dns_answer::class, DNS_CLASS_IN, encode_name(), i, uip_ds6_addr::ipaddr, dns_answer::ipaddr, uip_ds6_addr::isused, dns_answer::len, NATIVE_DNS_TYPE, RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS, resolv_hostname, dns_answer::ttl, dns_answer::type, UIP_DS6_ADDR_NB, uip_ds6_if, uip_gethostaddr, and uip_is_addr_link_local.
Referenced by check_entries(), and mdns_prep_host_announce_packet().
|
static |
Called when new UDP data arrives.
QUESTION HANDLING SECTION
ANSWER HANDLING SECTION
References dns_answer::class, dns_question::class, CLOCK_SECOND, clock_seconds(), DEBUG_PRINTF, decode_name(), DNS_CLASS_IN, DNS_FLAG2_ERR_MASK, dns_name_isequal(), DNS_TYPE_ANY, namemap::err, namemap::expiration, dns_hdr::flags1, dns_hdr::flags2, i, dns_hdr::id, dns_answer::ipaddr, namemap::ipaddr, dns_answer::len, mdns_announce_requested(), MDNS_PORT, mdns_prep_host_announce_packet(), mdns_state, MDNS_STATE_READY, namemap::name, names, NATIVE_DNS_TYPE, NULL, dns_hdr::numanswers, dns_hdr::numauthrr, dns_hdr::numextrarr, dns_hdr::numquestions, PRINTF, RESOLV_DECODE_INDEX, RESOLV_ENTRIES, resolv_found(), resolv_hostname, RESOLV_SUPPORTS_RECORD_EXPIRATION, skip_name(), start_name_collision_check(), namemap::state, state, STATE_ASKING, STATE_DONE, STATE_ERROR, STATE_UNUSED, dns_answer::ttl, dns_answer::type, dns_question::type, uip_appdata, uip_htons(), UIP_UDP_BUF, and uip_udp_packet_sendto().
Referenced by PROCESS_THREAD().
|
static |
PROCESS | ( | mdns_process | , |
"DNS mdnser" | |||
) |
PROCESS | ( | resolv_process | , |
"DNS resolver" | |||
) |
PROCESS | ( | mdns_probe_process | , |
"mDNS probe" | |||
) |
PROCESS_THREAD | ( | mdns_process | , |
ev | , | ||
data | |||
) |
References check_entries(), MDNS_PORT, mdns_query(), names, newdata(), NULL, printf, process_alloc_event(), PROCESS_BEGIN, PROCESS_END, PROCESS_EVENT_TIMER, PROCESS_WAIT_EVENT, uip_udp_conn::rport, start_name_collision_check(), tcpip_event, tcpip_poll_udp(), udp_new(), uip_ds6_maddr_add(), uip_newdata, uip_poll, and uip_udp_bind.
PROCESS_THREAD | ( | mdns_probe_process | , |
ev | , | ||
data | |||
) |
Process for probing for name conflicts.
References CLOCK_SECOND, etimer_set(), mdns_announce_requested(), mdns_state, MDNS_STATE_PROBING, MDNS_STATE_READY, MDNS_STATE_WAIT_BEFORE_PROBE, NULL, PRINTF, PROCESS_BEGIN, PROCESS_END, PROCESS_EVENT_TIMER, PROCESS_WAIT_EVENT_UNTIL, random_rand(), resolv_event_found, resolv_hostname, resolv_query(), and strcasecmp().
PROCESS_THREAD | ( | resolv_process | , |
ev | , | ||
data | |||
) |
The main UDP function.
References check_entries(), CONTIKI_CONF_DEFAULT_HOSTNAME, len, mdns_needs_host_announce, MDNS_PORT, mdns_prep_host_announce_packet(), names, newdata(), NULL, PRINTF, process_alloc_event(), PROCESS_BEGIN, PROCESS_END, PROCESS_EVENT_TIMER, PROCESS_WAIT_EVENT, resolv_event_found, resolv_hostname, resolv_set_hostname(), tcpip_event, tcpip_poll_udp(), udp_new(), uip_appdata, uip_ds6_maddr_add(), uip_newdata, uip_poll, uip_udp_bind, and uip_udp_packet_sendto().
|
static |
References dns_name_without_dots, len, and RESOLV_CONF_MAX_DOMAIN_NAME_SIZE.
Referenced by resolv_lookup(), and resolv_query().
void resolv_conf | ( | const uip_ipaddr_t * | dnsserver | ) |
Configure a DNS server.
dnsserver | A pointer to a 4-byte representation of the IP address of the DNS server to be configured. |
|
static |
Callback function which is called when a hostname is found.
References uip_802154_longaddr::addr, CLOCK_SECOND, i, mdns_state, MDNS_STATE_PROBING, MDNS_STATE_READY, PRINTF, PROCESS_BROADCAST, process_post(), RESOLV_CONF_MAX_DOMAIN_NAME_SIZE, resolv_event_found, resolv_hostname, start_name_collision_check(), strncasecmp(), UIP_CONF_IPV6, uip_ds6_is_my_addr, uip_hostaddr, uip_ipaddr_cmp, uip_lladdr, and UIP_LLADDR_LEN.
Referenced by check_entries(), and newdata().
const char* resolv_get_hostname | ( | void | ) |
Returns the local hostname being advertised via MDNS.
References resolv_hostname.
uip_ipaddr_t* resolv_getserver | ( | void | ) |
Obtain the currently configured DNS server.
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.
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 | ) |
Queues a name so that a question for the name will be sent out.
name | The hostname that is to be queried. |
References clock_seconds(), namemap::expiration, i, namemap::is_mdns, namemap::is_probe, mdns_state, MDNS_STATE_PROBING, namemap::name, names, PRINTF, PROCESS_EVENT_TIMER, process_post(), remove_trailing_dots(), RESOLV_ENTRIES, resolv_hostname, RESOLV_SUPPORTS_RECORD_EXPIRATION, namemap::seqno, seqno, namemap::state, STATE_DONE, STATE_NEW, STATE_UNUSED, and strcasecmp().
Referenced by PROCESS_THREAD().
void resolv_set_hostname | ( | const char * | hostname | ) |
Changes the local hostname advertised by MDNS.
hostname | The 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 |
References DEBUG_PRINTF, and n.
Referenced by newdata().
|
static |
References process_exit(), and process_start().
Referenced by newdata(), PROCESS_THREAD(), resolv_found(), and resolv_set_hostname().
int strcasecmp | ( | const char * | s1, |
const char * | s2 | ||
) |
Referenced by newdata(), PROCESS_THREAD(), resolv_lookup(), resolv_query(), and resolv_set_hostname().
int strncasecmp | ( | const char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Referenced by newdata(), and resolv_found().
|
static |
Referenced by mdns_lookup(), mdns_query(), and remove_trailing_dots().
|
static |
Referenced by mdns_getserver().
|
static |
|
static |
process_event_t mdns_event_found |
Event that is broadcasted when a DNS name has been resolved.
|
static |
|
static |
Referenced by mdns_announce_requested(), and PROCESS_THREAD().
|
static |
Referenced by newdata(), PROCESS_THREAD(), resolv_found(), and resolv_query().
|
static |
Referenced by check_entries(), mdns_lookup(), mdns_query(), newdata(), and PROCESS_THREAD().
|
static |
Referenced by check_entries(), newdata(), PROCESS_THREAD(), resolv_lookup(), and resolv_query().
|
static |
|
static |
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().
|
static |
|
static |
|
static |
Referenced by check_entries().
|
static |
Referenced by check_entries().
|
static |
Referenced by mdns_query().
|
static |
Referenced by resolv_query(), send_packet(), send_rerr(), and send_rrep().