From 1cbdb9d13754e1476620f5a3938b726270821adb Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 29 Sep 2014 23:23:11 +0300 Subject: [PATCH] Add helper function for generating random MAC addresses with same OUI random_mac_addr_keep_oui() is similar to random_mac_addr(), but it maintains the OUI part of the source address. Signed-off-by: Jouni Malinen --- src/utils/common.c | 10 ++++++++++ src/utils/common.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/utils/common.c b/src/utils/common.c index 78d196e9c..990200491 100644 --- a/src/utils/common.c +++ b/src/utils/common.c @@ -856,3 +856,13 @@ int random_mac_addr(u8 *addr) addr[0] |= 0x02; /* locally administered */ return 0; } + + +int random_mac_addr_keep_oui(u8 *addr) +{ + if (os_get_random(addr + 3, 3) < 0) + return -1; + addr[0] &= 0xfe; /* unicast */ + addr[0] |= 0x02; /* locally administered */ + return 0; +} diff --git a/src/utils/common.h b/src/utils/common.h index 1a191d206..14d9ad1e9 100644 --- a/src/utils/common.h +++ b/src/utils/common.h @@ -539,6 +539,7 @@ void str_clear_free(char *str); void bin_clear_free(void *bin, size_t len); int random_mac_addr(u8 *addr); +int random_mac_addr_keep_oui(u8 *addr); /*