gen_eth_addr.c 744 B

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