summaryrefslogtreecommitdiff
path: root/staging/tools.c
diff options
context:
space:
mode:
authorMatteo Croce <mcroce@redhat.com>2018-08-21 16:38:09 +0200
committerTobias Klauser <tklauser@distanz.ch>2018-08-22 10:21:37 +0200
commitc7c176394ad2b87f56b0aed2731eb9dde29750f0 (patch)
tree1c423f98bc7ac52feb134044efeed38ccc6d0507 /staging/tools.c
parent01f339a7bb170310f9dd6a389d9c89b6c62032d0 (diff)
mausezahn: improve random mac address generation
Modify -b option to generate all random MAC addresses. Improve the random generation algorithm, use nrand48() which fills the ethernet address in two calls instead of six calls to rand() and six floating point calculations. Set the locally administered bit of generated MAC addresses. Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'staging/tools.c')
-rw-r--r--staging/tools.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/staging/tools.c b/staging/tools.c
index 72445b6..f7c4131 100644
--- a/staging/tools.c
+++ b/staging/tools.c
@@ -687,15 +687,9 @@ int check_eth_mac_txt(int src_or_dst)
// Okay, lets check the commandline argument:
//
// Do you want a random MAC?
- // TODO: Consider enforcement of unicast addresses
if (strncmp(eth_mac_txt, "rand", 4)==0)
{
- eth_mac[0] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
- eth_mac[1] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
- eth_mac[2] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
- eth_mac[3] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
- eth_mac[4] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
- eth_mac[5] = (u_int8_t) ( ((float) rand()/RAND_MAX)*256);
+ rand_addr(eth_mac);
*eth_rand = 1;
}
// Do you want your own interface MAC?