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. You should create it manually,
18 * if it doesn't exist.
23 struct ether_addr addr
;
24 char hostname
[ETHER_LINE_LEN
];
29 if ((fd
= open(ETHER_FILE_NAME
, O_RDONLY
)) == -1) {
30 perror ("Cannot open file /etc/ethers");
34 if (fstat(fd
, &statb
)) {
35 perror("Stat failed");
38 ethers
= mmap(NULL
, statb
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
40 if (ethers
== MAP_FAILED
) {
41 perror("File mapping failed");
45 ether_line(ethers
, &addr
, hostname
);
47 for (i
= 0; i
< 6; i
++) {
48 printf("%02x", addr
.ether_addr_octet
[i
]);
52 printf(" %s\n", hostname
);