mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Merge branch 'getrandom' of https://github.com/MaxKellermann/zeek
- 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:
commit
83874fa5fa
3 changed files with 24 additions and 1 deletions
15
src/util.cc
15
src/util.cc
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue