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