]>
Commit | Line | Data |
---|---|---|
870a0fe4 AT |
1 | #ifdef HAVE_CONFIG_H |
2 | #include "config.h" | |
3 | #endif | |
e483a610 BH |
4 | #include <bitset> |
5 | #include "dnsparser.hh" | |
6 | #include "iputils.hh" | |
7 | #undef L | |
8 | #include <boost/program_options.hpp> | |
9 | ||
10 | #include <boost/format.hpp> | |
11 | #include <boost/utility.hpp> | |
12 | #include <boost/multi_index_container.hpp> | |
13 | #include <boost/multi_index/ordered_index.hpp> | |
14 | #include <boost/multi_index/key_extractors.hpp> | |
15 | ||
16 | #include "mplexer.hh" | |
d89592cd | 17 | #include "statbag.hh" |
e4bca3a9 | 18 | #include "arguments.hh" |
e483a610 | 19 | |
61b26744 | 20 | #include "namespaces.hh" |
e483a610 | 21 | using namespace ::boost::multi_index; |
10f4eea8 | 22 | #include "namespaces.hh" |
e483a610 BH |
23 | |
24 | namespace po = boost::program_options; | |
25 | po::variables_map g_vm; | |
26 | ||
d89592cd | 27 | StatBag S; |
e4bca3a9 PD |
28 | ArgvMap &arg() |
29 | { | |
30 | static ArgvMap arg; | |
31 | return arg; | |
32 | } | |
e483a610 | 33 | |
d09ce00c | 34 | void usage() { |
a4437033 | 35 | cerr<<"Syntax: pdns_notify IP_ADDRESS[:PORT] DOMAIN"<<endl; |
d09ce00c PL |
36 | } |
37 | ||
e483a610 BH |
38 | int main(int argc, char** argv) |
39 | try | |
40 | { | |
d09ce00c PL |
41 | |
42 | for(int n=1 ; n < argc; ++n) { | |
43 | if ((string) argv[n] == "--help") { | |
44 | usage(); | |
45 | return EXIT_SUCCESS; | |
46 | } | |
47 | ||
48 | if ((string) argv[n] == "--version") { | |
49 | cerr<<"notify "<<VERSION<<endl; | |
50 | return EXIT_SUCCESS; | |
51 | } | |
52 | } | |
53 | ||
d89592cd | 54 | if(argc!=3) { |
d09ce00c | 55 | usage(); |
d89592cd BH |
56 | exit(1); |
57 | } | |
58 | ||
e483a610 BH |
59 | int sock = socket(AF_INET, SOCK_DGRAM, 0); |
60 | if(sock < 0) | |
61 | throw runtime_error("Creating socket for incoming packets: "+stringerror()); | |
62 | ||
d89592cd BH |
63 | |
64 | // ComboAddress local("127.0.0.1", (int)0); | |
65 | // if(::bind(sock, (struct sockaddr*) &local, local.getSocklen()) < 0) | |
66 | // throw runtime_error("Failed to bind local socket to address "+local.toString()+": "+stringerror()); | |
71e063fd BH |
67 | |
68 | ComboAddress pdns(argv[1], 53); | |
e483a610 BH |
69 | if(connect(sock, (struct sockaddr*) &pdns, pdns.getSocklen()) < 0) |
70 | throw runtime_error("Failed to connect PowerDNS socket to address "+pdns.toString()+": "+stringerror()); | |
71 | ||
72 | vector<uint8_t> outpacket; | |
eaedd091 | 73 | DNSPacketWriter pw(outpacket, DNSName(argv[2]), QType::SOA, 1, Opcode::Notify); |
e483a610 BH |
74 | pw.getHeader()->id = random(); |
75 | ||
76 | ||
77 | if(send(sock, &outpacket[0], outpacket.size(), 0) < 0) { | |
78 | throw runtime_error("Unable to send notify to PowerDNS: "+stringerror()); | |
79 | } | |
80 | ||
81 | char buffer[1500]; | |
82 | ||
83 | int len=recv(sock, buffer, sizeof(buffer),0); | |
84 | if(len < 0) | |
85 | throw runtime_error("Unable to receive notification response from PowerDNS: "+stringerror()); | |
86 | ||
87 | string packet(buffer, len); | |
88 | MOADNSParser mdp(packet); | |
89 | ||
bf491f9b | 90 | cerr<<"Received notification response with error: "<<RCode::to_s(mdp.d_header.rcode)<<endl; |
5ab019ac | 91 | cerr<<"For: '"<<mdp.d_qname.toString()<<"'"<<endl; |
e483a610 | 92 | } |
adc10f99 | 93 | catch(std::exception& e) |
e483a610 BH |
94 | { |
95 | cerr<<"Fatal: "<<e.what()<<endl; | |
96 | } | |
97 |