tst-ethers.c 704 B

12345678910111213141516171819202122232425262728293031323334353637
  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. * You should create /etc/ethers file with
  8. * host "teeth" manually, if it doesn't exist.
  9. */
  10. int main(void)
  11. {
  12. struct ether_addr addr;
  13. char host[ETHER_LINE_LEN];
  14. int i;
  15. int res = ether_hostton("teeth", &addr);
  16. if (res) {
  17. printf("Either /etc/ethers is missing or it has incorrect contents\n");
  18. return 1;
  19. }
  20. for (i = 0; i < 6; i++) {
  21. printf("%02x", addr.ether_addr_octet[i]);
  22. if (i < 5)
  23. printf(":");
  24. }
  25. res = ether_ntohost(host, &addr);
  26. if (res)
  27. return 1;
  28. printf(" %s\n", host);
  29. return 0;
  30. }