Commit f776d407 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

lib/nicbm: use urandom to initialize MAC address

parent b55b52b5
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "lib/simbricks/nicbm/nicbm.h" #include "lib/simbricks/nicbm/nicbm.h"
#include <limits.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -476,20 +476,15 @@ Runner::Runner(Device &dev) : dev_(dev), events_(EventCmp()) { ...@@ -476,20 +476,15 @@ Runner::Runner(Device &dev) : dev_(dev), events_(EventCmp()) {
// mac_addr = lrand48() & ~(3ULL << 46); // mac_addr = lrand48() & ~(3ULL << 46);
dma_pending_ = 0; dma_pending_ = 0;
uint32_t hnhash = time(NULL) ^ getpid(); int rfd;
char hostname[HOST_NAME_MAX]; if ((rfd = open("/dev/urandom", O_RDONLY)) < 0) {
memset(hostname, 0, sizeof(hostname)); perror("Runner::Runner: opening urandom failed");
if (gethostname(hostname, HOST_NAME_MAX)) { abort();
fprintf(stderr, "Runner::Runner: warning getting hostname failed\n");
} }
for (size_t i = 0; i < sizeof(hostname) / sizeof(uint32_t); i++) { if (read(rfd, &mac_addr_, 6) != 6) {
hnhash ^= ((uint32_t *) hostname)[i]; perror("Runner::Runner: reading urandom failed");
} }
srand48(hnhash); close(rfd);
mac_addr_ = lrand48();
mac_addr_ <<= 16;
mac_addr_ ^= lrand48();
mac_addr_ &= ~3ULL; mac_addr_ &= ~3ULL;
std::cerr << std::hex << mac_addr_ << std::endl; std::cerr << std::hex << mac_addr_ << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment