blob: 3806d9a4682abfa8e059ea4c42ce8db500e40de0 [file] [log] [blame]
Junxiao Shi3b081542017-07-04 18:37:34 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "program.hpp"
27#include "core/extended-error-message.hpp"
28#include "core/version.hpp"
29#include <unistd.h>
30
31namespace ndn {
32namespace tools {
33namespace autoconfig_server {
34
35static void
36usage(const char* programName)
37{
38 std::cout << "Usage:\n" << programName << " [-h] [-V] [-p prefix] [-p prefix] ... hub-face\n"
39 << " -h - print usage and exit\n"
40 << " -V - print version number and exit\n"
41 << " -p prefix - a local prefix of the HUB\n"
42 << "\n"
43 << " hub-face - a FaceUri to reach the HUB\n"
44 << std::endl;
45}
46
47int
48main(int argc, char** argv)
49{
50 Options options;
51
52 int opt = -1;
53 while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
54 switch (opt) {
55 case 'h':
56 usage(argv[0]);
57 return 0;
58 case 'V':
59 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
60 return 0;
61 case 'p':
62 options.routablePrefixes.emplace_back(::optarg);
63 break;
64 default:
65 usage(argv[0]);
66 return 2;
67 }
68 }
69
70 if (argc != ::optind + 1) {
71 usage(argv[0]);
72 return 2;
73 }
74
75 if (!options.hubFaceUri.parse(argv[::optind])) {
76 std::cerr << "ERROR: cannot parse HUB FaceUri\n";
77 return 2;
78 }
79
80 try {
81 Face face;
82 KeyChain keyChain;
83 Program program(options, face, keyChain);
84 program.run();
85 }
86 catch (const std::exception& e) {
87 std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
88 return 1;
89 }
90 return 0;
91}
92
93} // namespace autoconfig_server
94} // namespace tools
95} // namespace ndn
96
97int
98main(int argc, char** argv)
99{
100 return ndn::tools::autoconfig_server::main(argc, argv);
101}