DNS host name to IP address resolver.
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 |
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_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... | |
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_conn * | mdns_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().
|
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, DNS_CLASS_IN, DNS_FLAG1_RD, DNS_PORT, DNS_TYPE_A, DNS_TYPE_AAAA, encode_name(), etimer_set(), dns_hdr::flags1, i, dns_hdr::id, namemap::is_mdns, MDNS_CONF_MAX_MDNS_RETRIES, MDNS_CONF_MAX_RETRIES, MDNS_CONF_SUPPORTS_MDNS, MDNS_ENCODE_INDEX, MDNS_ENTRIES, mdns_found(), MDNS_PORT, namemap::name, names, NULL, dns_hdr::numextrarr, dns_hdr::numquestions, printf, 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 |
Called when new UDP data arrives.
References uip_ds6_netif::addr_list, dns_answer::class, dns_question::class, DNS_CLASS_IN, DNS_FLAG1_AUTHORATIVE, DNS_FLAG1_RESPONSE, DNS_FLAG2_ERR_MASK, DNS_TYPE_A, DNS_TYPE_AAAA, DNS_TYPE_ANY, encode_name(), namemap::err, dns_hdr::flags1, dns_hdr::flags2, i, dns_hdr::id, ip64_addr_4to6(), uip_ds6_addr::ipaddr, dns_answer::ipaddr, namemap::ipaddr, uip_ds6_addr::isused, dns_answer::len, MDNS_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS, MDNS_DECODE_INDEX, MDNS_ENTRIES, mdns_found(), MDNS_PORT, namemap::name, names, NULL, dns_hdr::numanswers, dns_hdr::numauthrr, dns_hdr::numextrarr, dns_hdr::numquestions, parse_name(), printf, namemap::state, state, STATE_ASKING, STATE_DONE, STATE_ERROR, strcasecmp(), strncasecmp(), dns_answer::ttl, dns_answer::type, dns_question::type, uip_appdata, UIP_CONF_IPV6, UIP_DS6_ADDR_NB, uip_ds6_if, uip_gethostaddr, uip_htons(), uip_is_addr_link_local, UIP_UDP_BUF, and uip_udp_packet_sendto().
Referenced by PROCESS_THREAD().