mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
dns_msg: add debug output
This commit is contained in:
parent
74356c9737
commit
305b5db4eb
@ -26,6 +26,9 @@
|
||||
|
||||
#include "net/dns/msg.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
static ssize_t _enc_domain_name(uint8_t *out, const char *domain_name)
|
||||
{
|
||||
/*
|
||||
@ -76,10 +79,13 @@ static ssize_t _skip_hostname(const uint8_t *buf, size_t len,
|
||||
|
||||
if (bufpos >= buflim) {
|
||||
/* out-of-bound */
|
||||
DEBUG("dns_msg: bufpos is out of bounds\n");
|
||||
return -EBADMSG;
|
||||
}
|
||||
|
||||
/* handle DNS Message Compression */
|
||||
if (*bufpos >= 192) {
|
||||
if (*bufpos & 0xc0) {
|
||||
DEBUG("dns_msg: hostname is compressed\n");
|
||||
if ((bufpos + 2) >= buflim) {
|
||||
return -EBADMSG;
|
||||
}
|
||||
@ -90,6 +96,7 @@ static ssize_t _skip_hostname(const uint8_t *buf, size_t len,
|
||||
res += bufpos[res] + 1;
|
||||
if ((&bufpos[res]) >= buflim) {
|
||||
/* out-of-bound */
|
||||
DEBUG("dns_msg: hostname out-of-bounds\n");
|
||||
return -EBADMSG;
|
||||
}
|
||||
}
|
||||
@ -156,6 +163,7 @@ int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family,
|
||||
bufpos += tmp;
|
||||
if ((bufpos + RR_TYPE_LENGTH + RR_CLASS_LENGTH +
|
||||
RR_TTL_LENGTH + sizeof(uint16_t)) >= buflim) {
|
||||
DEBUG("dns_msg: record beyond buf limit");
|
||||
return -EBADMSG;
|
||||
}
|
||||
uint16_t _type = ntohs(_get_short(bufpos));
|
||||
@ -173,6 +181,8 @@ int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family,
|
||||
return -EBADMSG;
|
||||
}
|
||||
|
||||
DEBUG("dns_msg: type: %u, class: %u, len: %u\n", _type, class, addrlen);
|
||||
|
||||
/* skip unwanted answers */
|
||||
if ((class != DNS_CLASS_IN) ||
|
||||
((_type == DNS_TYPE_A) && (family == AF_INET6)) ||
|
||||
|
Loading…
Reference in New Issue
Block a user