blob: 67cb435406b383a417824a6acb965c43d489ac31 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <stdint.h>
3#include <string.h>
4#include <netinet/ether.h>
5
6static struct tests
7{
8 const char *input;
9 int valid;
10 uint8_t result[6];
11} tests[] =
12{
13 { "", 0, {0, 0, 0, 0, 0, 0} },
14 { "AB:CD:EF:01:23:45", 1, {171, 205, 239, 1, 35, 69} },
15 { "\022B:BB:BB:BB:BB:BB", 0, {0, 0, 0, 0, 0, 0} }
16};
17
18
19int
20main (int argc, char *argv[])
21{
22 int result = 0;
23 size_t cnt;
24
25 for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
26 {
27 struct ether_addr *addr;
28
29 if (!!(addr = ether_aton (tests[cnt].input)) != tests[cnt].valid)
30 {
31 if (tests[cnt].valid)
32 printf ("\"%s\" not seen as valid MAC address\n", tests[cnt].input);
33 else
34 printf ("\"%s\" seen as valid MAC address\n", tests[cnt].input);
35 result = 1;
36 }
37 else if (tests[cnt].valid
38 && memcmp(addr, &tests[cnt].result, sizeof(struct ether_addr)))
39 {
40 printf ("\"%s\" not converted correctly\n", tests[cnt].input);
41 result = 1;
42 }
43 }
44
45 return result;
46}