Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: net/tools/dns_fuzz_stub/dns_fuzz_stub.cc

Issue 10538063: Print #EOF when DNS fuzz stub finishes successfully (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initialize id and qtype Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <iostream>
6 #include <string> 7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "base/values.h" 16 #include "base/values.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 LOG(ERROR) << "response[" << i << "] is out of range."; 101 LOG(ERROR) << "response[" << i << "] is out of range.";
101 return false; 102 return false;
102 } 103 }
103 resp_buf->push_back(static_cast<char>(resp_byte_int)); 104 resp_buf->push_back(static_cast<char>(resp_byte_int));
104 } 105 }
105 DCHECK(resp_buf->size() == resp_size); 106 DCHECK(resp_buf->size() == resp_size);
106 107
107 return true; 108 return true;
108 } 109 }
109 110
111 void RunTestCase(uint16 id, std::string& qname, uint16 qtype,
112 std::vector<char>& resp_buf) {
113 net::DnsQuery query(id, qname, qtype);
114 net::DnsResponse response;
115 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data());
116
117 if (!response.InitParse(resp_buf.size(), query)) {
118 LOG(INFO) << "InitParse failed.";
119 return;
120 }
121
122 net::AddressList address_list;
123 base::TimeDelta ttl;
124 net::DnsResponse::Result result = response.ParseToAddressList(
125 &address_list, &ttl);
126 if (result != net::DnsResponse::DNS_SUCCESS) {
127 LOG(INFO) << "ParseToAddressList failed: " << result;
128 return;
129 }
130
131 LOG(INFO) << "Address List:";
132 for (unsigned int i = 0; i < address_list.size(); i++) {
133 LOG(INFO) << "\t" << address_list[i].ToString();
134 }
135 LOG(INFO) << "TTL: " << ttl.InSeconds() << " seconds";
136 }
137
110 } 138 }
111 139
112 int main(int argc, char** argv) { 140 int main(int argc, char** argv) {
113 if (argc != 2) { 141 if (argc != 2) {
114 LOG(ERROR) << "Usage: " << argv[0] << " test_case_filename"; 142 LOG(ERROR) << "Usage: " << argv[0] << " test_case_filename";
115 return 1; 143 return 1;
116 } 144 }
117 145
118 const char* filename = argv[1]; 146 const char* filename = argv[1];
119 147
120 LOG(INFO) << "Test case: " << filename; 148 LOG(INFO) << "Test case: " << filename;
121 149
122 uint16 id; 150 uint16 id = 0;
123 std::string qname_dotted; 151 std::string qname_dotted;
124 uint16 qtype; 152 uint16 qtype = 0;
125 std::vector<char> resp_buf; 153 std::vector<char> resp_buf;
126 154
127 if (!ReadTestCase(filename, &id, &qname_dotted, &qtype, &resp_buf)) { 155 if (!ReadTestCase(filename, &id, &qname_dotted, &qtype, &resp_buf)) {
128 LOG(ERROR) << "Test case format invalid"; 156 LOG(ERROR) << "Test case format invalid";
129 return 2; 157 return 2;
130 } 158 }
131 159
132 LOG(INFO) << "Query: id=" << id 160 LOG(INFO) << "Query: id=" << id
133 << " qname=" << qname_dotted 161 << " qname=" << qname_dotted
134 << " qtype=" << qtype; 162 << " qtype=" << qtype;
135 LOG(INFO) << "Response: " << resp_buf.size() << " bytes"; 163 LOG(INFO) << "Response: " << resp_buf.size() << " bytes";
136 164
137 std::string qname; 165 std::string qname;
138 if (!net::DNSDomainFromDot(qname_dotted, &qname)) { 166 if (!net::DNSDomainFromDot(qname_dotted, &qname)) {
139 LOG(ERROR) << "DNSDomainFromDot(" << qname_dotted << ") failed."; 167 LOG(ERROR) << "DNSDomainFromDot(" << qname_dotted << ") failed.";
140 return 3; 168 return 3;
141 } 169 }
142 170
143 net::DnsQuery query(id, qname, qtype); 171 RunTestCase(id, qname, qtype, resp_buf);
144 net::DnsResponse response;
145 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data());
146 172
147 if (!response.InitParse(resp_buf.size(), query)) { 173 std::cout << "#EOF" << std::endl;
148 LOG(INFO) << "InitParse failed.";
149 return 0;
150 }
151
152 net::AddressList address_list;
153 base::TimeDelta ttl;
154 net::DnsResponse::Result result = response.ParseToAddressList(
155 &address_list, &ttl);
156 if (result != net::DnsResponse::DNS_SUCCESS) {
157 LOG(INFO) << "ParseToAddressList failed: " << result;
158 return 0;
159 }
160
161 LOG(INFO) << "Address List:";
162 for (unsigned int i = 0; i < address_list.size(); i++) {
163 LOG(INFO) << "\t" << address_list[i].ToString();
164 }
165 LOG(INFO) << "TTL: " << ttl.InSeconds() << " seconds";
166 174
167 return 0; 175 return 0;
168 } 176 }
169 177
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698