summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-02-28 09:56:28 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-02-28 09:56:28 +0000
commitc65d99084a5979a34ff3aa504135152b6b31b2bb (patch)
tree7e0cd1b8b74ca7cb4b0f642b37fc2939b67377a9 /test
parent56a0a95d9345a865de215af619f42140d6060116 (diff)
Added support for ether_line, ether_ntohost and ether_hostton.
Added related test cases. Signed-off-by: Matthew Wilcox <matthew@wil.cx> Hacked-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/inet/tst-ethers-line.c45
-rwxr-xr-xtest/inet/tst-ethers.c28
2 files changed, 73 insertions, 0 deletions
diff --git a/test/inet/tst-ethers-line.c b/test/inet/tst-ethers-line.c
new file mode 100755
index 000000000..d4835b546
--- /dev/null
+++ b/test/inet/tst-ethers-line.c
@@ -0,0 +1,45 @@
+#include <netinet/ether.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#define ETHER_LINE_LEN 256
+
+int main(void)
+{
+ struct ether_addr addr;
+ char hostname[ETHER_LINE_LEN];
+ int fd, i;
+ const char *ethers;
+ struct stat statb;
+
+ if ((fd = open(ETHER_FILE_NAME, O_RDONLY)) == -1) {
+ perror ("Cannot open file");
+ exit(1);
+ }
+
+ if (fstat(fd, &statb)) {
+ perror("Stat failed");
+ exit(1);
+ }
+ ethers = mmap(NULL, statb.st_size, PROT_READ, MAP_SHARED, fd, 0);
+
+ if (ethers == MAP_FAILED) {
+ perror("File mapping failed");
+ exit(1);
+ }
+
+ ether_line(ethers, &addr, hostname);
+
+ for (i = 0; i < 6; i++) {
+ printf("%02x", addr.ether_addr_octet[i]);
+ if (i < 5)
+ printf(":");
+ }
+ printf(" %s\n", hostname);
+
+ return 0;
+}
diff --git a/test/inet/tst-ethers.c b/test/inet/tst-ethers.c
new file mode 100755
index 000000000..eb6280c3f
--- /dev/null
+++ b/test/inet/tst-ethers.c
@@ -0,0 +1,28 @@
+#include <netinet/ether.h>
+#include <stdio.h>
+
+#define ETHER_LINE_LEN 256
+
+int main(void)
+{
+ struct ether_addr addr;
+ char host[ETHER_LINE_LEN];
+ int i;
+ int res = ether_hostton("teeth", &addr);
+
+ if (res)
+ 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;
+}