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
3 // found in the LICENSE file.
5 // A binary wrapper for QuicClient. Connects to --hostname via --address
6 // on --port and requests URLs specified on the command line.
9 // quic_client --address=127.0.0.1 --port=6122 --hostname=www.google.com
10 // http://www.google.com/index.html http://www.google.com/favicon.ico
14 #include "base/at_exit.h"
15 #include "base/command_line.h"
16 #include "base/logging.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "net/base/ip_endpoint.h"
19 #include "net/quic/quic_protocol.h"
20 #include "net/tools/quic/quic_client.h"
22 int32 FLAGS_port = 6121;
23 std::string FLAGS_address = "127.0.0.1";
24 std::string FLAGS_hostname = "localhost";
26 int main(int argc, char *argv[]) {
27 CommandLine::Init(argc, argv);
28 CommandLine* line = CommandLine::ForCurrentProcess();
29 if (line->HasSwitch("h") || line->HasSwitch("help")) {
30 const char* help_str =
31 "Usage: quic_client [options]\n"
34 "-h, --help show this help message and exit\n"
35 "--port=<port> specify the port to connect to\n"
36 "--address=<address> specify the IP address to connect to\n"
37 "--host=<host> specify the SNI hostname to use\n";
38 std::cout << help_str;
41 if (line->HasSwitch("port")) {
43 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
47 if (line->HasSwitch("address")) {
48 FLAGS_address = line->GetSwitchValueASCII("address");
50 if (line->HasSwitch("hostname")) {
51 FLAGS_hostname = line->GetSwitchValueASCII("hostname");
53 LOG(INFO) << "server port: " << FLAGS_port
54 << " address: " << FLAGS_address
55 << " hostname: " << FLAGS_hostname;
57 base::AtExitManager exit_manager;
59 net::IPAddressNumber addr;
60 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr));
61 // TODO(rjshade): Set version on command line.
62 net::tools::QuicClient client(
63 net::IPEndPoint(addr, FLAGS_port), FLAGS_hostname,
64 net::QuicSupportedVersions(), true);
68 if (!client.Connect()) return 1;
70 client.SendRequestsAndWaitForResponse(line->GetArgs());