59
65
connect(d_socket, (struct sockaddr*)&remote, remote.getSocklen());
60
66
d_oks = d_errors = d_nodatas = d_nxdomains = d_unknowns = 0;
61
67
d_receiveds = d_receiveerrors = d_senderrors = 0;
62
for(unsigned int id =0 ; id < numeric_limits<uint16_t>::max(); ++id)
68
for(unsigned int id =0 ; id < std::numeric_limits<uint16_t>::max(); ++id)
63
69
d_idqueue.push_back(id);
108
114
// parse packet, set 'id', fill out 'ip'
110
116
MOADNSParser mdp(string(buf, len));
111
cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
112
cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
113
cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
118
cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
119
cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
120
cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
114
122
dr.rcode = mdp.d_header.rcode;
115
123
for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {
116
124
if(i->first.d_place == 1 && i->first.d_type == QType::A)
118
126
if(i->first.d_place == 2 && i->first.d_type == QType::SOA) {
119
127
dr.seenauthsoa = 1;
121
cout<<i->first.d_place-1<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
122
cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.d_content->getZoneRepresentation()<<"\n";
131
cout<<i->first.d_place-1<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
132
cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.d_content->getZoneRepresentation()<<"\n";
125
136
id = mdp.d_header.id;
140
151
(*d_acc)(usec/1000.0);
141
152
// if(usec > 1000000)
142
153
// cerr<<"Slow: "<<domain<<" ("<<usec/1000.0<<" msec)\n";
143
cout<<domain<<": ("<<usec/1000.0<<"msec) rcode: "<<dr.rcode;
144
BOOST_FOREACH(const ComboAddress& ca, dr.ips) {
145
cout<<", "<<ca.toString();
155
cout<<domain<<": ("<<usec/1000.0<<"msec) rcode: "<<dr.rcode;
156
BOOST_FOREACH(const ComboAddress& ca, dr.ips) {
157
cout<<", "<<ca.toString();
148
161
if(dr.rcode == RCode::NXDomain) {
170
182
int main(int argc, char** argv)
172
if(argc != 3 && argc != 4) {
173
cerr<<"Syntax: dnsbulktest ip-address port number [limit] < top-1m.csv"<<endl;
176
SendReceive sr(argv[1], atoi(argv[2]));
177
unsigned int limit = 0;
179
limit = atoi(argv[3]);
184
po::options_description desc("Allowed options");
186
("help,h", "produce help message")
187
("quiet,q", "be quiet about individual queries")
188
("envoutput,e", "write report in shell environment format")
191
po::options_description alloptions;
192
po::options_description hidden("hidden options");
194
("ip-address", po::value<string>(), "ip-address")
195
("portnumber", po::value<uint16_t>(), "portnumber")
196
("limit", po::value<uint32_t>()->default_value(0), "limit");
198
alloptions.add(desc).add(hidden);
199
po::positional_options_description p;
200
p.add("ip-address", 1);
201
p.add("portnumber", 1);
204
po::store(po::command_line_parser(argc, argv).options(alloptions).positional(p).run(), g_vm);
207
if (g_vm.count("help")) {
208
cerr << "Usage: dnsbulktest [--options] ip-address portnumber [limit]"<<endl;
209
cerr << desc << "\n";
213
if(!g_vm.count("portnumber")) {
214
cerr<<"Fatal, need to specify ip-address and portnumber"<<endl;
215
cerr << "Usage: dnsbulktest [--options] ip-address portnumber [limit]"<<endl;
216
cerr << desc << "\n";
220
g_quiet = g_vm.count("quiet")>0;
221
g_envoutput = g_vm.count("envoutput")>0;
223
SendReceive sr(g_vm["ip-address"].as<string>(), g_vm["portnumber"].as<uint16_t>());
224
unsigned int limit = g_vm["limit"].as<unsigned int>();
181
226
reportAllTypes();
182
227
vector<string> domains;
189
234
pair<string, string> split;
235
string::size_type pos;
190
236
while(stringfgets(stdin, line)) {
191
237
if(limit && domains.size() >= limit)
194
240
trim_right(line);
195
241
split=splitField(line,',');
242
pos=split.second.find('/');
243
if(pos != string::npos) // alexa has whole urls in the list now..
244
split.second.resize(pos);
245
if(find_if(split.second.begin(), split.second.end(), isalpha) == split.second.end())
247
continue; // this was an IP address
196
249
domains.push_back(split.second);
197
250
domains.push_back("www."+split.second);
239
292
cerr << statfmt % extended_p_square(*sr.d_acc)[i] % (100*sr.d_probs[i]);
296
cout<<"DBT_QUEUED="<<domains.size()<<endl;
297
cout<<"DBT_SENDERRORS="<<sr.d_senderrors<<endl;
298
cout<<"DBT_RECEIVED="<<sr.d_receiveds<<endl;
299
cout<<"DBT_TIMEOUTS="<<inflighter.getTimeouts()<<endl;
300
cout<<"DBT_UNEXPECTEDS="<<inflighter.getUnexpecteds()<<endl;
301
cout<<"DBT_OKPERCENTAGE="<<((float)sr.d_oks/domains.size()*100)<<endl;
302
cout<<"DBT_OKPERCENTAGEINT="<<(int)((float)sr.d_oks/domains.size()*100)<<endl;