Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/dns.h
// Copyright (c) 2017-2019 The Bitcoin developers | // Copyright (c) 2017-2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SEEDER_DNS_H | #ifndef BITCOIN_SEEDER_DNS_H | ||||
#define BITCOIN_SEEDER_DNS_H 1 | #define BITCOIN_SEEDER_DNS_H 1 | ||||
#include <cstddef> | #include <cstddef> | ||||
#include <cstdint> | #include <cstdint> | ||||
constexpr int MAX_LABEL_LENGTH = 63; | |||||
constexpr int MAX_QUERY_NAME_LENGTH = 255; | |||||
// Max size of the null-terminated buffer parse_name() writes to. | |||||
constexpr int MAX_QUERY_NAME_BUFFER_LENGTH = MAX_QUERY_NAME_LENGTH + 1; | |||||
struct addr_t { | struct addr_t { | ||||
int v; | int v; | ||||
union { | union { | ||||
uint8_t v4[4]; | uint8_t v4[4]; | ||||
uint8_t v6[16]; | uint8_t v6[16]; | ||||
} data; | } data; | ||||
}; | }; | ||||
struct dns_opt_t { | struct dns_opt_t { | ||||
int port; | int port; | ||||
int datattl; | int datattl; | ||||
int nsttl; | int nsttl; | ||||
const char *host; | const char *host; | ||||
const char *ns; | const char *ns; | ||||
const char *mbox; | const char *mbox; | ||||
uint32_t (*cb)(void *opt, char *requested_hostname, addr_t *addr, | uint32_t (*cb)(void *opt, char *requested_hostname, addr_t *addr, | ||||
uint32_t max, uint32_t ipv4, uint32_t ipv6); | uint32_t max, uint32_t ipv4, uint32_t ipv6); | ||||
// stats | // stats | ||||
uint64_t nRequests; | uint64_t nRequests; | ||||
}; | }; | ||||
// 0: ok | // 0: ok | ||||
// -1: premature end of input, forward reference, component > 63 char, invalid | // -1: premature end of input, forward reference, label > MAX_LABEL_LENGTH, | ||||
// character | // invalid character | ||||
// -2: insufficient space in output | // -2: insufficient space in output | ||||
int parse_name(const uint8_t **inpos, const uint8_t *inend, | int parse_name(const uint8_t **inpos, const uint8_t *inend, | ||||
const uint8_t *inbuf, char *buf, size_t bufsize); | const uint8_t *inbuf, char *buf, size_t bufsize); | ||||
int dnsserver(dns_opt_t *opt); | int dnsserver(dns_opt_t *opt); | ||||
#endif // BITCOIN_SEEDER_DNS_H | #endif // BITCOIN_SEEDER_DNS_H |