diff options
author | 2021-03-18 09:00:38 -0600 | |
---|---|---|
committer | 2021-03-18 11:28:01 -0600 | |
commit | 367c27cb023e84226c2b54ef5f594997f8e4d70a (patch) | |
tree | 1e30f2df5c8e5794cde8830191022b7b89f1706a | |
parent | compat: backport to FreeBSD 12.2 (diff) | |
download | wireguard-freebsd-367c27cb023e84226c2b54ef5f594997f8e4d70a.tar.xz wireguard-freebsd-367c27cb023e84226c2b54ef5f594997f8e4d70a.zip |
compat: backport to FreeBSD 12.1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/compat.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h index 649e7dc..6126e26 100644 --- a/src/compat.h +++ b/src/compat.h @@ -67,5 +67,22 @@ static inline void taskqgroup_drain_all(struct taskqgroup *tqg) gtaskqueue_drain_all(q); } } +#endif + +#if __FreeBSD_version < 1202000 +static inline uint32_t arc4random_uniform(uint32_t bound) +{ + uint32_t ret, max_mod_bound; + + if (bound < 2) + return 0; + max_mod_bound = (1 + ~bound) % bound; + + do { + ret = arc4random(); + } while (ret < max_mod_bound); + + return ret % bound; +} #endif |