xref: /openbmc/u-boot/tools/gen_eth_addr.c (revision 1d2c0506)
1 /*
2  * (C) Copyright 2001
3  * Murray Jensen <Murray.Jensen@cmst.csiro.au>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <time.h>
12 
13 int
14 main(int argc, char *argv[])
15 {
16     unsigned long ethaddr_low, ethaddr_high;
17 
18     srand(time(0) + (getpid() << 8));
19 
20     /*
21      * setting the 2nd LSB in the most significant byte of
22      * the address makes it a locally administered ethernet
23      * address
24      */
25     ethaddr_high = (rand() & 0xfeff) | 0x0200;
26     ethaddr_low = rand();
27 
28     printf("%02lx:%02lx:%02lx:%02lx:%02lx:%02lx\n",
29 	ethaddr_high >> 8, ethaddr_high & 0xff,
30 	ethaddr_low >> 24, (ethaddr_low >> 16) & 0xff,
31 	(ethaddr_low >> 8) & 0xff, ethaddr_low & 0xff);
32 
33     return (0);
34 }
35