lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdint.h> |
| 3 | #include <string.h> |
| 4 | #include <netinet/ether.h> |
| 5 | |
| 6 | static 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 | |
| 19 | int |
| 20 | main (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 | } |