1919#include <string.h>
2020#include <stdio.h>
2121
22+ #include "net/dns.h"
2223#include "net/sock/udp.h"
2324#include "net/sock/dns.h"
2425
@@ -114,7 +115,8 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
114115 return tmp ;
115116 }
116117 bufpos += tmp ;
117- bufpos += 4 ; /* skip type and class of query */
118+ /* skip type and class of query */
119+ bufpos += (RR_TYPE_LENGTH + RR_CLASS_LENGTH );
118120 }
119121
120122 for (unsigned n = 0 ; n < ntohs (hdr -> ancount ); n ++ ) {
@@ -123,14 +125,14 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
123125 return tmp ;
124126 }
125127 bufpos += tmp ;
126- if ((bufpos + 2 + 2 + 4 ) >= buflim ) {
128+ if ((bufpos + RR_TYPE_LENGTH + RR_CLASS_LENGTH + RR_TTL_LENGTH ) >= buflim ) {
127129 return - EBADMSG ;
128130 }
129131 uint16_t _type = ntohs (_get_short (bufpos ));
130- bufpos += 2 ;
132+ bufpos += RR_TYPE_LENGTH ;
131133 uint16_t class = ntohs (_get_short (bufpos ));
132- bufpos += 2 ;
133- bufpos += 4 ; /* skip ttl */
134+ bufpos += RR_CLASS_LENGTH ;
135+ bufpos += RR_TTL_LENGTH ; /* skip ttl */
134136
135137 unsigned addrlen = ntohs (_get_short (bufpos ));
136138 /* skip unwanted answers */
@@ -154,7 +156,7 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
154156 (family == AF_UNSPEC ))) {
155157 return - EBADMSG ;
156158 }
157- bufpos += 2 ;
159+ bufpos += RR_RDLENGTH_LENGTH ;
158160 if ((bufpos + addrlen ) >= buflim ) {
159161 return - EBADMSG ;
160162 }
0 commit comments