Sponge
CS144's user-space TCP library
webget.cc
Go to the documentation of this file.
1 #include "socket.hh"
2 #include "util.hh"
3 
4 #include <cstdlib>
5 #include <iostream>
6 
7 using namespace std;
8 
9 void get_URL(const string &host, const string &path) {
10  // Your code here.
11 
12  // You will need to connect to the "http" service on
13  // the computer whose name is in the "host" string,
14  // then request the URL path given in the "path" string.
15 
16  // Then you'll need to print out everything the server sends back,
17  // (not just one call to read() -- everything) until you reach
18  // the "eof" (end of file).
19 
20  cerr << "Function called: get_URL(" << host << ", " << path << ").\n";
21  cerr << "Warning: get_URL() has not been implemented yet.\n";
22 }
23 
24 int main(int argc, char *argv[]) {
25  try {
26  if (argc <= 0) {
27  abort(); // For sticklers: don't try to access argv[0] if argc <= 0.
28  }
29 
30  // The program takes two command-line arguments: the hostname and "path" part of the URL.
31  // Print the usage message unless there are these two arguments (plus the program name
32  // itself, so arg count = 3 in total).
33  if (argc != 3) {
34  cerr << "Usage: " << argv[0] << " HOST PATH\n";
35  cerr << "\tExample: " << argv[0] << " stanford.edu /class/cs144\n";
36  return EXIT_FAILURE;
37  }
38 
39  // Get the command-line arguments.
40  const string host = argv[1];
41  const string path = argv[2];
42 
43  // Call the student-written function.
44  get_URL(host, path);
45  } catch (const exception &e) {
46  cerr << e.what() << "\n";
47  return EXIT_FAILURE;
48  }
49 
50  return EXIT_SUCCESS;
51 }
socket.hh
util.hh
std::exception
get_URL
void get_URL(const string &host, const string &path)
Definition: webget.cc:9
std::cerr
std
std::abort
T abort(T... args)
std::exception::what
T what(T... args)
main
int main(int argc, char *argv[])
Definition: webget.cc:24