]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add helper function for generating random MAC addresses with same OUI
authorJouni Malinen <j@w1.fi>
Mon, 29 Sep 2014 20:23:11 +0000 (23:23 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 29 Sep 2014 21:40:23 +0000 (00:40 +0300)
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 <j@w1.fi>
src/utils/common.c
src/utils/common.h

index 78d196e9c2d46ff9a05c5b1ff215ea9d02e8aa5c..9902004917966c1b03d08d818476ce79d041e1fc 100644 (file)
@@ -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;
+}
index 1a191d206411f760b42dcbeb76080c17d7c60818..14d9ad1e9cb044d79cf0732e3dcb90d684caca42 100644 (file)
@@ -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);
 
 
 /*