1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (C) 2012-2021 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <perfdhcp/avalanche_scen.h>
#include <perfdhcp/basic_scen.h>
#include <perfdhcp/command_options.h>

#include <exceptions/exceptions.h>

#include <iostream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <stdint.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc::perfdhcp;

int
main(int argc, char* argv[]) {
    int ret_code = 0;
    std::string diags;
    bool parser_error = true;
    try {
        CommandOptions command_options;
        diags = command_options.getDiags();
        // If parser returns true it means that user specified
        // 'h' or 'v' command line option. Program shows the
        // help or version message and exits here.
        // The third argument indicates that the command line
        // should be printed when it gets parsed. This is useful
        // in particular when the command line needs to be
        // extracted from the log file.
        if (command_options.parse(argc, argv, true)) {
            return (ret_code);
        }
        parser_error = false;
        auto scenario = command_options.getScenario();
        PerfSocket socket(command_options);
        if (scenario == Scenario::BASIC) {
            BasicScen scen(command_options, socket);
            ret_code = scen.run();
        } else if (scenario == Scenario::AVALANCHE) {
            AvalancheScen scen(command_options, socket);
            ret_code = scen.run();
        }
    } catch (const std::exception& e) {
        ret_code = 1;
        if (!parser_error) {
            std::cerr << std::endl << "ERROR: running perfdhcp: "
                      << e.what() << std::endl;
        } else {
            CommandOptions::usage();
            std::cerr << std::endl << "ERROR: parsing command line options: "
                      << e.what() << std::endl;
        }
        if (diags.find('e') != std::string::npos) {
            std::cerr << "Fatal error" << std::endl;
        }
    } catch (...) {
        ret_code = 1;
        if (!parser_error) {
            std::cerr << std::endl << "ERROR: running perfdhcp"
                      << std::endl;
        } else {
            CommandOptions::usage();
            std::cerr << std::endl << "ERROR: parsing command line options"
                      << std::endl;
        }
        if (diags.find('e') != std::string::npos) {
            std::cerr << "Fatal error" << std::endl;
        }
    }
    return (ret_code);
}