Add --address, bind to specific address

This commit is contained in:
uhliksk 2020-08-06 03:23:55 +02:00
parent 529a667f30
commit bf40486011
No known key found for this signature in database
GPG key ID: 694EC7F466459F2D
3 changed files with 20 additions and 3 deletions

View file

@ -425,7 +425,7 @@ int dnsserver(dns_opt_t *opt) {
memset((char *) &si_me, 0, sizeof(si_me)); memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin6_family = AF_INET6; si_me.sin6_family = AF_INET6;
si_me.sin6_port = htons(opt->port); si_me.sin6_port = htons(opt->port);
si_me.sin6_addr = in6addr_any; inet_pton(AF_INET6, opt->addr, &si_me.sin6_addr);
if (bind(listenSocket, (struct sockaddr*)&si_me, sizeof(si_me))==-1) if (bind(listenSocket, (struct sockaddr*)&si_me, sizeof(si_me))==-1)
return -2; return -2;
} }

1
dns.h
View file

@ -16,6 +16,7 @@ struct dns_opt_t {
int datattl; int datattl;
int nsttl; int nsttl;
const char *host; const char *host;
const char *addr;
const char *ns; const char *ns;
const char *mbox; const char *mbox;
int (*cb)(void *opt, char *requested_hostname, addr_t *addr, int max, int ipv4, int ipv6); int (*cb)(void *opt, char *requested_hostname, addr_t *addr, int max, int ipv4, int ipv6);

View file

@ -28,11 +28,12 @@ public:
const char *ns; const char *ns;
const char *host; const char *host;
const char *tor; const char *tor;
const char *ip_addr;
const char *ipv4_proxy; const char *ipv4_proxy;
const char *ipv6_proxy; const char *ipv6_proxy;
std::set<uint64_t> filter_whitelist; std::set<uint64_t> filter_whitelist;
CDnsSeedOpts() : nThreads(96), nDnsThreads(4), nPort(53), mbox(NULL), ns(NULL), host(NULL), tor(NULL), fUseTestNet(false), fWipeBan(false), fWipeIgnore(false), ipv4_proxy(NULL), ipv6_proxy(NULL) {} CDnsSeedOpts() : nThreads(96), nDnsThreads(4), ip_addr("::"), nPort(53), mbox(NULL), ns(NULL), host(NULL), tor(NULL), fUseTestNet(false), fWipeBan(false), fWipeIgnore(false), ipv4_proxy(NULL), ipv6_proxy(NULL) {}
void ParseCommandLine(int argc, char **argv) { void ParseCommandLine(int argc, char **argv) {
static const char *help = "Bitcoin-seeder\n" static const char *help = "Bitcoin-seeder\n"
@ -44,6 +45,7 @@ public:
"-m <mbox> E-Mail address reported in SOA records\n" "-m <mbox> E-Mail address reported in SOA records\n"
"-t <threads> Number of crawlers to run in parallel (default 96)\n" "-t <threads> Number of crawlers to run in parallel (default 96)\n"
"-d <threads> Number of DNS server threads (default 4)\n" "-d <threads> Number of DNS server threads (default 4)\n"
"-a <address> Address to listen on (default ::)\n"
"-p <port> UDP port to listen on (default 53)\n" "-p <port> UDP port to listen on (default 53)\n"
"-o <ip:port> Tor proxy IP/Port\n" "-o <ip:port> Tor proxy IP/Port\n"
"-i <ip:port> IPV4 SOCKS5 proxy IP/Port\n" "-i <ip:port> IPV4 SOCKS5 proxy IP/Port\n"
@ -63,6 +65,7 @@ public:
{"mbox", required_argument, 0, 'm'}, {"mbox", required_argument, 0, 'm'},
{"threads", required_argument, 0, 't'}, {"threads", required_argument, 0, 't'},
{"dnsthreads", required_argument, 0, 'd'}, {"dnsthreads", required_argument, 0, 'd'},
{"address", required_argument, 0, 'a'},
{"port", required_argument, 0, 'p'}, {"port", required_argument, 0, 'p'},
{"onion", required_argument, 0, 'o'}, {"onion", required_argument, 0, 'o'},
{"proxyipv4", required_argument, 0, 'i'}, {"proxyipv4", required_argument, 0, 'i'},
@ -75,7 +78,7 @@ public:
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "h:n:m:t:p:d:o:i:k:w:", long_options, &option_index); int c = getopt_long(argc, argv, "h:n:m:t:a:p:d:o:i:k:w:", long_options, &option_index);
if (c == -1) break; if (c == -1) break;
switch (c) { switch (c) {
case 'h': { case 'h': {
@ -105,6 +108,18 @@ public:
break; break;
} }
case 'a': {
if (strchr(optarg, ':')==NULL) {
char* ip4_addr = (char*) malloc(strlen(optarg)+8);
strcpy(ip4_addr, "::FFFF:");
strcat(ip4_addr, optarg);
ip_addr = ip4_addr;
} else {
ip_addr = optarg;
}
break;
}
case 'p': { case 'p': {
int p = strtol(optarg, NULL, 10); int p = strtol(optarg, NULL, 10);
if (p > 0 && p < 65536) nPort = p; if (p > 0 && p < 65536) nPort = p;
@ -260,6 +275,7 @@ public:
dns_opt.datattl = 3600; dns_opt.datattl = 3600;
dns_opt.nsttl = 40000; dns_opt.nsttl = 40000;
dns_opt.cb = GetIPList; dns_opt.cb = GetIPList;
dns_opt.addr = opts->ip_addr;
dns_opt.port = opts->nPort; dns_opt.port = opts->nPort;
dns_opt.nRequests = 0; dns_opt.nRequests = 0;
dbQueries = 0; dbQueries = 0;