Microchip® Advanced Software Framework

mdns.c File Reference

DNS host name to IP address resolver.

Author
Adam Dunkels adam@.nosp@m.dunk.nosp@m.els.c.nosp@m.om

This file implements a DNS host name to IP address resolver.

#include "net/ip/tcpip.h"
#include "net/ip/resolv.h"
#include "net/ip/uip-udp-packet.h"
#include "ip64-addr.h"
#include "compiler.h"
#include "mdns.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>

Data Structures

struct  dns_answer
 
struct  dns_hdr
 
struct  namemap
 

Macros

#define CONTIKI_CONF_DEFAULT_HOSTNAME   "contiki"
 
#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   (1) /* XXX temporarily fake A records */
 
#define DNS_TYPE_ANY   (255)
 
#define DNS_TYPE_CNAME   (5)
 
#define DNS_TYPE_MX   (15)
 
#define DNS_TYPE_PTR   (12)
 
#define DNS_TYPE_SRV   (33)
 
#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_RESPONDER_PORT   (5354)
 
#define STATE_ASKING   2
 
#define STATE_DONE   3
 
#define STATE_ERROR   4
 
#define STATE_NEW   1
 
#define STATE_UNUSED   0
 
#define VERBOSE_DEBUG   0
 
#define WITH_EDNS_LIMIT_UDP_RES_PAYLOAD   1
 

Functions

static void check_entries (void)
 
static unsigned char * encode_name (unsigned char *query, char *nameptr)
 
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...
 
void mdns_query (const char *name)
 Queues a name so that a question for the name will be sent out. More...
 
static void newdata (void)
 
static unsigned char * parse_name (unsigned char *query)
 
 PROCESS (mdns_process,"DNS mdnser")
 
 PROCESS_THREAD (mdns_process, ev, data)
 

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 struct namemap names [MDNS_ENTRIES]
 
static struct etimer retry
 
static uint8_t seqno
 

#define DNS_FLAG1_AUTHORATIVE   0x04

Referenced by newdata().

#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

Referenced by newdata().

#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   2

Referenced by check_entries(), and newdata().

#define STATE_DONE   3

Referenced by mdns_lookup(), and newdata().

#define STATE_ERROR   4

Referenced by check_entries(), and newdata().

#define STATE_NEW   1

Referenced by check_entries(), and mdns_query().

#define STATE_UNUSED   0

Referenced by mdns_query().