From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Sun, 1 Apr 2012 15:34:26 -0400 Subject: [U-Boot] [PATCH 2/5] net: add helper to generate random mac address In-Reply-To: <1333197516-5138-3-git-send-email-michael@walle.cc> References: <1333197516-5138-1-git-send-email-michael@walle.cc> <1333197516-5138-3-git-send-email-michael@walle.cc> Message-ID: <201204011534.27331.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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: