Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Modernizing filters to Cpp11. #1323

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Pcap++/header/PcapFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace pcpp
* @param[out] result An empty string that the parsing will be written into. If the string isn't empty, its content will be overridden
* If the filter is not valid the result will be an empty string
*/
virtual void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Verify the filter is valid
Expand Down Expand Up @@ -279,7 +279,7 @@ namespace pcpp
*/
IPFilter(const std::string& ipAddress, Direction dir, int len) : IFilterWithDirection(dir), m_Address(ipAddress), m_IPv4Mask(""), m_Len(len) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the IPv4 address
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace pcpp
*/
IPv4IDFilter(uint16_t ipID, FilterOperator op) : IFilterWithOperator(op), m_IpID(ipID) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the IP ID to filter
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace pcpp
*/
IPv4TotalLengthFilter(uint16_t totalLength, FilterOperator op) : IFilterWithOperator(op), m_TotalLength(totalLength) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the total length value
Expand Down Expand Up @@ -379,7 +379,7 @@ namespace pcpp
*/
PortFilter(uint16_t port, Direction dir);

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the port
Expand Down Expand Up @@ -410,7 +410,7 @@ namespace pcpp
*/
PortRangeFilter(uint16_t fromPort, uint16_t toPort, Direction dir) : IFilterWithDirection(dir), m_FromPort(fromPort), m_ToPort(toPort) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the lower end of the port range
Expand Down Expand Up @@ -444,7 +444,7 @@ namespace pcpp
*/
MacAddressFilter(MacAddress address, Direction dir) : IFilterWithDirection(dir), m_MacAddress(address) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the MAC address
Expand Down Expand Up @@ -472,7 +472,7 @@ namespace pcpp
*/
explicit EtherTypeFilter(uint16_t etherType) : m_EtherType(etherType) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the EtherType value
Expand Down Expand Up @@ -610,7 +610,7 @@ namespace pcpp
*/
explicit NotFilter(GeneralFilter* filterToInverse) { m_FilterToInverse = filterToInverse; }

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set a filter to create an inverse filter from
Expand Down Expand Up @@ -649,7 +649,7 @@ namespace pcpp
*/
explicit ProtoFilter(ProtocolTypeFamily protoFamily) : m_ProtoFamily(protoFamily) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the protocol to filter with
Expand Down Expand Up @@ -685,7 +685,7 @@ namespace pcpp
*/
explicit ArpFilter(ArpOpcode opCode) : m_OpCode(opCode) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the ARP opcode
Expand Down Expand Up @@ -713,7 +713,7 @@ namespace pcpp
*/
explicit VlanFilter(uint16_t vlanId) : m_VlanID(vlanId) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set the VLAN ID of the filter
Expand Down Expand Up @@ -783,7 +783,7 @@ namespace pcpp
*/
void setTcpFlagsBitMask(uint8_t tcpFlagBitMask, MatchOptions matchOption) { m_TcpFlagsBitMask = tcpFlagBitMask; m_MatchOption = matchOption; }

void parseToString(std::string& result);
void parseToString(std::string& result) override;
};


Expand All @@ -806,7 +806,7 @@ namespace pcpp
*/
TcpWindowSizeFilter(uint16_t windowSize, FilterOperator op) : IFilterWithOperator(op), m_WindowSize(windowSize) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set window-size value
Expand Down Expand Up @@ -835,7 +835,7 @@ namespace pcpp
*/
UdpLengthFilter(uint16_t length, FilterOperator op) : IFilterWithOperator(op), m_Length(length) {}

void parseToString(std::string& result);
void parseToString(std::string& result) override;

/**
* Set length value
Expand Down
8 changes: 4 additions & 4 deletions Pcap++/src/PcapFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void IPFilter::convertToIPAddressWithLen(std::string& ipAddrmodified) const
if (ipAddr.getType() == IPAddress::IPv4AddressType)
{
uint32_t addrAsInt = ipAddr.getIPv4().toInt();
uint32_t mask = ((uint32_t) - 1) >> ((sizeof(uint32_t) * 8) - m_Len);
uint32_t mask = static_cast<uint32_t>(-1) >> ((sizeof(uint32_t) * 8) - m_Len);
addrAsInt &= mask;
ipAddrmodified = IPv4Address(addrAsInt).toString();
}
Expand Down Expand Up @@ -271,9 +271,9 @@ void PortRangeFilter::parseToString(std::string& result)
parseDirection(dir);

std::ostringstream fromPortStream;
fromPortStream << (int)m_FromPort;
fromPortStream << static_cast<int>(m_FromPort);
std::ostringstream toPortStream;
toPortStream << (int)m_ToPort;
toPortStream << static_cast<int>(m_ToPort);

result = dir + " portrange " + fromPortStream.str() + '-' + toPortStream.str();
}
Expand Down Expand Up @@ -410,7 +410,7 @@ void TcpFlagsFilter::parseToString(std::string& result)
else //m_MatchOption == MatchAll
{
std::ostringstream stream;
stream << (int)m_TcpFlagsBitMask;
stream << static_cast<int>(m_TcpFlagsBitMask);
result += " = " + stream.str();
}
}
Expand Down
Loading