summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid A Ramos <daramos@gustav.stanford.edu>2011-05-01 17:28:31 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2011-05-01 17:28:31 +0200
commit23135f442dc220b496e2a4af3366cc2795587ec7 (patch)
treec574df29255ed2469ed2bf629b2c2aa05737adb2 /test
parent221464c9c4227810de9f027c3ace63805480d723 (diff)
inet: add ether_aton testcase
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/inet/tst-ether_aton.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/inet/tst-ether_aton.c b/test/inet/tst-ether_aton.c
new file mode 100644
index 000000000..67cb43540
--- /dev/null
+++ b/test/inet/tst-ether_aton.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+static struct tests
+{
+ const char *input;
+ int valid;
+ uint8_t result[6];
+} tests[] =
+{
+ { "", 0, {0, 0, 0, 0, 0, 0} },
+ { "AB:CD:EF:01:23:45", 1, {171, 205, 239, 1, 35, 69} },
+ { "\022B:BB:BB:BB:BB:BB", 0, {0, 0, 0, 0, 0, 0} }
+};
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ size_t cnt;
+
+ for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
+ {
+ struct ether_addr *addr;
+
+ if (!!(addr = ether_aton (tests[cnt].input)) != tests[cnt].valid)
+ {
+ if (tests[cnt].valid)
+ printf ("\"%s\" not seen as valid MAC address\n", tests[cnt].input);
+ else
+ printf ("\"%s\" seen as valid MAC address\n", tests[cnt].input);
+ result = 1;
+ }
+ else if (tests[cnt].valid
+ && memcmp(addr, &tests[cnt].result, sizeof(struct ether_addr)))
+ {
+ printf ("\"%s\" not converted correctly\n", tests[cnt].input);
+ result = 1;
+ }
+ }
+
+ return result;
+}