diff --git a/Examples/HttpAnalyzer/main.cpp b/Examples/HttpAnalyzer/main.cpp index 9e5f8b63e0..125df6a91d 100644 --- a/Examples/HttpAnalyzer/main.cpp +++ b/Examples/HttpAnalyzer/main.cpp @@ -168,8 +168,13 @@ void printMethods(const HttpRequestStats& reqStatscollector) std::vector columnsWidths = {9, 5}; pcpp::TablePrinter printer(columnNames, columnsWidths); + // Copy elements to a vector + std::vector> map2vec(reqStatscollector.methodCount.begin(), reqStatscollector.methodCount.end()); + std::sort(map2vec.begin(), map2vec.end(), + [](const std::pair& left, + const std::pair& right) { return left.first < right.first; }); // go over the method count table and print each method and count - for (auto iter : reqStatscollector.methodCount) + for (auto iter : map2vec) { std::stringstream values; diff --git a/Tests/ExamplesTest/expected_output/httpanalyzer_manyprotocols.txt b/Tests/ExamplesTest/expected_output/httpanalyzer_manyprotocols.txt index cefaa10f86..7e6e47b789 100644 --- a/Tests/ExamplesTest/expected_output/httpanalyzer_manyprotocols.txt +++ b/Tests/ExamplesTest/expected_output/httpanalyzer_manyprotocols.txt @@ -45,8 +45,8 @@ HTTP request methods --------------------- | Method | Count | --------------------- -| POST | 3 | | GET | 150 | +| POST | 3 | --------------------- Hostnames count