tst-ethers.c 535 B

123456789101112131415161718192021222324252627282930313233
  1. #include <netinet/ether.h>
  2. #include <stdio.h>
  3. #define ETHER_LINE_LEN 256
  4. /* This test requires /etc/ethers to exist
  5. * and to have host "teeth". For example:
  6. * 00:11:22:33:44:55 teeth
  7. */
  8. int main(void)
  9. {
  10. struct ether_addr addr;
  11. char host[ETHER_LINE_LEN];
  12. int i;
  13. int res = ether_hostton("teeth", &addr);
  14. if (res)
  15. return 1;
  16. for (i = 0; i < 6; i++) {
  17. printf("%02x", addr.ether_addr_octet[i]);
  18. if (i < 5)
  19. printf(":");
  20. }
  21. res = ether_ntohost(host, &addr);
  22. if (res)
  23. return 1;
  24. printf(" %s\n", host);
  25. return 0;
  26. }