| 553 | } |
| 554 | |
| 555 | static void WriteNameCompressed(std::vector<uint8_t>* buffer, const char* name, std::map<std::string, uint16_t>* suffix_offsets) |
| 556 | { |
| 557 | const bool enable_compression = suffix_offsets != 0; |
| 558 | const char* cursor = name; |
| 559 | while (*cursor) |
| 560 | { |
| 561 | if (enable_compression) |
| 562 | { |
| 563 | std::map<std::string, uint16_t>::iterator it = suffix_offsets->find(cursor); |
| 564 | if (it != suffix_offsets->end()) |
| 565 | { |
| 566 | const uint16_t pointer = it->second; |
| 567 | buffer->push_back((uint8_t) (0xC0 | ((pointer >> 8) & 0x3F))); |
| 568 | buffer->push_back((uint8_t) (pointer & 0xFF)); |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | (*suffix_offsets)[cursor] = (uint16_t) buffer->size(); |
| 573 | } |
| 574 | |
| 575 | char label[63]; |
| 576 | uint32_t label_len = 0; |
| 577 | while (*cursor && *cursor != '.') |
| 578 | { |
| 579 | ASSERT_TRUE(label_len < sizeof(label)); |
| 580 | ASSERT_TRUE(DecodeEscapedChar(&cursor, &label[label_len])); |
| 581 | ++label_len; |
| 582 | } |
| 583 | buffer->push_back((uint8_t) label_len); |
| 584 | buffer->insert(buffer->end(), label, label + label_len); |
| 585 | if (*cursor == '.') |
| 586 | ++cursor; |
| 587 | } |
| 588 | |
| 589 | buffer->push_back(0); |
| 590 | } |
| 591 | |
| 592 | static void BuildResponsePacket(const RawDnsResponseRecord* records, uint32_t record_count, bool compress_names, std::vector<uint8_t>* buffer) |
| 593 | { |
no test coverage detected