Skip to content

Commit

Permalink
header: move to a dedicated pcapplusplus folder to follow install hie…
Browse files Browse the repository at this point in the history
…rarchy
  • Loading branch information
clementperon committed Sep 22, 2024
1 parent 7b2599f commit 4f38461
Show file tree
Hide file tree
Showing 309 changed files with 31,825 additions and 852 deletions.
28 changes: 14 additions & 14 deletions Common++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ add_library(
src/TablePrinter.cpp)

set(public_headers
header/DeprecationUtils.h
header/GeneralUtils.h
header/IpAddress.h
header/IpAddressUtils.h
header/IpUtils.h
header/Logger.h
header/LRUList.h
header/MacAddress.h
header/OUILookup.h
header/PcapPlusPlusVersion.h
header/PointerVector.h
header/SystemUtils.h
header/TablePrinter.h
header/TimespecTimeval.h)
header/pcapplusplus/DeprecationUtils.h
header/pcapplusplus/GeneralUtils.h
header/pcapplusplus/IpAddress.h
header/pcapplusplus/IpAddressUtils.h
header/pcapplusplus/IpUtils.h
header/pcapplusplus/Logger.h
header/pcapplusplus/LRUList.h
header/pcapplusplus/MacAddress.h
header/pcapplusplus/OUILookup.h
header/pcapplusplus/PcapPlusPlusVersion.h
header/pcapplusplus/PointerVector.h
header/pcapplusplus/SystemUtils.h
header/pcapplusplus/TablePrinter.h
header/pcapplusplus/TimespecTimeval.h)

# Set the public header that will be installed
set_property(TARGET Common++ PROPERTY PUBLIC_HEADER ${public_headers})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions Common++/header/pcapplusplus/DeprecationUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

/// @file

#ifndef PCPP_DEPRECATED
# if defined(__GNUC__) || defined(__clang__)
# define PCPP_DEPRECATED(msg) __attribute__((deprecated(msg)))
# elif defined(_MSC_VER)
# define PCPP_DEPRECATED(msg) __declspec(deprecated(msg))
# else
# pragma message("WARNING: DEPRECATED feature is not implemented for this compiler")
# define PCPP_DEPRECATED(msg)
# endif
#endif

#if !defined(DISABLE_WARNING_PUSH) || !defined(DISABLE_WARNING_POP)
# if defined(_MSC_VER)
# define DISABLE_WARNING_PUSH __pragma(warning(push))
# define DISABLE_WARNING_POP __pragma(warning(pop))
# define DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber))

# define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(4996)
# elif defined(__GNUC__) || defined(__clang__)
# define DO_PRAGMA(X) _Pragma(#X)
# define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push)
# define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop)
# define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName)

// clang-format off
# define DISABLE_WARNING_DEPRECATED DISABLE_WARNING(-Wdeprecated-declarations)
// clang-format on
# else
# pragma message("WARNING: Disabling of warnings is not implemented for this compiler")
# define DISABLE_WARNING_PUSH
# define DISABLE_WARNING_POP

# define DISABLE_WARNING_DEPRECATED
# endif
#endif
80 changes: 80 additions & 0 deletions Common++/header/pcapplusplus/GeneralUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

#include <string>
#include <stdint.h>
#include <type_traits>

/// @file

/**
* \namespace pcpp
* \brief The main namespace for the PcapPlusPlus lib
*/
namespace pcpp
{
/**
* Convert a byte array into a string of hex characters. For example: for the array { 0xaa, 0x2b, 0x10 } the string
* "aa2b10" will be returned
* @param[in] byteArr A byte array
* @param[in] byteArrSize The size of the byte array [in bytes]
* @param[in] stringSizeLimit An optional parameter that enables to limit the returned string size. If set to a
* positive integer value the returned string size will be equal or less than this value. If the string
* representation of the whole array is longer than this size then only part of the array will be read. The default
* value is -1 which means no string size limitation
* @return A string of hex characters representing the byte array
*/
std::string byteArrayToHexString(const uint8_t* byteArr, size_t byteArrSize, int stringSizeLimit = -1);

/**
* Convert a string of hex characters into a byte array. For example: for the string "aa2b10" an array of values
* { 0xaa, 0x2b, 0x10 } will be returned
* @param[in] hexString A string of hex characters
* @param[out] resultByteArr A pre-allocated byte array where the result will be written to
* @param[in] resultByteArrSize The size of the pre-allocated byte array
* @return The size of the result array. If the string represents an array that is longer than the pre-allocated
* size (resultByteArrSize) then the result array will contain only the part of the string that managed to fit into
* the array, and the returned size will be resultByteArrSize. However if the string represents an array that is
* shorter than the pre-allocated size then some of the cells will remain empty and contain zeros, and the returned
* size will be the part of the array that contain data. If the input is an illegal hex string 0 will be returned.
* Illegal hex string means odd number of characters or a string that contains non-hex characters
*/
size_t hexStringToByteArray(const std::string& hexString, uint8_t* resultByteArr, size_t resultByteArrSize);

/**
* This is a cross platform version of memmem (https://man7.org/linux/man-pages/man3/memmem.3.html) which is not
* supported on all platforms.
* @param[in] haystack A pointer to the buffer to be searched
* @param[in] haystackLen Length of the haystack buffer
* @param[in] needle A pointer to a buffer that will be searched for
* @param[in] needleLen Length of the needle buffer
* @return A pointer to the beginning of the substring, or nullptr if the substring is not found
*/
char* cross_platform_memmem(const char* haystack, size_t haystackLen, const char* needle, size_t needleLen);

/**
* Calculates alignment.
* @param[in] number Given number
* @return The aligned number
*/
template <int alignment> static int align(int number)
{
// Only works for alignment with power of 2
constexpr bool isPowerOfTwo = alignment && ((alignment & (alignment - 1)) == 0);
static_assert(isPowerOfTwo, "Alignment must be a power of 2");
int mask = alignment - 1;
return (number + mask) & ~mask;
}

/**
* A template class to calculate enum class hash
* @tparam EnumClass
*/
template <typename EnumClass, typename std::enable_if<std::is_enum<EnumClass>::value, bool>::type = false>
struct EnumClassHash
{
size_t operator()(EnumClass value) const
{
return static_cast<typename std::underlying_type<EnumClass>::type>(value);
}
};
} // namespace pcpp
Loading

0 comments on commit 4f38461

Please sign in to comment.