2 * Copyright (c) 2007 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/types.h>
31 #include <net/ethernet.h>
39 printf("ok %d %s\n", testnum, __func__); \
43 #define NOTOK(why) do { \
44 printf("not ok %d %s # %s\n", testnum, __func__, why); \
48 #define TODO() NOTOK("TODO")
50 static const char *ether_line_string =
51 "01:23:45:67:89:ab ether_line_hostname";
52 static const char *ether_line_hostname = "ether_line_hostname";
53 static const struct ether_addr ether_line_addr = {
54 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
64 if (ether_line(ether_line_string, &e, hostname) != 0)
65 NOTOK("returned error");
66 if (bcmp(&e, ðer_line_addr, ETHER_ADDR_LEN) != 0)
68 if (strcmp(hostname, ether_line_hostname) != 0) {
69 printf("hostname: %s\n", hostname);
70 NOTOK("bad hostname");
75 static const char *ether_line_bad_1_string = "x";
78 test_ether_line_bad_1(void)
84 if (ether_line(ether_line_bad_1_string, &e, hostname) == 0)
85 NOTOK("returned success");
89 static const char *ether_line_bad_2_string = "x x";
92 test_ether_line_bad_2(void)
98 if (ether_line(ether_line_bad_2_string, &e, hostname) == 0)
99 NOTOK("returned success");
103 static const char *ether_aton_string = "01:23:45:67:89:ab";
104 static const struct ether_addr ether_aton_addr = {
105 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
109 test_ether_aton_r(void)
111 struct ether_addr e, *ep;
114 ep = ether_aton_r(ether_aton_string, &e);
116 NOTOK("returned NULL");
118 NOTOK("returned different pointer");
119 if (bcmp(&e, ðer_aton_addr, ETHER_ADDR_LEN) != 0)
120 NOTOK("bad address");
124 static const char *ether_aton_bad_string = "x";
127 test_ether_aton_r_bad(void)
129 struct ether_addr e, *ep;
132 ep = ether_aton_r(ether_aton_bad_string, &e);
134 NOTOK("returned success");
136 NOTOK("returned different pointer");
141 test_ether_aton(void)
143 struct ether_addr *ep;
146 ep = ether_aton(ether_aton_string);
148 NOTOK("returned NULL");
149 if (bcmp(ep, ðer_aton_addr, ETHER_ADDR_LEN) != 0)
150 NOTOK("bad address");
155 test_ether_aton_bad(void)
157 struct ether_addr *ep;
160 ep = ether_aton(ether_aton_bad_string);
162 NOTOK("returned success");
166 static const char *ether_ntoa_string = "01:23:45:67:89:ab";
167 static const struct ether_addr ether_ntoa_addr = {
168 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
172 test_ether_ntoa_r(void)
177 cp = ether_ntoa_r(ðer_ntoa_addr, buf);
179 NOTOK("returned NULL");
181 NOTOK("returned different pointer");
182 if (strcmp(cp, ether_ntoa_string) != 0)
188 test_ether_ntoa(void)
193 cp = ether_ntoa(ðer_ntoa_addr);
195 NOTOK("returned NULL");
196 if (strcmp(cp, ether_ntoa_string) != 0)
202 test_ether_ntohost(void)
210 test_ether_hostton(void)
218 main(int argc, char *argv[])
224 test_ether_line_bad_1();
225 test_ether_line_bad_2();
227 test_ether_aton_r_bad();
229 test_ether_aton_bad();
232 test_ether_ntohost();
233 test_ether_hostton();