blob: 38b4f32d0891cb09ee2cb01adcbef633ab371dda [file] [log] [blame]
Junxiao Shi3b081542017-07-04 18:37:34 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa997d292017-08-24 20:16:59 -04002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi3b081542017-07-04 18:37:34 +00004 * 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"
Junxiao Shi3b081542017-07-04 18:37:34 +000027#include "core/version.hpp"
Davide Pesaventoa997d292017-08-24 20:16:59 -040028
29#include <iostream>
Junxiao Shi3b081542017-07-04 18:37:34 +000030#include <unistd.h>
31
Davide Pesavento97e33022019-02-14 16:00:50 -050032#include <boost/exception/diagnostic_information.hpp>
33
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034namespace ndn::autoconfig_server {
Junxiao Shi3b081542017-07-04 18:37:34 +000035
36static void
37usage(const char* programName)
38{
Davide Pesavento59769b12017-11-12 23:52:06 -050039 std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n"
40 << "\n"
41 << "Options:\n"
Junxiao Shi3b081542017-07-04 18:37:34 +000042 << " -h - print usage and exit\n"
43 << " -V - print version number and exit\n"
Davide Pesavento97e33022019-02-14 16:00:50 -050044 << " -p prefix - a local prefix of the hub\n"
45 << " hub-face - a FaceUri to reach the hub\n";
Junxiao Shi3b081542017-07-04 18:37:34 +000046}
47
Davide Pesavento59769b12017-11-12 23:52:06 -050048static int
Junxiao Shi3b081542017-07-04 18:37:34 +000049main(int argc, char** argv)
50{
51 Options options;
52
53 int opt = -1;
54 while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
55 switch (opt) {
56 case 'h':
57 usage(argv[0]);
58 return 0;
59 case 'V':
60 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
61 return 0;
62 case 'p':
63 options.routablePrefixes.emplace_back(::optarg);
64 break;
65 default:
66 usage(argv[0]);
67 return 2;
68 }
69 }
70
71 if (argc != ::optind + 1) {
72 usage(argv[0]);
73 return 2;
74 }
75
76 if (!options.hubFaceUri.parse(argv[::optind])) {
Davide Pesavento97e33022019-02-14 16:00:50 -050077 std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl;
Junxiao Shi3b081542017-07-04 18:37:34 +000078 return 2;
79 }
80
81 try {
82 Face face;
83 KeyChain keyChain;
84 Program program(options, face, keyChain);
85 program.run();
86 }
87 catch (const std::exception& e) {
Davide Pesavento97e33022019-02-14 16:00:50 -050088 std::cerr << "ERROR: " << boost::diagnostic_information(e);
Junxiao Shi3b081542017-07-04 18:37:34 +000089 return 1;
90 }
91 return 0;
92}
93
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040094} // namespace ndn::autoconfig_server
Junxiao Shi3b081542017-07-04 18:37:34 +000095
96int
97main(int argc, char** argv)
98{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040099 return ndn::autoconfig_server::main(argc, argv);
Junxiao Shi3b081542017-07-04 18:37:34 +0000100}