tst-ether_aton.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <netinet/ether.h>
  4. static int
  5. do_test (void)
  6. {
  7. struct ether_addr *valp, val;
  8. int result, r;
  9. char hostname[32], buf[64], *p;
  10. valp = ether_aton ("12:34:56:78:9a:bc");
  11. printf ("ether_aton (\"12:34:56:78:9a:bc\") = %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n",
  12. valp->ether_addr_octet[0],
  13. valp->ether_addr_octet[1],
  14. valp->ether_addr_octet[2],
  15. valp->ether_addr_octet[3],
  16. valp->ether_addr_octet[4],
  17. valp->ether_addr_octet[5]);
  18. result = (valp->ether_addr_octet[0] != 0x12
  19. || valp->ether_addr_octet[1] != 0x34
  20. || valp->ether_addr_octet[2] != 0x56
  21. || valp->ether_addr_octet[3] != 0x78
  22. || valp->ether_addr_octet[4] != 0x9a
  23. || valp->ether_addr_octet[5] != 0xbc);
  24. if ((r = ether_line ("0:c0:f0:46:5f:97 host.ether.com \t# comment",
  25. &val, hostname)) == 0)
  26. {
  27. ether_ntoa_r (&val, buf);
  28. p = strchr (buf, '\0');
  29. *p++ = ' ';
  30. strcpy (p, hostname);
  31. printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = \"%s\"\n",
  32. buf);
  33. result |= strcmp ("0:c0:f0:46:5f:97 host.ether.com", buf) != 0;
  34. }
  35. else
  36. {
  37. printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = %d\n", r);
  38. result |= 1;
  39. }
  40. r = ether_line ("0:c0:2:d0 foo.bar ", &val, hostname);
  41. printf ("ether_line (\"0:c0:2:d0 foo.bar \") = %d\n", r);
  42. result |= r != -1;
  43. r = ether_line ("0:c0:2:d0:1a:2a ", &val, hostname);
  44. printf ("ether_line (\"0:c0:2:d0:1a:2a \") = %d\n", r);
  45. result |= r != -1;
  46. return result;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"