Bitcoin ABC  0.22.12
P2P Digital Currency
dns.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 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_DNS_H
6 #define BITCOIN_SEEDER_DNS_H 1
7 
8 #include <cstddef>
9 #include <cstdint>
10 
11 constexpr int MAX_LABEL_LENGTH = 63;
12 constexpr int MAX_QUERY_NAME_LENGTH = 255;
13 // Max size of the null-terminated buffer parse_name() writes to.
15 
16 struct addr_t {
17  int v;
18  union {
19  uint8_t v4[4];
20  uint8_t v6[16];
21  } data;
22 };
23 
24 struct dns_opt_t {
25  int port;
26  int datattl;
27  int nsttl;
28  const char *host;
29  const char *ns;
30  const char *mbox;
31  uint32_t (*cb)(void *opt, char *requested_hostname, addr_t *addr,
32  uint32_t max, uint32_t ipv4, uint32_t ipv6);
33  // stats
34  uint64_t nRequests;
35 };
36 
37 enum class ParseNameStatus {
38  OK,
39  // Premature end of input, forward reference, component > 63 char, invalid
40  // character
41  InputError,
42  // Insufficient space in output
44 };
45 
46 ParseNameStatus parse_name(const uint8_t **inpos, const uint8_t *inend,
47  const uint8_t *inbuf, char *buf, size_t bufsize);
48 
49 // 0: k
50 // -1: component > 63 characters
51 // -2: insufficent space in output
52 // -3: two subsequent dots
53 int write_name(uint8_t **outpos, const uint8_t *outend, const char *name,
54  int offset);
55 
56 int dnsserver(dns_opt_t *opt);
57 
58 #endif // BITCOIN_SEEDER_DNS_H
uint64_t nRequests
Definition: dns.h:34
ParseNameStatus
Definition: dns.h:37
Definition: dns.h:24
constexpr int MAX_LABEL_LENGTH
Definition: dns.h:11
int datattl
Definition: dns.h:26
int v
Definition: dns.h:17
union addr_t::@20 data
ParseNameStatus parse_name(const uint8_t **inpos, const uint8_t *inend, const uint8_t *inbuf, char *buf, size_t bufsize)
Definition: dns.cpp:66
int nsttl
Definition: dns.h:27
const char * name
Definition: rest.cpp:43
uint8_t v6[16]
Definition: dns.h:20
constexpr int MAX_QUERY_NAME_BUFFER_LENGTH
Definition: dns.h:14
int dnsserver(dns_opt_t *opt)
Definition: dns.cpp:596
const char * host
Definition: dns.h:28
Definition: dns.h:16
int port
Definition: dns.h:25
const char * ns
Definition: dns.h:29
const char * mbox
Definition: dns.h:30
int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, int offset)
Definition: dns.cpp:132
constexpr int MAX_QUERY_NAME_LENGTH
Definition: dns.h:12
uint8_t v4[4]
Definition: dns.h:19