From 7920ab2b95a4c6d2756687b9dee635e036d96dbc Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 11 Aug 2021 11:43:06 +0200 Subject: [PATCH] dns_msg: make parsing input buffer const --- sys/include/net/dns/msg.h | 3 ++- sys/net/application_layer/dns/msg.c | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sys/include/net/dns/msg.h b/sys/include/net/dns/msg.h index 9a0975f291..8faa54f4a1 100644 --- a/sys/include/net/dns/msg.h +++ b/sys/include/net/dns/msg.h @@ -109,7 +109,8 @@ size_t dns_msg_compose_query(void *dns_buf, const char *domain_name, * @return -EBADMSG, when an address corresponding to @p family can not be found * in @p buf. */ -int dns_msg_parse_reply(uint8_t *buf, size_t len, int family, void *addr_out); +int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family, + void *addr_out); #ifdef __cplusplus } diff --git a/sys/net/application_layer/dns/msg.c b/sys/net/application_layer/dns/msg.c index 8e119d9f7c..ea9d0854d3 100644 --- a/sys/net/application_layer/dns/msg.c +++ b/sys/net/application_layer/dns/msg.c @@ -61,14 +61,15 @@ static unsigned _put_short(uint8_t *out, uint16_t val) return 2; } -static unsigned _get_short(uint8_t *buf) +static unsigned _get_short(const uint8_t *buf) { uint16_t _tmp; memcpy(&_tmp, buf, 2); return _tmp; } -static ssize_t _skip_hostname(const uint8_t *buf, size_t len, uint8_t *bufpos) +static ssize_t _skip_hostname(const uint8_t *buf, size_t len, + const uint8_t *bufpos) { const uint8_t *buflim = buf + len; unsigned res = 0; @@ -129,11 +130,12 @@ size_t dns_msg_compose_query(void *dns_buf, const char *domain_name, return bufpos - buf; } -int dns_msg_parse_reply(uint8_t *buf, size_t len, int family, void *addr_out) +int dns_msg_parse_reply(const uint8_t *buf, size_t len, int family, + void *addr_out) { const uint8_t *buflim = buf + len; - dns_hdr_t *hdr = (dns_hdr_t *)buf; - uint8_t *bufpos = buf + sizeof(*hdr); + const dns_hdr_t *hdr = (dns_hdr_t *)buf; + const uint8_t *bufpos = buf + sizeof(*hdr); /* skip all queries that are part of the reply */ for (unsigned n = 0; n < ntohs(hdr->qdcount); n++) {