1 /** 2 * Determine the length of an uncompressed wire format domain name. 3 * 4 * \param[in] p pointer to uncompressed domain name 5 * \param[in] eop pointer to end of buffer containing name 6 * \param[out] sz length of name 7 * 8 * \return wdns_res_success 9 * \return wdns_res_name_len 10 * \return wdns_res_overflow 11 * \return wdns_res_invalid_length_octet 12 */ 13 14 wdns_res wdns_len_uname(const uint8_t * p,const uint8_t * eop,size_t * sz)15wdns_len_uname(const uint8_t *p, const uint8_t *eop, size_t *sz) 16 { 17 uint32_t olen = eop - p; 18 uint32_t len = olen; 19 20 if (p >= eop) 21 return (wdns_res_overflow); 22 23 while (len-- != 0) { 24 uint8_t oclen; 25 WDNS_BUF_GET8(oclen, p); 26 27 if (oclen > 63 || oclen > len) 28 return (wdns_res_invalid_length_octet); 29 if (oclen == 0) 30 break; 31 32 WDNS_BUF_ADVANCE(p, len, oclen); 33 } 34 35 *sz = olen - len; 36 if (*sz > WDNS_MAXLEN_NAME) 37 return (wdns_res_name_len); 38 return (wdns_res_success); 39 } 40