Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
11static const uint8_t END_OF_NAME_FIELD = 0;
12
13// Builds the name field of the question section of a DNS query
14static std::vector<uint8_t>
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 }
38
39 return nameField;
40}
41
42#endif // BITCOIN_SEEDER_TEST_DNS_UTIL_H
static std::vector< uint8_t > CreateDNSQuestionNameField(const std::string &queryName)
Definition dns_util.h:15
static const uint8_t END_OF_NAME_FIELD
Definition dns_util.h:11
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85