- Removed the superfluous check for C++17 in the merge since that's
  a requirement enforced at the CMake-level.

* 'getrandom' of https://github.com/MaxKellermann/zeek:
  util: use getrandom() on Linux if available
This commit is contained in:
Jon Siwek 2020-01-28 12:42:25 -08:00
commit 83874fa5fa
3 changed files with 24 additions and 1 deletions

View file

@ -55,6 +55,13 @@
#include "3rdparty/doctest.h"
#ifdef __linux__
#if __has_include(<sys/random.h>)
#define HAVE_GETRANDOM
#include <sys/random.h>
#endif
#endif
TEST_CASE("util extract_ip")
{
CHECK(extract_ip("[1.2.3.4]") == "1.2.3.4");
@ -1035,6 +1042,14 @@ void init_random_seed(const char* read_file, const char* write_file)
seeds_done = true;
}
#ifdef HAVE_GETRANDOM
if ( ! seeds_done )
{
ssize_t nbytes = getrandom(buf, sizeof(buf), 0);
seeds_done = nbytes == ssize_t(sizeof(buf));
}
#endif
if ( ! seeds_done )
{
// Gather up some entropy.