1 #include <netinet/ether.h>
9 /* glibc 2.4 has no ETHER_FILE_NAME, host compile fails without this */
10 #ifndef ETHER_FILE_NAME
11 #define ETHER_FILE_NAME "/etc/ethers"
14 #define ETHER_LINE_LEN 256
16 /* This test requires /etc/ethers to exist
17 * and to have nonzero length
22 struct ether_addr addr;
23 char hostname[ETHER_LINE_LEN];
28 if ((fd = open(ETHER_FILE_NAME, O_RDONLY)) == -1) {
29 perror ("Cannot open file");
33 if (fstat(fd, &statb)) {
34 perror("Stat failed");
37 ethers = mmap(NULL, statb.st_size, PROT_READ, MAP_SHARED, fd, 0);
39 if (ethers == MAP_FAILED) {
40 perror("File mapping failed");
44 ether_line(ethers, &addr, hostname);
46 for (i = 0; i < 6; i++) {
47 printf("%02x", addr.ether_addr_octet[i]);
51 printf(" %s\n", hostname);