]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dumresp.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.
33 std::atomic
<uint64_t>* g_counter
;
37 auto prev
= g_counter
->load();
40 cout
<<g_counter
->load()-prev
<<"\t"<<g_counter
->load()<<endl
;
41 prev
=g_counter
->load();
46 cerr
<<"Syntax: dumresp LOCAL-ADDRESS LOCAL-PORT NUMBER-OF-PROCESSES"<<endl
;
49 int main(int argc
, char** argv
)
52 for(int i
= 1; i
< argc
; i
++) {
53 if((string
) argv
[i
] == "--help"){
58 if((string
) argv
[i
] == "--version"){
59 cerr
<<"dumresp "<<VERSION
<<endl
;
69 auto ptr
= mmap(NULL
, sizeof(std::atomic
<uint64_t>), PROT_READ
| PROT_WRITE
,
70 MAP_SHARED
| MAP_ANONYMOUS
, -1, 0);
72 g_counter
= new(ptr
) std::atomic
<uint64_t>();
75 for(; i
< atoi(argv
[3]); ++i
) {
80 std::thread
t(printStatus
);
84 ComboAddress
local(argv
[1], atoi(argv
[2]));
85 Socket
s(local
.sin4
.sin_family
, SOCK_DGRAM
);
88 if(setsockopt(s
.getHandle(), SOL_SOCKET
, SO_REUSEPORT
, &one
, sizeof(one
)) < 0)
89 unixDie("setsockopt for REUSEPORT");
93 cout
<<"Bound to "<<local
.toStringWithPort()<<endl
;
95 struct dnsheader
* dh
= (struct dnsheader
*)buffer
;
97 ComboAddress rem
=local
;
98 socklen_t socklen
= rem
.getSocklen();
100 len
=recvfrom(s
.getHandle(), buffer
, sizeof(buffer
), 0, (struct sockaddr
*)&rem
, &socklen
);
109 if(sendto(s
.getHandle(), buffer
, len
, 0, (struct sockaddr
*)&rem
, socklen
) < 0)
114 catch(std::exception
& e
)
116 cerr
<<"Fatal error: "<<e
.what()<<endl
;