gen_eth_addr.c 747 B

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