Bitcoin ABC  0.24.7
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 *addr;
30  const char *ns;
31  const char *mbox;
32  uint32_t (*cb)(void *opt, char *requested_hostname, addr_t *addr,
33  uint32_t max, uint32_t ipv4, uint32_t ipv6);
34  // stats
35  uint64_t nRequests;
36 };
37 
38 enum class ParseNameStatus {
39  OK,
40  // Premature end of input, forward reference, component > 63 char, invalid
41  // character
42  InputError,
43  // Insufficient space in output
45 };
46 
47 ParseNameStatus parse_name(const uint8_t **inpos, const uint8_t *inend,
48  const uint8_t *inbuf, char *buf, size_t bufsize);
49 
50 // 0: k
51 // -1: component > 63 characters
52 // -2: insufficent space in output
53 // -3: two subsequent dots
54 int write_name(uint8_t **outpos, const uint8_t *outend, const char *name,
55  int offset);
56 
57 int dnsserver(dns_opt_t *opt);
58 
59 #endif // BITCOIN_SEEDER_DNS_H
ParseNameStatus
ParseNameStatus
Definition: dns.h:38
dns_opt_t::nsttl
int nsttl
Definition: dns.h:27
dnsserver
int dnsserver(dns_opt_t *opt)
Definition: dns.cpp:596
parse_name
ParseNameStatus parse_name(const uint8_t **inpos, const uint8_t *inend, const uint8_t *inbuf, char *buf, size_t bufsize)
Definition: dns.cpp:66
dns_opt_t::mbox
const char * mbox
Definition: dns.h:31
addr_t::v6
uint8_t v6[16]
Definition: dns.h:20
MAX_QUERY_NAME_BUFFER_LENGTH
constexpr int MAX_QUERY_NAME_BUFFER_LENGTH
Definition: dns.h:14
dns_opt_t::host
const char * host
Definition: dns.h:28
MAX_LABEL_LENGTH
constexpr int MAX_LABEL_LENGTH
Definition: dns.h:11
ParseNameStatus::InputError
@ InputError
dns_opt_t::port
int port
Definition: dns.h:25
addr_t::v4
uint8_t v4[4]
Definition: dns.h:19
ParseNameStatus::OK
@ OK
dns_opt_t::nRequests
uint64_t nRequests
Definition: dns.h:35
MAX_QUERY_NAME_LENGTH
constexpr int MAX_QUERY_NAME_LENGTH
Definition: dns.h:12
addr_t::data
union addr_t::@17 data
name
const char * name
Definition: rest.cpp:43
dns_opt_t::addr
const char * addr
Definition: dns.h:29
write_name
int write_name(uint8_t **outpos, const uint8_t *outend, const char *name, int offset)
Definition: dns.cpp:132
dns_opt_t
Definition: dns.h:24
addr_t
Definition: dns.h:16
ParseNameStatus::OutputBufferError
@ OutputBufferError
dns_opt_t::datattl
int datattl
Definition: dns.h:26
addr_t::v
int v
Definition: dns.h:17
dns_opt_t::cb
uint32_t(* cb)(void *opt, char *requested_hostname, addr_t *addr, uint32_t max, uint32_t ipv4, uint32_t ipv6)
Definition: dns.h:32
dns_opt_t::ns
const char * ns
Definition: dns.h:30