Merge pull request #163 from oliverschmidt/master
Some coding style nomalization.
This commit is contained in:
commit
b01db7557a
|
@ -110,7 +110,7 @@ strcasecmp(const char *s1, const char *s2)
|
||||||
/* TODO: Add case support! */
|
/* TODO: Add case support! */
|
||||||
return strcmp(s1, s2);
|
return strcmp(s1, s2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __SDCC */
|
||||||
|
|
||||||
#define UIP_UDP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
#define UIP_UDP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||||
|
|
||||||
|
@ -119,24 +119,24 @@ strcasecmp(const char *s1, const char *s2)
|
||||||
* described by draft-cheshire-dnsext-multicastdns.
|
* described by draft-cheshire-dnsext-multicastdns.
|
||||||
*/
|
*/
|
||||||
#ifndef RESOLV_CONF_SUPPORTS_MDNS
|
#ifndef RESOLV_CONF_SUPPORTS_MDNS
|
||||||
#define RESOLV_CONF_SUPPORTS_MDNS (1)
|
#define RESOLV_CONF_SUPPORTS_MDNS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS
|
#ifndef RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS
|
||||||
#define RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS (0)
|
#define RESOLV_CONF_MDNS_INCLUDE_GLOBAL_V6_ADDRS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** The maximum number of retries when asking for a name. */
|
/** The maximum number of retries when asking for a name. */
|
||||||
#ifndef RESOLV_CONF_MAX_RETRIES
|
#ifndef RESOLV_CONF_MAX_RETRIES
|
||||||
#define RESOLV_CONF_MAX_RETRIES (4)
|
#define RESOLV_CONF_MAX_RETRIES 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RESOLV_CONF_MAX_MDNS_RETRIES
|
#ifndef RESOLV_CONF_MAX_MDNS_RETRIES
|
||||||
#define RESOLV_CONF_MAX_MDNS_RETRIES (3)
|
#define RESOLV_CONF_MAX_MDNS_RETRIES 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RESOLV_CONF_MAX_DOMAIN_NAME_SIZE
|
#ifndef RESOLV_CONF_MAX_DOMAIN_NAME_SIZE
|
||||||
#define RESOLV_CONF_MAX_DOMAIN_NAME_SIZE (32)
|
#define RESOLV_CONF_MAX_DOMAIN_NAME_SIZE 32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(CONTIKI_TARGET_NAME) && defined(BOARD)
|
#if !defined(CONTIKI_TARGET_NAME) && defined(BOARD)
|
||||||
|
@ -153,29 +153,29 @@ strcasecmp(const char *s1, const char *s2)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DNS_TYPE_A (1)
|
#define DNS_TYPE_A 1
|
||||||
#define DNS_TYPE_CNAME (5)
|
#define DNS_TYPE_CNAME 5
|
||||||
#define DNS_TYPE_PTR (12)
|
#define DNS_TYPE_PTR 12
|
||||||
#define DNS_TYPE_MX (15)
|
#define DNS_TYPE_MX 15
|
||||||
#define DNS_TYPE_TXT (16)
|
#define DNS_TYPE_TXT 16
|
||||||
#define DNS_TYPE_AAAA (28)
|
#define DNS_TYPE_AAAA 28
|
||||||
#define DNS_TYPE_SRV (33)
|
#define DNS_TYPE_SRV 33
|
||||||
#define DNS_TYPE_ANY (255)
|
#define DNS_TYPE_ANY 255
|
||||||
#define DNS_TYPE_NSEC (47)
|
#define DNS_TYPE_NSEC 47
|
||||||
|
|
||||||
#define DNS_CLASS_IN (1)
|
#define DNS_CLASS_IN 1
|
||||||
#define DNS_CLASS_ANY (255)
|
#define DNS_CLASS_ANY 255
|
||||||
|
|
||||||
#ifndef DNS_PORT
|
#ifndef DNS_PORT
|
||||||
#define DNS_PORT (53)
|
#define DNS_PORT 53
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MDNS_PORT
|
#ifndef MDNS_PORT
|
||||||
#define MDNS_PORT (5353)
|
#define MDNS_PORT 5353
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MDNS_RESPONDER_PORT
|
#ifndef MDNS_RESPONDER_PORT
|
||||||
#define MDNS_RESPONDER_PORT (5354)
|
#define MDNS_RESPONDER_PORT 5354
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \internal The DNS message header. */
|
/** \internal The DNS message header. */
|
||||||
|
@ -271,7 +271,6 @@ enum {
|
||||||
EVENT_NEW_SERVER = 0
|
EVENT_NEW_SERVER = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||||
/** \internal The DNS question message structure. */
|
/** \internal The DNS question message structure. */
|
||||||
struct dns_question {
|
struct dns_question {
|
||||||
|
@ -301,6 +300,9 @@ static int mdns_needs_host_announce;
|
||||||
PROCESS(mdns_probe_process, "mDNS probe");
|
PROCESS(mdns_probe_process, "mDNS probe");
|
||||||
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
|
|
||||||
|
/* For removing trailing dots in resolv_query() and resolve_lookup2(). */
|
||||||
|
static char dns_name_without_dots[RESOLV_CONF_MAX_DOMAIN_NAME_SIZE + 1];
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* \brief Decodes a DNS name from the DNS format into the given string.
|
* \brief Decodes a DNS name from the DNS format into the given string.
|
||||||
|
@ -355,7 +357,6 @@ decode_name(const unsigned char *query, char *dest,
|
||||||
*dest = 0;
|
*dest = 0;
|
||||||
return len != 0;
|
return len != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
|
@ -396,7 +397,6 @@ dns_name_isequal(const unsigned char *queryptr, const char *name,
|
||||||
|
|
||||||
return name[0] == 0;
|
return name[0] == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
|
@ -427,7 +427,6 @@ skip_name(unsigned char *query)
|
||||||
DEBUG_PRINTF("\n");
|
DEBUG_PRINTF("\n");
|
||||||
return query + 1;
|
return query + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
|
@ -457,10 +456,8 @@ encode_name(unsigned char *query, const char *nameptr)
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
|
@ -468,7 +465,6 @@ mdns_announce_requested(void)
|
||||||
{
|
{
|
||||||
mdns_needs_host_announce = 1;
|
mdns_needs_host_announce = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
|
@ -478,7 +474,6 @@ start_name_collision_check(clock_time_t after)
|
||||||
process_exit(&mdns_probe_process);
|
process_exit(&mdns_probe_process);
|
||||||
process_start(&mdns_probe_process, (void *)&after);
|
process_start(&mdns_probe_process, (void *)&after);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
*/
|
*/
|
||||||
|
@ -524,7 +519,7 @@ mdns_write_announce_records(unsigned char *queryptr, uint8_t * count)
|
||||||
(*count)++;
|
(*count)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else /* UIP_CONF_IPV6 */
|
||||||
queryptr = encode_name(queryptr, resolv_hostname);
|
queryptr = encode_name(queryptr, resolv_hostname);
|
||||||
ans = (struct dns_answer *)queryptr;
|
ans = (struct dns_answer *)queryptr;
|
||||||
ans->type = UIP_HTONS(DNS_TYPE_A);
|
ans->type = UIP_HTONS(DNS_TYPE_A);
|
||||||
|
@ -535,10 +530,9 @@ mdns_write_announce_records(unsigned char *queryptr, uint8_t * count)
|
||||||
uip_gethostaddr((uip_ipaddr_t *) ans->ipaddr);
|
uip_gethostaddr((uip_ipaddr_t *) ans->ipaddr);
|
||||||
queryptr = (unsigned char *)ans + sizeof(*ans);
|
queryptr = (unsigned char *)ans + sizeof(*ans);
|
||||||
(*count)++;
|
(*count)++;
|
||||||
#endif
|
#endif /* UIP_CONF_IPV6 */
|
||||||
return queryptr;
|
return queryptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* Called when we need to announce ourselves
|
* Called when we need to announce ourselves
|
||||||
|
@ -590,20 +584,19 @@ mdns_prep_host_announce_packet(void)
|
||||||
*queryptr++ = 0x00;
|
*queryptr++ = 0x00;
|
||||||
*queryptr++ = 0x00;
|
*queryptr++ = 0x00;
|
||||||
*queryptr++ = 0x08;
|
*queryptr++ = 0x08;
|
||||||
#else
|
#else /* UIP_CONF_IPV6 */
|
||||||
*queryptr++ = 0x40;
|
*queryptr++ = 0x40;
|
||||||
*queryptr++ = 0x00;
|
*queryptr++ = 0x00;
|
||||||
*queryptr++ = 0x00;
|
*queryptr++ = 0x00;
|
||||||
*queryptr++ = 0x00;
|
*queryptr++ = 0x00;
|
||||||
#endif
|
#endif /* UIP_CONF_IPV6 */
|
||||||
|
|
||||||
hdr->numanswers = uip_htons(total_answers);
|
hdr->numanswers = uip_htons(total_answers);
|
||||||
hdr->numextrarr = UIP_HTONS(1);
|
hdr->numextrarr = UIP_HTONS(1);
|
||||||
|
|
||||||
return (queryptr - (unsigned char *)uip_appdata);
|
return (queryptr - (unsigned char *)uip_appdata);
|
||||||
}
|
}
|
||||||
#endif // #if RESOLV_CONF_SUPPORTS_MDNS
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* Runs through the list of names to see if there are any that have
|
* Runs through the list of names to see if there are any that have
|
||||||
|
@ -630,9 +623,9 @@ check_entries(void)
|
||||||
if(++namemapptr->retries ==
|
if(++namemapptr->retries ==
|
||||||
(namemapptr->is_mdns ? RESOLV_CONF_MAX_MDNS_RETRIES :
|
(namemapptr->is_mdns ? RESOLV_CONF_MAX_MDNS_RETRIES :
|
||||||
RESOLV_CONF_MAX_RETRIES))
|
RESOLV_CONF_MAX_RETRIES))
|
||||||
#else
|
#else /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
if(++namemapptr->retries == RESOLV_CONF_MAX_RETRIES)
|
if(++namemapptr->retries == RESOLV_CONF_MAX_RETRIES)
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
{
|
{
|
||||||
/* STATE_ERROR basically means "not found". */
|
/* STATE_ERROR basically means "not found". */
|
||||||
namemapptr->state = STATE_ERROR;
|
namemapptr->state = STATE_ERROR;
|
||||||
|
@ -650,7 +643,7 @@ check_entries(void)
|
||||||
/* Probing retries are much more aggressive, 250ms */
|
/* Probing retries are much more aggressive, 250ms */
|
||||||
namemapptr->tmr = 2;
|
namemapptr->tmr = 2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
} else {
|
} else {
|
||||||
/* Its timer has not run out, so we move on to next
|
/* Its timer has not run out, so we move on to next
|
||||||
* entry.
|
* entry.
|
||||||
|
@ -672,9 +665,9 @@ check_entries(void)
|
||||||
if(namemapptr->is_mdns) {
|
if(namemapptr->is_mdns) {
|
||||||
hdr->id = 0;
|
hdr->id = 0;
|
||||||
}
|
}
|
||||||
#else
|
#else /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
hdr->flags1 = DNS_FLAG1_RD;
|
hdr->flags1 = DNS_FLAG1_RD;
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
hdr->numquestions = UIP_HTONS(1);
|
hdr->numquestions = UIP_HTONS(1);
|
||||||
query = (char *)uip_appdata + sizeof(*hdr);
|
query = (char *)uip_appdata + sizeof(*hdr);
|
||||||
query = encode_name(query, namemapptr->name);
|
query = encode_name(query, namemapptr->name);
|
||||||
|
@ -683,15 +676,15 @@ check_entries(void)
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_ANY) >> 8);
|
*query++ = (uint8_t) ((DNS_TYPE_ANY) >> 8);
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_ANY));
|
*query++ = (uint8_t) ((DNS_TYPE_ANY));
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
{
|
{
|
||||||
#if UIP_CONF_IPV6
|
#if UIP_CONF_IPV6
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_AAAA) >> 8);
|
*query++ = (uint8_t) ((DNS_TYPE_AAAA) >> 8);
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_AAAA));
|
*query++ = (uint8_t) ((DNS_TYPE_AAAA));
|
||||||
#else
|
#else /* UIP_CONF_IPV6 */
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_A) >> 8);
|
*query++ = (uint8_t) ((DNS_TYPE_A) >> 8);
|
||||||
*query++ = (uint8_t) ((DNS_TYPE_A));
|
*query++ = (uint8_t) ((DNS_TYPE_A));
|
||||||
#endif
|
#endif /* UIP_CONF_IPV6 */
|
||||||
}
|
}
|
||||||
*query++ = (uint8_t) ((DNS_CLASS_IN) >> 8);
|
*query++ = (uint8_t) ((DNS_CLASS_IN) >> 8);
|
||||||
*query++ = (uint8_t) ((DNS_CLASS_IN));
|
*query++ = (uint8_t) ((DNS_CLASS_IN));
|
||||||
|
@ -709,36 +702,32 @@ check_entries(void)
|
||||||
query = mdns_write_announce_records(query, &count);
|
query = mdns_write_announce_records(query, &count);
|
||||||
hdr->numauthrr = UIP_HTONS(count);
|
hdr->numauthrr = UIP_HTONS(count);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
uip_udp_packet_sendto(resolv_conn,
|
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||||
uip_appdata,
|
|
||||||
(query - (uint8_t *) uip_appdata),
|
(query - (uint8_t *) uip_appdata),
|
||||||
&resolv_mdns_addr, UIP_HTONS(MDNS_PORT));
|
&resolv_mdns_addr, UIP_HTONS(MDNS_PORT));
|
||||||
|
|
||||||
PRINTF("resolver: (i=%d) Sent MDNS request for \"%s\".\n", i,
|
PRINTF("resolver: (i=%d) Sent MDNS request for \"%s\".\n", i,
|
||||||
namemapptr->name);
|
namemapptr->name);
|
||||||
} else {
|
} else {
|
||||||
uip_udp_packet_sendto(resolv_conn,
|
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||||
uip_appdata,
|
|
||||||
(query - (uint8_t *) uip_appdata),
|
(query - (uint8_t *) uip_appdata),
|
||||||
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
||||||
|
|
||||||
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
||||||
namemapptr->name);
|
namemapptr->name);
|
||||||
}
|
}
|
||||||
#else
|
#else /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
uip_udp_packet_sendto(resolv_conn,
|
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||||
uip_appdata,
|
|
||||||
(query - (uint8_t *) uip_appdata),
|
(query - (uint8_t *) uip_appdata),
|
||||||
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
&resolv_default_dns_server, UIP_HTONS(DNS_PORT));
|
||||||
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
PRINTF("resolver: (i=%d) Sent DNS request for \"%s\".\n", i,
|
||||||
namemapptr->name);
|
namemapptr->name);
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* Called when new UDP data arrives.
|
* Called when new UDP data arrives.
|
||||||
|
@ -796,7 +785,7 @@ newdata(void)
|
||||||
|
|
||||||
memcpy(&aligned, question, sizeof(aligned));
|
memcpy(&aligned, question, sizeof(aligned));
|
||||||
question = &aligned;
|
question = &aligned;
|
||||||
#endif
|
#endif /* __ARM__ */
|
||||||
|
|
||||||
DEBUG_PRINTF("resolver: Question %d: type=%d class=%d\n", ++i,
|
DEBUG_PRINTF("resolver: Question %d: type=%d class=%d\n", ++i,
|
||||||
uip_htons(question->type), uip_htons(question->class));
|
uip_htons(question->type), uip_htons(question->class));
|
||||||
|
@ -823,8 +812,7 @@ newdata(void)
|
||||||
if(UIP_UDP_BUF->srcport == UIP_HTONS(MDNS_PORT)) {
|
if(UIP_UDP_BUF->srcport == UIP_HTONS(MDNS_PORT)) {
|
||||||
mdns_announce_requested();
|
mdns_announce_requested();
|
||||||
} else {
|
} else {
|
||||||
uip_udp_packet_sendto(resolv_conn,
|
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||||
uip_appdata,
|
|
||||||
mdns_prep_host_announce_packet(),
|
mdns_prep_host_announce_packet(),
|
||||||
&UIP_UDP_BUF->srcipaddr,
|
&UIP_UDP_BUF->srcipaddr,
|
||||||
UIP_UDP_BUF->srcport);
|
UIP_UDP_BUF->srcport);
|
||||||
|
@ -848,7 +836,7 @@ newdata(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ANSWER HANDLING SECTION **************************************************/
|
/** ANSWER HANDLING SECTION **************************************************/
|
||||||
|
@ -868,7 +856,7 @@ newdata(void)
|
||||||
i = -1;
|
i = -1;
|
||||||
namemapptr = NULL;
|
namemapptr = NULL;
|
||||||
} else
|
} else
|
||||||
#endif // RESOLV_CONF_SUPPORTS_MDNS
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
{
|
{
|
||||||
/* The ID in the DNS header should be our entry into the name table. */
|
/* The ID in the DNS header should be our entry into the name table. */
|
||||||
i = RESOLV_DECODE_INDEX(hdr->id);
|
i = RESOLV_DECODE_INDEX(hdr->id);
|
||||||
|
@ -916,7 +904,7 @@ newdata(void)
|
||||||
|
|
||||||
memcpy(&aligned, ans, sizeof(aligned));
|
memcpy(&aligned, ans, sizeof(aligned));
|
||||||
ans = &aligned;
|
ans = &aligned;
|
||||||
#endif
|
#endif /* __ARM__ */
|
||||||
|
|
||||||
#if VERBOSE_DEBUG
|
#if VERBOSE_DEBUG
|
||||||
static char debug_name[40];
|
static char debug_name[40];
|
||||||
|
@ -927,14 +915,13 @@ newdata(void)
|
||||||
uip_ntohs(ans->class) & 0x7FFF,
|
uip_ntohs(ans->class) & 0x7FFF,
|
||||||
(int)((uint32_t) uip_ntohs(ans->ttl[0]) << 16) | (uint32_t)
|
(int)((uint32_t) uip_ntohs(ans->ttl[0]) << 16) | (uint32_t)
|
||||||
uip_ntohs(ans->ttl[1]), uip_ntohs(ans->len));
|
uip_ntohs(ans->ttl[1]), uip_ntohs(ans->len));
|
||||||
#endif
|
#endif /* VERBOSE_DEBUG */
|
||||||
|
|
||||||
/* Check the class and length of the answer to make sure
|
/* Check the class and length of the answer to make sure
|
||||||
* it matches what we are expecting
|
* it matches what we are expecting
|
||||||
*/
|
*/
|
||||||
if(((uip_ntohs(ans->class) & 0x7FFF) != DNS_CLASS_IN)
|
if(((uip_ntohs(ans->class) & 0x7FFF) != DNS_CLASS_IN) ||
|
||||||
|| (ans->len != UIP_HTONS(sizeof(uip_ipaddr_t)))
|
(ans->len != UIP_HTONS(sizeof(uip_ipaddr_t)))) {
|
||||||
) {
|
|
||||||
goto skip_to_next_answer;
|
goto skip_to_next_answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,11 +929,11 @@ newdata(void)
|
||||||
if(ans->type != UIP_HTONS(DNS_TYPE_AAAA)) {
|
if(ans->type != UIP_HTONS(DNS_TYPE_AAAA)) {
|
||||||
goto skip_to_next_answer;
|
goto skip_to_next_answer;
|
||||||
}
|
}
|
||||||
#else // UIP_CONF_IPV6
|
#else /* UIP_CONF_IPV6 */
|
||||||
if(ans->type != UIP_HTONS(DNS_TYPE_A)) {
|
if(ans->type != UIP_HTONS(DNS_TYPE_A)) {
|
||||||
goto skip_to_next_answer;
|
goto skip_to_next_answer;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* UIP_CONF_IPV6 */
|
||||||
|
|
||||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||||
if(UIP_UDP_BUF->srcport == UIP_HTONS(MDNS_PORT)
|
if(UIP_UDP_BUF->srcport == UIP_HTONS(MDNS_PORT)
|
||||||
|
@ -963,10 +950,9 @@ newdata(void)
|
||||||
if(dns_name_isequal(queryptr, namemapptr->name, uip_appdata)) {
|
if(dns_name_isequal(queryptr, namemapptr->name, uip_appdata)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if((namemapptr->state == STATE_UNUSED)
|
if((namemapptr->state == STATE_UNUSED) ||
|
||||||
|| (namemapptr->state == STATE_DONE
|
(namemapptr->state == STATE_DONE &&
|
||||||
&& clock_seconds() > namemapptr->expiration)
|
clock_seconds() > namemapptr->expiration)) {
|
||||||
) {
|
|
||||||
available_i = i;
|
available_i = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -994,7 +980,7 @@ newdata(void)
|
||||||
namemapptr = &names[i];
|
namemapptr = &names[i];
|
||||||
|
|
||||||
} else
|
} else
|
||||||
#endif // #if RESOLV_CONF_SUPPORTS_MDNS
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
{
|
{
|
||||||
/* This will force us to stop even if there are more answers. */
|
/* This will force us to stop even if there are more answers. */
|
||||||
nanswers = 1;
|
nanswers = 1;
|
||||||
|
@ -1018,14 +1004,12 @@ newdata(void)
|
||||||
resolv_found(namemapptr->name, &namemapptr->ipaddr);
|
resolv_found(namemapptr->name, &namemapptr->ipaddr);
|
||||||
|
|
||||||
skip_to_next_answer:
|
skip_to_next_answer:
|
||||||
queryptr =
|
queryptr = (unsigned char *)skip_name(queryptr) + 10 + uip_htons(ans->len);
|
||||||
(unsigned char *)skip_name(queryptr) + 10 + uip_htons(ans->len);
|
|
||||||
--nanswers;
|
--nanswers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RESOLV_CONF_SUPPORTS_MDNS
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#if RESOLV_CONF_SUPPORTS_MDNS
|
||||||
/**
|
/**
|
||||||
* \brief Changes the local hostname advertised by MDNS.
|
* \brief Changes the local hostname advertised by MDNS.
|
||||||
* \param hostname The new hostname to advertise.
|
* \param hostname The new hostname to advertise.
|
||||||
|
@ -1036,9 +1020,8 @@ resolv_set_hostname(const char *hostname)
|
||||||
strncpy(resolv_hostname, hostname, RESOLV_CONF_MAX_DOMAIN_NAME_SIZE);
|
strncpy(resolv_hostname, hostname, RESOLV_CONF_MAX_DOMAIN_NAME_SIZE);
|
||||||
|
|
||||||
/* Add the .local suffix if it isn't already there */
|
/* Add the .local suffix if it isn't already there */
|
||||||
if(strlen(resolv_hostname) < 7
|
if(strlen(resolv_hostname) < 7 ||
|
||||||
|| strcasecmp(resolv_hostname + strlen(resolv_hostname) - 6,
|
strcasecmp(resolv_hostname + strlen(resolv_hostname) - 6, ".local") != 0) {
|
||||||
".local") != 0) {
|
|
||||||
strncat(resolv_hostname, ".local", RESOLV_CONF_MAX_DOMAIN_NAME_SIZE);
|
strncat(resolv_hostname, ".local", RESOLV_CONF_MAX_DOMAIN_NAME_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1046,7 +1029,6 @@ resolv_set_hostname(const char *hostname)
|
||||||
|
|
||||||
start_name_collision_check(0);
|
start_name_collision_check(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \brief Returns the local hostname being advertised via MDNS.
|
* \brief Returns the local hostname being advertised via MDNS.
|
||||||
|
@ -1057,7 +1039,6 @@ resolv_get_hostname(void)
|
||||||
{
|
{
|
||||||
return resolv_hostname;
|
return resolv_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* Process for probing for name conflicts.
|
* Process for probing for name conflicts.
|
||||||
|
@ -1099,9 +1080,7 @@ PROCESS_THREAD(mdns_probe_process, ev, data)
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
}
|
}
|
||||||
#endif // RESOLV_CONF_SUPPORTS_MDNS
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* The main UDP function.
|
* The main UDP function.
|
||||||
|
@ -1156,8 +1135,7 @@ PROCESS_THREAD(resolv_process, ev, data)
|
||||||
|
|
||||||
len = mdns_prep_host_announce_packet();
|
len = mdns_prep_host_announce_packet();
|
||||||
|
|
||||||
uip_udp_packet_sendto(resolv_conn,
|
uip_udp_packet_sendto(resolv_conn, uip_appdata,
|
||||||
uip_appdata,
|
|
||||||
len, &resolv_mdns_addr, UIP_HTONS(MDNS_PORT));
|
len, &resolv_mdns_addr, UIP_HTONS(MDNS_PORT));
|
||||||
|
|
||||||
mdns_needs_host_announce = 0;
|
mdns_needs_host_announce = 0;
|
||||||
|
@ -1167,7 +1145,7 @@ PROCESS_THREAD(resolv_process, ev, data)
|
||||||
*/
|
*/
|
||||||
tcpip_poll_udp(resolv_conn);
|
tcpip_poll_udp(resolv_conn);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
{
|
{
|
||||||
check_entries();
|
check_entries();
|
||||||
}
|
}
|
||||||
|
@ -1179,15 +1157,11 @@ PROCESS_THREAD(resolv_process, ev, data)
|
||||||
if(mdns_needs_host_announce) {
|
if(mdns_needs_host_announce) {
|
||||||
tcpip_poll_udp(resolv_conn);
|
tcpip_poll_udp(resolv_conn);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For removing trailing dots in resolv_query() and resolve_lookup2(). */
|
|
||||||
static char dns_name_without_dots[RESOLV_CONF_MAX_DOMAIN_NAME_SIZE + 1];
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* Queues a name so that a question for the name will be sent out.
|
* Queues a name so that a question for the name will be sent out.
|
||||||
|
@ -1205,7 +1179,8 @@ resolv_query(const char *name)
|
||||||
|
|
||||||
lseq = lseqi = 0;
|
lseq = lseqi = 0;
|
||||||
|
|
||||||
{ /* Remove trailing dots, if present. */
|
/* Remove trailing dots, if present. */
|
||||||
|
{
|
||||||
size_t len = strlen(name);
|
size_t len = strlen(name);
|
||||||
|
|
||||||
if(name[len - 1] == '.') {
|
if(name[len - 1] == '.') {
|
||||||
|
@ -1222,10 +1197,9 @@ resolv_query(const char *name)
|
||||||
if(0 == strcasecmp(nameptr->name, name)) {
|
if(0 == strcasecmp(nameptr->name, name)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if((nameptr->state == STATE_UNUSED)
|
if((nameptr->state == STATE_UNUSED) ||
|
||||||
|| (nameptr->state == STATE_DONE
|
(nameptr->state == STATE_DONE &&
|
||||||
&& clock_seconds() > nameptr->expiration)
|
clock_seconds() > nameptr->expiration)) {
|
||||||
) {
|
|
||||||
lseqi = i;
|
lseqi = i;
|
||||||
lseq = 255;
|
lseq = 255;
|
||||||
} else if(seqno - nameptr->seqno > lseq) {
|
} else if(seqno - nameptr->seqno > lseq) {
|
||||||
|
@ -1254,25 +1228,21 @@ resolv_query(const char *name)
|
||||||
|
|
||||||
static const char local_suffix[] = "local";
|
static const char local_suffix[] = "local";
|
||||||
|
|
||||||
if((name_len > (sizeof(local_suffix) - 1))
|
if((name_len > (sizeof(local_suffix) - 1)) &&
|
||||||
&& (0 ==
|
(0 == strcasecmp(name + name_len - (sizeof(local_suffix) - 1), local_suffix))) {
|
||||||
strcasecmp(name + name_len - (sizeof(local_suffix) - 1),
|
|
||||||
local_suffix))
|
|
||||||
) {
|
|
||||||
PRINTF("resolver: Using MDNS to look up \"%s\".\n", name);
|
PRINTF("resolver: Using MDNS to look up \"%s\".\n", name);
|
||||||
nameptr->is_mdns = 1;
|
nameptr->is_mdns = 1;
|
||||||
} else {
|
} else {
|
||||||
nameptr->is_mdns = 0;
|
nameptr->is_mdns = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nameptr->is_probe = (mdns_state == MDNS_STATE_PROBING)
|
nameptr->is_probe = (mdns_state == MDNS_STATE_PROBING) &&
|
||||||
&& (0 == strcmp(nameptr->name, resolv_hostname));
|
(0 == strcmp(nameptr->name, resolv_hostname));
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
|
|
||||||
/* Force check_entires() to run on our process. */
|
/* Force check_entires() to run on our process. */
|
||||||
process_post(&resolv_process, PROCESS_EVENT_TIMER, 0);
|
process_post(&resolv_process, PROCESS_EVENT_TIMER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* Look up a hostname in the array of known hostnames.
|
* Look up a hostname in the array of known hostnames.
|
||||||
|
@ -1292,7 +1262,8 @@ resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr)
|
||||||
|
|
||||||
struct namemap *nameptr;
|
struct namemap *nameptr;
|
||||||
|
|
||||||
{ /* Remove trailing dots, if present. */
|
/* Remove trailing dots, if present. */
|
||||||
|
{
|
||||||
size_t len = strlen(name);
|
size_t len = strlen(name);
|
||||||
|
|
||||||
if(name[len - 1] == '.') {
|
if(name[len - 1] == '.') {
|
||||||
|
@ -1318,7 +1289,7 @@ resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr)
|
||||||
}
|
}
|
||||||
ret = RESOLV_STATUS_CACHED;
|
ret = RESOLV_STATUS_CACHED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* UIP_CONF_LOOPBACK_INTERFACE */
|
||||||
|
|
||||||
/* Walk through the list to see if the name is in there. */
|
/* Walk through the list to see if the name is in there. */
|
||||||
for(i = 0; i < RESOLV_ENTRIES; ++i) {
|
for(i = 0; i < RESOLV_ENTRIES; ++i) {
|
||||||
|
@ -1337,7 +1308,8 @@ resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr)
|
||||||
case STATE_ASKING:
|
case STATE_ASKING:
|
||||||
ret = RESOLV_STATUS_RESOLVING;
|
ret = RESOLV_STATUS_RESOLVING;
|
||||||
break;
|
break;
|
||||||
case STATE_ERROR: /* Almost certainly a not-found error from server */
|
/* Almost certainly a not-found error from server */
|
||||||
|
case STATE_ERROR:
|
||||||
if(clock_seconds() >= nameptr->expiration) {
|
if(clock_seconds() >= nameptr->expiration) {
|
||||||
ret = RESOLV_STATUS_NOT_FOUND;
|
ret = RESOLV_STATUS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
@ -1374,11 +1346,10 @@ resolv_lookup(const char *name, uip_ipaddr_t ** ipaddr)
|
||||||
DEBUG_PRINTF("resolver: \"%s\" is NOT cached.\n", name);
|
DEBUG_PRINTF("resolver: \"%s\" is NOT cached.\n", name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* VERBOSE_DEBUG */
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* Obtain the currently configured DNS server.
|
* Obtain the currently configured DNS server.
|
||||||
|
@ -1392,7 +1363,6 @@ resolv_getserver(void)
|
||||||
{
|
{
|
||||||
return &resolv_default_dns_server;
|
return &resolv_default_dns_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* Configure a DNS server.
|
* Configure a DNS server.
|
||||||
|
@ -1406,7 +1376,6 @@ resolv_conf(const uip_ipaddr_t * dnsserver)
|
||||||
uip_ipaddr_copy(&resolv_default_dns_server, dnsserver);
|
uip_ipaddr_copy(&resolv_default_dns_server, dnsserver);
|
||||||
process_post(&resolv_process, EVENT_NEW_SERVER, &resolv_default_dns_server);
|
process_post(&resolv_process, EVENT_NEW_SERVER, &resolv_default_dns_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \internal
|
/** \internal
|
||||||
* Callback function which is called when a hostname is found.
|
* Callback function which is called when a hostname is found.
|
||||||
|
@ -1462,7 +1431,7 @@ resolv_found(char *name, uip_ipaddr_t * ipaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif /* RESOLV_CONF_SUPPORTS_MDNS */
|
||||||
|
|
||||||
#if VERBOSE_DEBUG
|
#if VERBOSE_DEBUG
|
||||||
if(ipaddr) {
|
if(ipaddr) {
|
||||||
|
@ -1480,7 +1449,7 @@ resolv_found(char *name, uip_ipaddr_t * ipaddr)
|
||||||
} else {
|
} else {
|
||||||
PRINTF("resolver: Unable to retrieve address for \"%s\".\n", name);
|
PRINTF("resolver: Unable to retrieve address for \"%s\".\n", name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* VERBOSE_DEBUG */
|
||||||
|
|
||||||
process_post(PROCESS_BROADCAST, resolv_event_found, name);
|
process_post(PROCESS_BROADCAST, resolv_event_found, name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue