summaryrefslogtreecommitdiffstats
path: root/net/base/fixed_host_resolver.cc
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 06:03:31 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 06:03:31 +0000
commit9697c5abfad683112288d367f07bf68d7eb9a05a (patch)
tree9f3568bad2be33a164e6f8f30f49b26e37f28347 /net/base/fixed_host_resolver.cc
parent7ea093ba47c5a1a1652f7249faf56399dd66876f (diff)
downloadchromium_src-9697c5abfad683112288d367f07bf68d7eb9a05a.zip
chromium_src-9697c5abfad683112288d367f07bf68d7eb9a05a.tar.gz
chromium_src-9697c5abfad683112288d367f07bf68d7eb9a05a.tar.bz2
Add a command line flag to force all network traffic through a particular server.
The command line is: --fixed-server=host:port When set, all traffic will be diverted through this server. This is useful for testing purposes with fixed servers. BUG=none TEST=none Review URL: http://codereview.chromium.org/345034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/fixed_host_resolver.cc')
-rw-r--r--net/base/fixed_host_resolver.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/net/base/fixed_host_resolver.cc b/net/base/fixed_host_resolver.cc
new file mode 100644
index 0000000..54e48a9
--- /dev/null
+++ b/net/base/fixed_host_resolver.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/fixed_host_resolver.h"
+
+#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
+#include "net/base/host_resolver_impl.h"
+
+namespace net {
+
+FixedHostResolver::FixedHostResolver(const std::string& host_and_port)
+ : initialized_(false) {
+ std::string host;
+ int port = 0;
+ if (!ParseHostAndPort(host_and_port, &host, &port)) {
+ LOG(ERROR) << "Invalid FixedHostResolver information: " << host_and_port;
+ return;
+ }
+
+ int rv = SystemHostResolverProc(host, net::ADDRESS_FAMILY_UNSPECIFIED,
+ &address_);
+ if (rv != OK) {
+ LOG(ERROR) << "Could not resolve fixed host: " << host;
+ return;
+ }
+
+ if (port <= 0) {
+ LOG(ERROR) << "FixedHostResolver must contain a port number";
+ return;
+ }
+
+ address_.SetPort(port);
+ initialized_ = true;
+}
+
+int FixedHostResolver::Resolve(const RequestInfo& info,
+ AddressList* addresses,
+ CompletionCallback* callback,
+ RequestHandle* out_req,
+ LoadLog* load_log) {
+ if (!initialized_)
+ return ERR_NAME_NOT_RESOLVED;
+
+ DCHECK(addresses);
+ *addresses = address_;
+ return OK;
+}
+
+} // namespace net
+