Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/dns.cpp
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 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. | ||||
#include <seeder/dns.h> | #include <seeder/dns.h> | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <util/time.h> | |||||
#include <cctype> | #include <cctype> | ||||
#include <cstdbool> | #include <cstdbool> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cstring> | #include <cstring> | ||||
#include <ctime> | #include <ctime> | ||||
▲ Show 20 Lines • Show All 454 Lines • ▼ Show 20 Lines | if (nquestion > 1) { | ||||
(cls == CLASS_IN || cls == QCLASS_ANY))) { | (cls == CLASS_IN || cls == QCLASS_ANY))) { | ||||
// authority section will be necessary, either NS or SOA | // authority section will be necessary, either NS or SOA | ||||
uint8_t *newpos = outpos; | uint8_t *newpos = outpos; | ||||
write_record_ns(&newpos, outend, "", offset, CLASS_IN, 0, opt->ns); | write_record_ns(&newpos, outend, "", offset, CLASS_IN, 0, opt->ns); | ||||
max_auth_size = newpos - outpos; | max_auth_size = newpos - outpos; | ||||
newpos = outpos; | newpos = outpos; | ||||
write_record_soa(&newpos, outend, "", offset, CLASS_IN, opt->nsttl, | write_record_soa(&newpos, outend, "", offset, CLASS_IN, opt->nsttl, | ||||
opt->ns, opt->mbox, time(NULL), 604800, 86400, | opt->ns, opt->mbox, GetTime(), 604800, 86400, | ||||
2592000, 604800); | 2592000, 604800); | ||||
if (max_auth_size < newpos - outpos) { | if (max_auth_size < newpos - outpos) { | ||||
max_auth_size = newpos - outpos; | max_auth_size = newpos - outpos; | ||||
} | } | ||||
// tfm::format(std::cout, "Authority section will claim %i bytes | // tfm::format(std::cout, "Authority section will claim %i bytes | ||||
// max\n", max_auth_size); | // max\n", max_auth_size); | ||||
} | } | ||||
Show All 12 Lines | if (nquestion > 1) { | ||||
} | } | ||||
// SOA records | // SOA records | ||||
if ((typ == TYPE_SOA || typ == QTYPE_ANY) && | if ((typ == TYPE_SOA || typ == QTYPE_ANY) && | ||||
(cls == CLASS_IN || cls == QCLASS_ANY) && opt->mbox) { | (cls == CLASS_IN || cls == QCLASS_ANY) && opt->mbox) { | ||||
int ret2 = | int ret2 = | ||||
write_record_soa(&outpos, outend - max_auth_size, "", offset, | write_record_soa(&outpos, outend - max_auth_size, "", offset, | ||||
CLASS_IN, opt->nsttl, opt->ns, opt->mbox, | CLASS_IN, opt->nsttl, opt->ns, opt->mbox, | ||||
time(NULL), 604800, 86400, 2592000, 604800); | GetTime(), 604800, 86400, 2592000, 604800); | ||||
// tfm::format(std::cout, "wrote SOA record: %i\n", ret2); | // tfm::format(std::cout, "wrote SOA record: %i\n", ret2); | ||||
if (!ret2) { | if (!ret2) { | ||||
outbuf[7]++; | outbuf[7]++; | ||||
} | } | ||||
} | } | ||||
// A/AAAA records | // A/AAAA records | ||||
if ((typ == TYPE_A || typ == TYPE_AAAA || typ == QTYPE_ANY) && | if ((typ == TYPE_A || typ == TYPE_AAAA || typ == QTYPE_ANY) && | ||||
Show All 36 Lines | if (nquestion > 1) { | ||||
} | } | ||||
} else if (!outbuf[7]) { | } else if (!outbuf[7]) { | ||||
// Didn't include any answers, so reply with SOA as this is a | // Didn't include any answers, so reply with SOA as this is a | ||||
// negative response. If we replied with NS above we'd create a bad | // negative response. If we replied with NS above we'd create a bad | ||||
// horizontal referral loop, as the NS response indicates where the | // horizontal referral loop, as the NS response indicates where the | ||||
// resolver should try next. | // resolver should try next. | ||||
int ret2 = write_record_soa( | int ret2 = write_record_soa( | ||||
&outpos, outend, "", offset, CLASS_IN, opt->nsttl, opt->ns, | &outpos, outend, "", offset, CLASS_IN, opt->nsttl, opt->ns, | ||||
opt->mbox, time(NULL), 604800, 86400, 2592000, 604800); | opt->mbox, GetTime(), 604800, 86400, 2592000, 604800); | ||||
// tfm::format(std::cout, "wrote SOA record: %i\n", ret2); | // tfm::format(std::cout, "wrote SOA record: %i\n", ret2); | ||||
if (!ret2) { | if (!ret2) { | ||||
outbuf[9]++; | outbuf[9]++; | ||||
} | } | ||||
} | } | ||||
// set AA | // set AA | ||||
outbuf[2] |= 4; | outbuf[2] |= 4; | ||||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |