bump for release
[uclibc-ng.git] / test / inet / tst-ethers-line.c
blob182faf0981900086a98860120082761f0901f297
1 #include <netinet/ether.h>
2 #include <stdio.h>
3 #include <sys/mman.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.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"
12 #endif
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.
21 int main(void)
23 struct ether_addr addr;
24 char hostname[ETHER_LINE_LEN];
25 int fd, i;
26 const char *ethers;
27 struct stat statb;
29 if ((fd = open(ETHER_FILE_NAME, O_RDONLY)) == -1) {
30 perror ("Cannot open file /etc/ethers");
31 exit(1);
34 if (fstat(fd, &statb)) {
35 perror("Stat failed");
36 exit(1);
38 ethers = mmap(NULL, statb.st_size, PROT_READ, MAP_SHARED, fd, 0);
40 if (ethers == MAP_FAILED) {
41 perror("File mapping failed");
42 exit(1);
45 ether_line(ethers, &addr, hostname);
47 for (i = 0; i < 6; i++) {
48 printf("%02x", addr.ether_addr_octet[i]);
49 if (i < 5)
50 printf(":");
52 printf(" %s\n", hostname);
54 return 0;