Microchip® Advanced Software Framework

resolv.c File Reference

    DNS host name to IP address resolver.
Author
Adam Dunkels adam@.nosp@m.dunk.nosp@m.els.c.nosp@m.om
Robert Quattlebaum darco.nosp@m.@dee.nosp@m.pdarc.nosp@m..com
    This file implements a DNS host name to IP address resolver,
    as well as an MDNS responder and resolver.
#include "net/ip/tcpip.h"
#include "net/ip/resolv.h"
#include "net/ip/uip-udp-packet.h"
#include "lib/random.h"
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "net/ipv6/uip-ds6.h"

Data Structures

struct  dns_answer
 
struct  dns_hdr
 
struct  dns_question
 
struct  namemap
 

Macros

#define _DEBUG_   CONTIKI_TARGET_COOJA
 
#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki-"CONTIKI_TARGET_NAME
 
#define CONTIKI_TARGET_NAME   stringy(BOARD)
 
#define DEBUG_PRINTF(...)   do { } while(0)
 
#define DNS_CLASS_ANY   255
 
#define DNS_CLASS_IN   1
 
#define DNS_FLAG1_AUTHORATIVE   0x04
 
#define DNS_FLAG1_OPCODE_INVERSE   0x08
 
#define DNS_FLAG1_OPCODE_STANDARD   0x00
 
#define DNS_FLAG1_OPCODE_STATUS   0x10
 
#define DNS_FLAG1_RD   0x01
 
#define DNS_FLAG1_RESPONSE   0x80
 
#define DNS_FLAG1_TRUNC   0x02
 
#define DNS_FLAG2_ERR_MASK   0x0f
 
#define DNS_FLAG2_ERR_NAME   0x03
 
#define DNS_FLAG2_ERR_NONE   0x00
 
#define DNS_FLAG2_RA   0x80
 
#define DNS_PORT   53
 
#define DNS_TYPE_A   1
 
#define DNS_TYPE_AAAA   28
 
#define DNS_TYPE_ANY   255
 
#define DNS_TYPE_CNAME   5
 
#define DNS_TYPE_MX   15
 
#define DNS_TYPE_NSEC   47
 
#define DNS_TYPE_PTR   12
 
#define DNS_TYPE_SRV   33
 
#define DNS_TYPE_TXT   16
 
#define MDNS_PORT   5353
 
#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 STATE_ASKING   3
 
#define STATE_DONE   4
 
#define STATE_ERROR   1
 
#define STATE_NEW   2
 
#define STATE_UNUSED   0
 
#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
 

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, const char *nameptr)
 
static void mdns_announce_requested (void)
 
static size_t mdns_prep_host_announce_packet (void)
 
static unsigned char * mdns_write_announce_records (unsigned char *queryptr, uint8_t *count)
 
static void newdata (void)
 
 PROCESS (resolv_process,"DNS resolver")
 
 PROCESS (mdns_probe_process,"mDNS probe")
 
 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 int mdns_needs_host_announce
 
static uint8_t mdns_state
 
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 uint8_t seqno
 

#define DNS_FLAG1_AUTHORATIVE   0x04
#define DNS_FLAG1_OPCODE_INVERSE   0x08
#define DNS_FLAG1_OPCODE_STANDARD   0x00
#define DNS_FLAG1_OPCODE_STATUS   0x10
#define DNS_FLAG1_RD   0x01

Referenced by check_entries().

#define DNS_FLAG1_RESPONSE   0x80
#define DNS_FLAG1_TRUNC   0x02
#define DNS_FLAG2_ERR_MASK   0x0f

Referenced by newdata().

#define DNS_FLAG2_ERR_NAME   0x03
#define DNS_FLAG2_ERR_NONE   0x00
#define DNS_FLAG2_RA   0x80
#define STATE_ASKING   3
#define STATE_DONE   4
#define STATE_ERROR   1
#define STATE_NEW   2
#define STATE_UNUSED   0

Referenced by newdata(), and resolv_query().