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