]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/notify.cc
auth 4.1 build: Switch to devtoolset 7 for el6
[thirdparty/pdns.git] / pdns / notify.cc
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include <bitset>
26 #include "dnsparser.hh"
27 #include "iputils.hh"
28 #undef L
29 #include <boost/program_options.hpp>
30
31 #include <boost/format.hpp>
32 #include <boost/utility.hpp>
33 #include <boost/multi_index_container.hpp>
34 #include <boost/multi_index/ordered_index.hpp>
35 #include <boost/multi_index/key_extractors.hpp>
36
37 #include "mplexer.hh"
38 #include "statbag.hh"
39 #include "arguments.hh"
40 #include "version.hh"
41 #include "namespaces.hh"
42 using namespace ::boost::multi_index;
43 #include "namespaces.hh"
44
45 namespace po = boost::program_options;
46 po::variables_map g_vm;
47
48 StatBag S;
49 ArgvMap &arg()
50 {
51 static ArgvMap arg;
52 return arg;
53 }
54
55 void usage() {
56 cerr<<"Syntax: pdns_notify IP_ADDRESS[:PORT] DOMAIN"<<endl;
57 }
58
59 int main(int argc, char** argv)
60 try
61 {
62
63 for(int n=1 ; n < argc; ++n) {
64 if ((string) argv[n] == "--help") {
65 usage();
66 return EXIT_SUCCESS;
67 }
68
69 if ((string) argv[n] == "--version") {
70 cerr<<"notify "<<VERSION<<endl;
71 return EXIT_SUCCESS;
72 }
73 }
74
75 if(argc!=3) {
76 usage();
77 exit(1);
78 }
79
80 int sock = socket(AF_INET, SOCK_DGRAM, 0);
81 if(sock < 0)
82 throw runtime_error("Creating socket for incoming packets: "+stringerror());
83
84
85 // ComboAddress local("127.0.0.1", (int)0);
86 // if(::bind(sock, (struct sockaddr*) &local, local.getSocklen()) < 0)
87 // throw runtime_error("Failed to bind local socket to address "+local.toString()+": "+stringerror());
88
89 ComboAddress pdns(argv[1], 53);
90 if(connect(sock, (struct sockaddr*) &pdns, pdns.getSocklen()) < 0)
91 throw runtime_error("Failed to connect PowerDNS socket to address "+pdns.toString()+": "+stringerror());
92
93 vector<uint8_t> outpacket;
94 DNSPacketWriter pw(outpacket, DNSName(argv[2]), QType::SOA, 1, Opcode::Notify);
95 pw.getHeader()->id = random();
96
97
98 if(send(sock, &outpacket[0], outpacket.size(), 0) < 0) {
99 throw runtime_error("Unable to send notify to PowerDNS: "+stringerror());
100 }
101
102 char buffer[1500];
103
104 int len=recv(sock, buffer, sizeof(buffer),0);
105 if(len < 0)
106 throw runtime_error("Unable to receive notification response from PowerDNS: "+stringerror());
107
108 string packet(buffer, len);
109 MOADNSParser mdp(false, packet);
110
111 cerr<<"Received notification response with error: "<<RCode::to_s(mdp.d_header.rcode)<<endl;
112 cerr<<"For: '"<<mdp.d_qname<<"'"<<endl;
113 }
114 catch(std::exception& e)
115 {
116 cerr<<"Fatal: "<<e.what()<<endl;
117 }
118