2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-22 01:21:45 +00:00

[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>
This commit is contained in:
Hannes Reinecke 2014-06-01 23:26:20 +01:00 committed by Michael Brown
parent 9f0b7f428a
commit d630052e6f
2 changed files with 17 additions and 0 deletions

View File

@ -87,6 +87,7 @@ extern int eth_pull ( struct net_device *netdev, struct io_buffer *iobuf,
const void **ll_dest, const void **ll_source,
uint16_t *net_proto, unsigned int *flags );
extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
extern void eth_random_addr ( void *hw_addr );
extern const char * eth_ntoa ( const void *ll_addr );
extern int eth_mc_hash ( unsigned int af, const void *net_addr,
void *ll_addr );

View File

@ -20,6 +20,7 @@
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <byteswap.h>
@ -112,6 +113,21 @@ void eth_init_addr ( const void *hw_addr, void *ll_addr ) {
memcpy ( ll_addr, hw_addr, ETH_ALEN );
}
/**
* 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
*