mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-01 06:45:27 +00:00
Mixed with srandomdev() BSD code
This commit is contained in:
committed by
Thomas Markwalder
parent
eece3e17eb
commit
46de3dfd99
@@ -3,7 +3,7 @@
|
|||||||
DHCP Client. */
|
DHCP Client. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-2020 by Internet Systems Consortium, Inc. ("ISC")
|
* Copyright (c) 2004-2022 by Internet Systems Consortium, Inc. ("ISC")
|
||||||
* Copyright (c) 1995-2003 by Internet Software Consortium
|
* Copyright (c) 1995-2003 by Internet Software Consortium
|
||||||
*
|
*
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
@@ -829,21 +829,36 @@ main(int argc, char **argv) {
|
|||||||
? DISCOVER_REQUESTED
|
? DISCOVER_REQUESTED
|
||||||
: DISCOVER_RUNNING);
|
: DISCOVER_RUNNING);
|
||||||
|
|
||||||
/* Make up a seed for the random number generator from current
|
/* PLEASE PREFER the random device: not all systems use random
|
||||||
time plus the sum of the last four bytes of each
|
* process identifiers so the alternative can be predictable. */
|
||||||
interface's hardware address interpreted as an integer.
|
|
||||||
Not much entropy, but we're booting, so we're not likely to
|
|
||||||
find anything better. */
|
|
||||||
seed = 0;
|
seed = 0;
|
||||||
for (ip = interfaces; ip; ip = ip->next) {
|
size_t nrnd = 0;
|
||||||
int junk;
|
#ifdef ISC_PATH_RANDOMDEV
|
||||||
memcpy(&junk,
|
FILE *frnd = fopen(ISC_PATH_RANDOMDEV, "r");
|
||||||
&ip->hw_address.hbuf[ip->hw_address.hlen -
|
if (frnd) {
|
||||||
sizeof seed], sizeof seed);
|
nrnd = fread(&seed, sizeof(seed), 1, frnd);
|
||||||
seed += junk;
|
fclose(frnd);
|
||||||
}
|
}
|
||||||
srandom(seed + cur_time + (unsigned)getpid());
|
#endif
|
||||||
|
/* Please leave the compiler to emit a warning about a constant
|
||||||
|
* condition in the if test. */
|
||||||
|
if (!nrnd) {
|
||||||
|
/* Make up a seed for the random number generator from current
|
||||||
|
time plus the sum of the last four bytes of each
|
||||||
|
interface's hardware address interpreted as an integer.
|
||||||
|
Not much entropy, but we're booting, so we're not likely to
|
||||||
|
find anything better. */
|
||||||
|
|
||||||
|
for (ip = interfaces; ip; ip = ip->next) {
|
||||||
|
int junk;
|
||||||
|
memcpy(&junk,
|
||||||
|
&ip->hw_address.hbuf[ip->hw_address.hlen -
|
||||||
|
sizeof seed], sizeof seed);
|
||||||
|
seed += junk;
|
||||||
|
}
|
||||||
|
seed += cur_time + (unsigned)getpid();
|
||||||
|
}
|
||||||
|
srandom(seed);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Establish a default DUID. We always do so for v6 and
|
* Establish a default DUID. We always do so for v6 and
|
||||||
|
Reference in New Issue
Block a user