diff options
author | Hannes Reinecke <hare@suse.de> | 2014-06-01 23:26:20 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2014-06-01 23:32:24 +0100 |
commit | d630052e6f44ce215503fb7f20819a1382ebfa9b (patch) | |
tree | bcf5bd83950e145011e05dd76634181e4480c6cc /src/net | |
parent | 9f0b7f428af04d0c5ddda78f9b034625f2f91831 (diff) | |
download | ipxe-d630052e6f44ce215503fb7f20819a1382ebfa9b.zip ipxe-d630052e6f44ce215503fb7f20819a1382ebfa9b.tar.gz ipxe-d630052e6f44ce215503fb7f20819a1382ebfa9b.tar.bz2 |
[ethernet] Provide eth_random_addr() to generate random Ethernet addresses
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ethernet.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/net/ethernet.c b/src/net/ethernet.c index a2e5658..03978c2 100644 --- a/src/net/ethernet.c +++ b/src/net/ethernet.c @@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> +#include <stdlib.h> #include <stdio.h> #include <string.h> #include <byteswap.h> @@ -113,6 +114,21 @@ void eth_init_addr ( const void *hw_addr, void *ll_addr ) { } /** + * Generate random Ethernet address + * + * @v hw_addr Generated hardware address + */ +void eth_random_addr ( void *hw_addr ) { + uint8_t *addr = hw_addr; + unsigned int i; + + for ( i = 0 ; i < ETH_ALEN ; i++ ) + addr[i] = random(); + addr[0] &= ~0x01; /* Clear multicast bit */ + addr[0] |= 0x02; /* Set locally-assigned bit */ +} + +/** * Transcribe Ethernet address * * @v ll_addr Link-layer address |