Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
f776d407
Commit
f776d407
authored
Aug 30, 2021
by
Antoine Kaufmann
Browse files
lib/nicbm: use urandom to initialize MAC address
parent
b55b52b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
13 deletions
+8
-13
lib/simbricks/nicbm/nicbm.cc
lib/simbricks/nicbm/nicbm.cc
+8
-13
No files found.
lib/simbricks/nicbm/nicbm.cc
View file @
f776d407
...
...
@@ -24,7 +24,7 @@
#include "lib/simbricks/nicbm/nicbm.h"
#include <
limits
.h>
#include <
fcntl
.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -476,20 +476,15 @@ Runner::Runner(Device &dev) : dev_(dev), events_(EventCmp()) {
// mac_addr = lrand48() & ~(3ULL << 46);
dma_pending_
=
0
;
uint32_t
hnhash
=
time
(
NULL
)
^
getpid
();
char
hostname
[
HOST_NAME_MAX
];
memset
(
hostname
,
0
,
sizeof
(
hostname
));
if
(
gethostname
(
hostname
,
HOST_NAME_MAX
))
{
fprintf
(
stderr
,
"Runner::Runner: warning getting hostname failed
\n
"
);
int
rfd
;
if
((
rfd
=
open
(
"/dev/urandom"
,
O_RDONLY
))
<
0
)
{
perror
(
"Runner::Runner: opening urandom failed"
);
abort
();
}
for
(
size_t
i
=
0
;
i
<
sizeof
(
hostname
)
/
sizeof
(
uint32_t
);
i
++
)
{
hnhash
^=
((
uint32_t
*
)
hostname
)[
i
]
;
if
(
read
(
rfd
,
&
mac_addr_
,
6
)
!=
6
)
{
perror
(
"Runner::Runner: reading urandom failed"
)
;
}
srand48
(
hnhash
);
mac_addr_
=
lrand48
();
mac_addr_
<<=
16
;
mac_addr_
^=
lrand48
();
close
(
rfd
);
mac_addr_
&=
~
3ULL
;
std
::
cerr
<<
std
::
hex
<<
mac_addr_
<<
std
::
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment