xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <netinet/ether.h> |
| 4 | |
| 5 | static int |
| 6 | do_test (void) |
| 7 | { |
| 8 | struct ether_addr *valp, val; |
| 9 | int result, r; |
| 10 | char hostname[32], buf[64], *p; |
| 11 | |
| 12 | valp = ether_aton ("12:34:56:78:9a:bc"); |
| 13 | |
| 14 | printf ("ether_aton (\"12:34:56:78:9a:bc\") = %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n", |
| 15 | valp->ether_addr_octet[0], |
| 16 | valp->ether_addr_octet[1], |
| 17 | valp->ether_addr_octet[2], |
| 18 | valp->ether_addr_octet[3], |
| 19 | valp->ether_addr_octet[4], |
| 20 | valp->ether_addr_octet[5]); |
| 21 | |
| 22 | result = (valp->ether_addr_octet[0] != 0x12 |
| 23 | || valp->ether_addr_octet[1] != 0x34 |
| 24 | || valp->ether_addr_octet[2] != 0x56 |
| 25 | || valp->ether_addr_octet[3] != 0x78 |
| 26 | || valp->ether_addr_octet[4] != 0x9a |
| 27 | || valp->ether_addr_octet[5] != 0xbc); |
| 28 | |
| 29 | if ((r = ether_line ("0:c0:f0:46:5f:97 host.ether.com \t# comment", |
| 30 | &val, hostname)) == 0) |
| 31 | { |
| 32 | ether_ntoa_r (&val, buf); |
| 33 | p = strchr (buf, '\0'); |
| 34 | *p++ = ' '; |
| 35 | strcpy (p, hostname); |
| 36 | |
| 37 | printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = \"%s\"\n", |
| 38 | buf); |
| 39 | |
| 40 | result |= strcmp ("0:c0:f0:46:5f:97 host.ether.com", buf) != 0; |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = %d\n", r); |
| 45 | result |= 1; |
| 46 | } |
| 47 | |
| 48 | r = ether_line ("0:c0:2:d0 foo.bar ", &val, hostname); |
| 49 | printf ("ether_line (\"0:c0:2:d0 foo.bar \") = %d\n", r); |
| 50 | result |= r != -1; |
| 51 | |
| 52 | r = ether_line ("0:c0:2:d0:1a:2a ", &val, hostname); |
| 53 | printf ("ether_line (\"0:c0:2:d0:1a:2a \") = %d\n", r); |
| 54 | result |= r != -1; |
| 55 | |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | #define TEST_FUNCTION do_test () |
| 60 | #include "../test-skeleton.c" |