Add helper function for generating random MAC addresses

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-09-27 19:12:02 +03:00
parent fee354c74d
commit 4d8fb63799
2 changed files with 12 additions and 0 deletions

View file

@ -846,3 +846,13 @@ void bin_clear_free(void *bin, size_t len)
os_free(bin);
}
}
int random_mac_addr(u8 *addr)
{
if (os_get_random(addr, ETH_ALEN) < 0)
return -1;
addr[0] &= 0xfe; /* unicast */
addr[0] |= 0x02; /* locally administered */
return 0;
}

View file

@ -538,6 +538,8 @@ void int_array_add_unique(int **res, int a);
void str_clear_free(char *str);
void bin_clear_free(void *bin, size_t len);
int random_mac_addr(u8 *addr);
/*
* gcc 4.4 ends up generating strict-aliasing warnings about some very common