1 /** 2 * Skip a possibly compressed domain name. 3 * 4 * This function will skip to the end of the buffer if a compression pointer 5 * or the terminal zero octet is not found. 6 * 7 * \param[in,out] data start of the domain name 8 * \param[in] eod end of buffer containing the domain name 9 * 10 * \return number of bytes skipped 11 */ 12 13 size_t wdns_skip_name(const uint8_t ** data,const uint8_t * eod)14wdns_skip_name(const uint8_t **data, const uint8_t *eod) 15 { 16 const uint8_t *src = *data; 17 size_t bytes_skipped; 18 uint8_t c; 19 20 while (src <= eod && (c = *src) != 0) { 21 if (c >= 192) { 22 /* compression pointers occupy two octets */ 23 src++; 24 break; 25 } else { 26 /* skip c octets to the end of the label, then one more to the next 27 * length octet */ 28 src += c + 1; 29 } 30 } 31 32 /* advance to one octet beyond the end of the name */ 33 src++; 34 35 if (src > eod) 36 src = eod; 37 38 bytes_skipped = src - *data; 39 *data = src; 40 41 return (bytes_skipped); 42 } 43