[U-Boot] [PATCH 2/5] net: add helper to generate random mac address
Mike Frysinger
vapier at gentoo.org
Sun Apr 1 21:34:26 CEST 2012
On Saturday 31 March 2012 08:38:33 Michael Walle wrote:
> --- a/include/net.h
> +++ b/include/net.h
>
> in emergency cases, where you need a working network connection to seti
"seti" -> "set"
> + * Eg. you wan't a rescue boot and don't have a serial port to access
"wan't" -> "want"
> +void eth_random_enetaddr(uchar *enetaddr)
> +{
> + uint32_t rval;
> +
> + srand(get_timer(0));
> + rval = rand();
> +
> + enetaddr[0] = 0x02; /* locally administered */
> + enetaddr[1] = 0x00;
> + enetaddr[2] = 0x00;
> + enetaddr[3] = rval & 0xff;
> + enetaddr[4] = (rval >> 8) & 0xff;
> + enetaddr[5] = (rval >> 16) & 0xff;
why only extract 24 of the 32bits ? and if you add a 2nd rand() call, you
could seed all 48bits easily.
then to make sure the first byte is correct, you finish off with:
/* make sure it's local and unicast */
enetaddr[0] = (enetaddr[0] | 0x02) & ~0x01;
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120401/e60aff6d/attachment.pgp>
More information about the U-Boot
mailing list