Browse Source

Changed type of portnumbers to proper one (doesn't seem to do much)

Stefan Schmidt 6 years ago
parent
commit
24f0a343b6
2 changed files with 27 additions and 27 deletions
  1. 10 10
      code_boost/src/cxx/statistics.cpp
  2. 17 17
      code_boost/src/cxx/statistics.h

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

@@ -226,10 +226,10 @@ void statistics::addIntervalStat(std::chrono::duration<int, std::micro> interval
  * @param dport The destination port.
  * @param timestamp The timestamp of the packet.
  */
-void statistics::addConvStat(const IPv4Address ipAddressSender,int sport,const IPv4Address ipAddressReceiver,int dport, std::chrono::microseconds timestamp){
+void statistics::addConvStat(const IPv4Address ipAddressSender, std::uint16_t sport,const IPv4Address ipAddressReceiver, std::uint16_t dport, std::chrono::microseconds timestamp){
 
-    conv f1 = {ipAddressReceiver, dport, ipAddressSender, sport};
-    conv f2 = {ipAddressSender, sport, ipAddressReceiver, dport};
+    conv f1 = {ipAddressReceiver, ipAddressSender, dport, sport};
+    conv f2 = {ipAddressSender, ipAddressReceiver, sport, dport};
 
     // if already exist A(ipAddressReceiver, dport), B(ipAddressSender, sport) conversation
     if (conv_statistics.count(f1)>0){
@@ -259,10 +259,10 @@ void statistics::addConvStat(const IPv4Address ipAddressSender,int sport,const I
  * @param protocol The used protocol.
  * @param timestamp The timestamp of the packet.
  */
-void statistics::addConvStatExt(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport,const std::string &protocol, std::chrono::microseconds timestamp){
+void statistics::addConvStatExt(const IPv4Address ipAddressSender, std::uint16_t sport, const IPv4Address ipAddressReceiver, std::uint16_t dport, const std::string &protocol, std::chrono::microseconds timestamp){
     if(this->getDoExtraTests()) {
-        convWithProt f1 = {ipAddressReceiver, dport, ipAddressSender, sport, protocol};
-        convWithProt f2 = {ipAddressSender, sport, ipAddressReceiver, dport, protocol};
+        convWithProt f1 = {ipAddressReceiver, ipAddressSender, dport, sport, protocol};
+        convWithProt f2 = {ipAddressSender, ipAddressReceiver, sport, dport, protocol};
         convWithProt f;
 
         // if there already exists a communication interval for the specified conversation
@@ -431,8 +431,8 @@ float statistics::getProtocolByteCount(const IPv4Address ipAddress, const std::s
  * @param ipAddressReceiver The IP address of the packet receiver.
  * @param incomingPort The port used by the receiver.
  */
-void statistics::incrementPortCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
-                                    int incomingPort, const std::string &protocol) {
+void statistics::incrementPortCount(const IPv4Address ipAddressSender, std::uint16_t outgoingPort, const IPv4Address ipAddressReceiver,
+                                    std::uint16_t incomingPort, const std::string &protocol) {
     port_values[outgoingPort]++;
     port_values[incomingPort]++;
     ip_ports[{ipAddressSender, "out", outgoingPort, protocol}].count++;
@@ -449,8 +449,8 @@ void statistics::incrementPortCount(const IPv4Address ipAddressSender, int outgo
  * @param incomingPort The port used by the receiver.
  * @param byteSent The packet's size.
  */
-void statistics::increasePortByteCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
-                                       int incomingPort, long bytesSent, const std::string &protocol) {
+void statistics::increasePortByteCount(const IPv4Address ipAddressSender, std::uint16_t outgoingPort, const IPv4Address ipAddressReceiver,
+                                       std::uint16_t incomingPort, long bytesSent, const std::string &protocol) {
     ip_ports[{ipAddressSender, "out", outgoingPort, protocol}].byteCount += bytesSent;
     ip_ports[{ipAddressReceiver, "in", incomingPort, protocol}].byteCount += bytesSent;
 }

+ 17 - 17
code_boost/src/cxx/statistics.h

@@ -51,9 +51,9 @@ struct ip_stats {
  */
 struct conv{
     IPv4Address ipAddressA;
-    int portA;
     IPv4Address ipAddressB;
-    int portB;
+    std::uint16_t portA;
+    std::uint16_t portB;
 
     bool operator==(const conv &other) const {
         return ipAddressA == other.ipAddressA
@@ -73,9 +73,9 @@ struct conv{
  */
 struct convWithProt{
     IPv4Address ipAddressA;
-    int portA;
     IPv4Address ipAddressB;
-    int portB;
+    std::uint16_t portA;
+    std::uint16_t portB;
     std::string protocol;
 
     bool operator==(const convWithProt &other) const {
@@ -303,7 +303,7 @@ struct entry_convStat {
 struct ipAddress_inOut_port {
     IPv4Address ipAddress;
     std::string trafficDirection;
-    int portNumber;
+    std::uint16_t portNumber;
     std::string protocol;
 
     bool operator==(const ipAddress_inOut_port &other) const {
@@ -454,9 +454,9 @@ namespace std {
             using std::hash;
             using std::string;
             return ((hash<uint32_t>()(k.ipAddressA)
-                     ^ (hash<int>()(k.portA) << 1)) >> 1)
+                     ^ (hash<std::uint16_t>()(k.portA) << 1)) >> 1)
                      ^ ((hash<uint32_t>()(k.ipAddressB)
-                     ^ (hash<int>()(k.portB) << 1)) >> 1);
+                     ^ (hash<std::uint16_t>()(k.portB) << 1)) >> 1);
         }
     };
 
@@ -467,9 +467,9 @@ namespace std {
             using std::hash;
             using std::string;
             return ((hash<uint32_t>()(c.ipAddressA)
-                     ^ (hash<int>()(c.portA) << 1)) >> 1)
+                     ^ (hash<std::uint16_t>()(c.portA) << 1)) >> 1)
                      ^ ((hash<uint32_t>()(c.ipAddressB)
-                     ^ (hash<int>()(c.portB) << 1)) >> 1)
+                     ^ (hash<std::uint16_t>()(c.portB) << 1)) >> 1)
                      ^ (hash<string>()(c.protocol));
         }
     };
@@ -493,7 +493,7 @@ namespace std {
             using std::string;
             return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<string>()(k.trafficDirection) << 1)) >> 1)
-                   ^ (hash<int>()(k.portNumber) << 1);
+                   ^ (hash<std::uint16_t>()(k.portNumber) << 1);
         }
     };
 
@@ -533,9 +533,9 @@ public:
 
     void incrementWinCount(const IPv4Address ipAddress, int winSize);
 
-    void addConvStat(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport, std::chrono::microseconds timestamp);
+    void addConvStat(const IPv4Address ipAddressSender, std::uint16_t sport, const IPv4Address ipAddressReceiver, std::uint16_t dport, std::chrono::microseconds timestamp);
 
-    void addConvStatExt(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport, const std::string &protocol, std::chrono::microseconds timestamp);
+    void addConvStatExt(const IPv4Address ipAddressSender, std::uint16_t sport, const IPv4Address ipAddressReceiver, std::uint16_t dport, const std::string &protocol, std::chrono::microseconds timestamp);
 
     void createCommIntervalStats();
 
@@ -562,11 +562,11 @@ public:
     void incrementUnrecognizedPDUCount(const std::string &srcMac, const std::string &dstMac, uint32_t typeNumber,
                                        const std::string &timestamp);
 
-    void incrementPortCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
-                            int incomingPort, const std::string &protocol);
+    void incrementPortCount(const IPv4Address ipAddressSender, std::uint16_t outgoingPort, const IPv4Address ipAddressReceiver,
+                            std::uint16_t incomingPort, const std::string &protocol);
 
-    void increasePortByteCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
-                               int incomingPort, long bytesSent, const std::string &protocol);
+    void increasePortByteCount(const IPv4Address ipAddressSender, std::uint16_t outgoingPort, const IPv4Address ipAddressReceiver,
+                               std::uint16_t incomingPort, long bytesSent, const std::string &protocol);
 
     int getProtocolCount(const IPv4Address ipAddress, const std::string &protocol);
 
@@ -687,7 +687,7 @@ private:
     std::unordered_map<int, int> mss_values;
 
     // {Port, count}
-    std::unordered_map<int, int> port_values;
+    std::unordered_map<std::uint16_t, int> port_values;
 
 
     //{IP Address, contacted IP Addresses}