]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/kvresp.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
29 /* This tool REALLY wants to be rewritten in Python, by ahu does not speak it very well.
30 What it does is provide answers to queries from the Lua generic UDP Question/Answer
31 stuff in kv-example-script.lua */
35 int main(int argc
, char** argv
)
39 cerr
<<"Syntax: kvresp local-address local-port"<<endl
;
43 ComboAddress
local(argv
[1], atoi(argv
[2]));
44 Socket
s(local
.sin4
.sin_family
, SOCK_DGRAM
);
47 cout
<<"Bound to "<<local
.toStringWithPort()<<endl
;
52 ComboAddress rem
=local
;
53 socklen_t socklen
= rem
.getSocklen();
55 len
=recvfrom(s
.getHandle(), buffer
, sizeof(buffer
), 0, (struct sockaddr
*)&rem
, &socklen
);
58 string
query(buffer
, len
);
59 cout
<<"Had packet: "<<query
<<endl
;
61 stringtok(parts
, query
);
65 if(parts
[0]=="DOMAIN")
66 response
= (parts
[1].find("xxx") != string::npos
) ? "1" : "0";
67 else if(parts
[0]=="IP")
68 response
= (parts
[1]=="127.0.0.1") ? "1" : "0";
72 cout
<<"Our reply: "<<response
<<endl
;
73 if(sendto(s
.getHandle(), response
.c_str(), response
.length(), 0, (struct sockaddr
*)&rem
, socklen
) < 0)
77 catch(std::exception
& e
)
79 cerr
<<"Fatal error: "<<e
.what()<<endl
;