Browse Source

Merge branch 'statistics_code_improvements' of stefan.schmidt/ID2T-toolkit into master

Jens Keim 5 years ago
parent
commit
fede99099c

+ 4 - 4
code_boost/src/cxx/pcap_processor.cpp

@@ -84,7 +84,7 @@ std::string pcap_processor::merge_pcaps(const std::string pcap_path) {
             try {
                 writer.write(*iterator_attack);
             } catch (serialization_error&) {
-                std::cout << std::setprecision(15) << "Could not serialize attack packet with timestamp " << tstmp_attack << std::endl;
+                std::cerr << std::setprecision(15) << "Could not serialize attack packet with timestamp " << tstmp_attack << std::endl;
             }
             iterator_attack++;
             if (iterator_attack == sniffer_attack.end())
@@ -93,7 +93,7 @@ std::string pcap_processor::merge_pcaps(const std::string pcap_path) {
             try {
                 writer.write(*iterator_base);
             } catch (serialization_error&) {
-                    std::cout << "Could not serialize base packet with timestamp " << std::setprecision(15) << tstmp_base << std::endl;
+                    std::cerr << "Could not serialize base packet with timestamp " << std::setprecision(15) << tstmp_base << std::endl;
             }
             iterator_base++;
         }
@@ -106,7 +106,7 @@ std::string pcap_processor::merge_pcaps(const std::string pcap_path) {
             writer.write(*iterator_attack);
         } catch (serialization_error&) {
             auto tstmp_attack = (iterator_attack->timestamp().seconds()) + (iterator_attack->timestamp().microseconds()*1e-6);
-            std::cout << "Could not serialize attack packet with timestamp " << std::setprecision(15) << tstmp_attack << std::endl;
+            std::cerr << "Could not serialize attack packet with timestamp " << std::setprecision(15) << tstmp_attack << std::endl;
         }
     }
     return new_filepath;
@@ -174,7 +174,7 @@ void pcap_processor::collect_statistics() {
         std::chrono::microseconds lastTimestamp = stats.getTimestampLastPacket();
         std::chrono::microseconds captureDuration = lastTimestamp - firstTimestamp;
         if(captureDuration.count()<=0){
-            std::cout << "ERROR: PCAP file is empty!" << std::endl;
+            std::cerr << "ERROR: PCAP file is empty!" << std::endl;
             return;
         }
         long timeInterval_microsec = captureDuration.count() / timeIntervalsNum;

+ 1 - 1
code_boost/src/cxx/statistics.cpp

@@ -779,7 +779,7 @@ void statistics::writeToDatabase(std::string database_path) {
     }
     else {
         // Tinslib failed to recognize the types of the packets in the input PCAP
-        std::cout<<"ERROR: Statistics could not be collected from the input PCAP!"<<"\n";
+        std::cerr<<"ERROR: Statistics could not be collected from the input PCAP!"<<"\n";
         return;
     }
 }

+ 15 - 15
code_boost/src/cxx/statistics_db.cpp

@@ -59,7 +59,7 @@ void statistics_db::writeStatisticsIP(const std::unordered_map<std::string, entr
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -92,7 +92,7 @@ void statistics_db::writeStatisticsDegree(const std::unordered_map<std::string,
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -123,7 +123,7 @@ void statistics_db::writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, i
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -154,7 +154,7 @@ void statistics_db::writeStatisticsMSS(const std::unordered_map<ipAddress_mss, i
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -184,7 +184,7 @@ void statistics_db::writeStatisticsToS(const std::unordered_map<ipAddress_tos, i
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -215,7 +215,7 @@ void statistics_db::writeStatisticsWin(const std::unordered_map<ipAddress_win, i
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -247,7 +247,7 @@ void statistics_db::writeStatisticsProtocols(const std::unordered_map<ipAddress_
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -292,7 +292,7 @@ void statistics_db::writeStatisticsPorts(const std::unordered_map<ipAddress_inOu
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -319,7 +319,7 @@ void statistics_db::writeStatisticsIpMac(const std::unordered_map<std::string, s
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -369,7 +369,7 @@ void statistics_db::writeStatisticsFile(int packetCount, float captureDuration,
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -436,7 +436,7 @@ void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat>
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -530,7 +530,7 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -587,7 +587,7 @@ void statistics_db::writeStatisticsInterval(const std::unordered_map<std::string
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -599,7 +599,7 @@ void statistics_db::writeDbVersion(){
 		transaction.commit();
 	}
 	catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }
 
@@ -731,6 +731,6 @@ void statistics_db::writeStatisticsUnrecognizedPDUs(const std::unordered_map<unr
         transaction.commit();
     }
     catch (std::exception &e) {
-        std::cout << "Exception in statistics_db: " << e.what() << std::endl;
+        std::cerr << "Exception in statistics_db::" << __func__ << ": " << e.what() << std::endl;
     }
 }

+ 1 - 1
code_boost/src/cxx/utilities.cpp

@@ -161,7 +161,7 @@ bool check_tcpChecksum(const std::string &ipAddressSender, const std::string &ip
     try {
         bufferArray_8 = tcpPkt.serialize();
     } catch (serialization_error&) {
-        std::cout << "Error: Could not serialize TCP packet with sender: " << ipAddressSender << ", receiver: "
+        std::cerr << "Error: Could not serialize TCP packet with sender: " << ipAddressSender << ", receiver: "
                   << ipAddressReceiver << ", seq: " << tcpPkt.seq() << std::endl;
         return false;
     }