tst-ether_aton.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <netinet/ether.h>
  5. static struct tests
  6. {
  7. const char *input;
  8. int valid;
  9. uint8_t result[6];
  10. } tests[] =
  11. {
  12. { "", 0, {0, 0, 0, 0, 0, 0} },
  13. { "AB:CD:EF:01:23:45", 1, {171, 205, 239, 1, 35, 69} },
  14. { "\022B:BB:BB:BB:BB:BB", 0, {0, 0, 0, 0, 0, 0} }
  15. };
  16. int
  17. main (int argc, char *argv[])
  18. {
  19. int result = 0;
  20. size_t cnt;
  21. for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
  22. {
  23. struct ether_addr *addr;
  24. if (!!(addr = ether_aton (tests[cnt].input)) != tests[cnt].valid)
  25. {
  26. if (tests[cnt].valid)
  27. printf ("\"%s\" not seen as valid MAC address\n", tests[cnt].input);
  28. else
  29. printf ("\"%s\" seen as valid MAC address\n", tests[cnt].input);
  30. result = 1;
  31. }
  32. else if (tests[cnt].valid
  33. && memcmp(addr, &tests[cnt].result, sizeof(struct ether_addr)))
  34. {
  35. printf ("\"%s\" not converted correctly\n", tests[cnt].input);
  36. result = 1;
  37. }
  38. }
  39. return result;
  40. }