summaryrefslogtreecommitdiff
path: root/test/inet/tst-ethers.c
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2016-10-24 20:22:12 +0200
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-10-24 20:22:12 +0200
commit7988979a722b4cdf287b2093956a76a3f19b9897 (patch)
treed35e251d0472ceca55a2eef61cff261c8ee68fab /test/inet/tst-ethers.c
add uClibc-ng test directory
Diffstat (limited to 'test/inet/tst-ethers.c')
-rw-r--r--test/inet/tst-ethers.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/inet/tst-ethers.c b/test/inet/tst-ethers.c
new file mode 100644
index 0000000..f12813a
--- /dev/null
+++ b/test/inet/tst-ethers.c
@@ -0,0 +1,37 @@
+#include <netinet/ether.h>
+#include <stdio.h>
+
+#define ETHER_LINE_LEN 256
+
+/* This test requires /etc/ethers to exist
+ * and to have host "teeth". For example:
+ * 00:11:22:33:44:55 teeth
+ * You should create /etc/ethers file with
+ * host "teeth" manually, if it doesn't exist.
+ */
+
+int main(void)
+{
+ struct ether_addr addr;
+ char host[ETHER_LINE_LEN];
+ int i;
+ int res = ether_hostton("teeth", &addr);
+
+ if (res) {
+ printf("Either /etc/ethers is missing or it has incorrect contents\n");
+ return 1;
+ }
+
+ for (i = 0; i < 6; i++) {
+ printf("%02x", addr.ether_addr_octet[i]);
+ if (i < 5)
+ printf(":");
+ }
+
+ res = ether_ntohost(host, &addr);
+ if (res)
+ return 1;
+ printf(" %s\n", host);
+
+ return 0;
+}