1 #ifndef SPONGE_LIBSPONGE_UTIL_HH
2 #define SPONGE_LIBSPONGE_UTIL_HH
12 #include <system_error>
43 int SystemCall(
const char *attempt,
const int return_value,
const int errno_mask = 0);
62 void add(std::string_view data);
63 uint16_t
value()
const;
67 void hexdump(
const char *data,
const size_t len,
const size_t indent = 0);
70 void hexdump(
const uint8_t *data,
const size_t len,
const size_t indent = 0);
The internet checksum algorithm.
InternetChecksum(const uint32_t initial_sum=0)
void add(std::string_view data)
std::system_error plus the name of what was being attempted
const char * what() const noexcept override
Returns a C string describing the error.
std::string _attempt_and_error
What was attempted, and what happened.
tagged_error(const std::error_category &category, const std::string &attempt, const int error_code)
Construct from a category, an attempt, and an error code.
a tagged_error for syscalls
unix_error(const std::string &attempt, const int error=errno)
int SystemCall(const char *attempt, const int return_value, const int errno_mask=0)
Error-checking wrapper for most syscalls.
void hexdump(const char *data, const size_t len, const size_t indent=0)
Hexdump the contents of a packet (or any other sequence of bytes)
std::mt19937 get_random_generator()
Seed a fast random generator.
uint64_t timestamp_ms()
Get the time in milliseconds since the program began.