Bitcoin ABC  0.22.13
P2P Digital Currency
dns_util.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SEEDER_TEST_DNS_UTIL_H
6 #define BITCOIN_SEEDER_TEST_DNS_UTIL_H
7 
8 #include <string>
9 #include <vector>
10 
11 static const uint8_t END_OF_NAME_FIELD = 0;
12 
13 // Builds the name field of the question section of a DNS query
14 static std::vector<uint8_t>
15 CreateDNSQuestionNameField(const std::string &queryName) {
16  std::vector<uint8_t> nameField;
17  size_t i = 0;
18  size_t labelIndex = 0;
19  while (i < queryName.size()) {
20  if (queryName[i] == '.') {
21  // Push the length of the label and then the label
22  nameField.push_back(i - labelIndex);
23  while (labelIndex < i) {
24  nameField.push_back(queryName[labelIndex]);
25  labelIndex++;
26  }
27  labelIndex = i + 1;
28  }
29  i++;
30  }
31  // Push the length of the label and then the label
32  nameField.push_back(i - labelIndex);
33  while (labelIndex < i) {
34  nameField.push_back(queryName[labelIndex]);
35  labelIndex++;
36  }
37  nameField.push_back(END_OF_NAME_FIELD);
38 
39  return nameField;
40 }
41 
42 #endif // BITCOIN_SEEDER_TEST_DNS_UTIL_H
static const uint8_t END_OF_NAME_FIELD
Definition: dns_util.h:11
static std::vector< uint8_t > CreateDNSQuestionNameField(const std::string &queryName)
Definition: dns_util.h:15