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 static const char *ether_line_string = "01:23:45:67:89:ab ether_line_hostname";
40 static const char *ether_line_hostname = "ether_line_hostname";
41 static const struct ether_addr ether_line_addr = {
42 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
45 ATF_TC_WITHOUT_HEAD(ether_line);
46 ATF_TC_BODY(ether_line, tc)
51 ATF_REQUIRE_MSG(ether_line(ether_line_string, &e, hostname) == 0,
52 "ether_line failed; errno=%d", errno);
53 ATF_REQUIRE_MSG(bcmp(&e, ðer_line_addr, ETHER_ADDR_LEN) == 0,
55 ATF_REQUIRE_MSG(strcmp(hostname, ether_line_hostname) == 0,
59 static const char *ether_line_bad_1_string = "x";
61 ATF_TC_WITHOUT_HEAD(ether_line_bad_1);
62 ATF_TC_BODY(ether_line_bad_1, tc)
67 ATF_REQUIRE_MSG(ether_line(ether_line_bad_1_string, &e, hostname) != 0,
68 "ether_line succeeded unexpectedly");
71 static const char *ether_line_bad_2_string = "x x";
73 ATF_TC_WITHOUT_HEAD(ether_line_bad_2);
74 ATF_TC_BODY(ether_line_bad_2, tc)
79 ATF_REQUIRE_MSG(ether_line(ether_line_bad_2_string, &e, hostname) != 0,
80 "ether_line succeeded unexpectedly");
83 static const char *ether_aton_string = "01:23:45:67:89:ab";
84 static const struct ether_addr ether_aton_addr = {
85 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
88 ATF_TC_WITHOUT_HEAD(ether_aton_r);
89 ATF_TC_BODY(ether_aton_r, tc)
91 struct ether_addr e, *ep;
93 ep = ether_aton_r(ether_aton_string, &e);
95 ATF_REQUIRE_MSG(ep != NULL, "ether_aton_r failed; errno=%d", errno);
96 ATF_REQUIRE_MSG(ep == &e,
97 "ether_aton_r returned different pointers; %p != %p", ep, &e);
100 static const char *ether_aton_bad_string = "x";
102 ATF_TC_WITHOUT_HEAD(ether_aton_r_bad);
103 ATF_TC_BODY(ether_aton_r_bad, tc)
105 struct ether_addr e, *ep;
107 ep = ether_aton_r(ether_aton_bad_string, &e);
108 ATF_REQUIRE_MSG(ep == NULL, "ether_aton_r succeeded unexpectedly");
111 ATF_TC_WITHOUT_HEAD(ether_aton);
112 ATF_TC_BODY(ether_aton, tc)
114 struct ether_addr *ep;
116 ep = ether_aton(ether_aton_string);
117 ATF_REQUIRE_MSG(ep != NULL, "ether_aton failed");
118 ATF_REQUIRE_MSG(bcmp(ep, ðer_aton_addr, ETHER_ADDR_LEN) == 0,
122 ATF_TC_WITHOUT_HEAD(ether_aton_bad);
123 ATF_TC_BODY(ether_aton_bad, tc)
125 struct ether_addr *ep;
127 ep = ether_aton(ether_aton_bad_string);
128 ATF_REQUIRE_MSG(ep == NULL, "ether_aton succeeded unexpectedly");
131 static const char *ether_ntoa_string = "01:23:45:67:89:ab";
132 static const struct ether_addr ether_ntoa_addr = {
133 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
136 ATF_TC_WITHOUT_HEAD(ether_ntoa_r);
137 ATF_TC_BODY(ether_ntoa_r, tc)
141 cp = ether_ntoa_r(ðer_ntoa_addr, buf);
142 ATF_REQUIRE_MSG(cp != NULL, "ether_ntoa_r failed");
143 ATF_REQUIRE_MSG(cp == buf,
144 "ether_ntoa_r returned a different pointer; %p != %p", cp, buf);
145 ATF_REQUIRE_MSG(strcmp(cp, ether_ntoa_string) == 0,
146 "strings did not match (`%s` != `%s`)", cp, ether_ntoa_string);
149 ATF_TC_WITHOUT_HEAD(ether_ntoa);
150 ATF_TC_BODY(ether_ntoa, tc)
154 cp = ether_ntoa(ðer_ntoa_addr);
155 ATF_REQUIRE_MSG(cp != NULL, "ether_ntoa failed");
156 ATF_REQUIRE_MSG(strcmp(cp, ether_ntoa_string) == 0,
157 "strings did not match (`%s` != `%s`)", cp, ether_ntoa_string);
161 ATF_TC_WITHOUT_HEAD(ether_ntohost);
162 ATF_TC_BODY(ether_ntohost, tc)
167 ATF_TC_WITHOUT_HEAD(ether_hostton);
168 ATF_TC_BODY(ether_hostton, tc)
177 ATF_TP_ADD_TC(tp, ether_line);
178 ATF_TP_ADD_TC(tp, ether_line_bad_1);
179 ATF_TP_ADD_TC(tp, ether_line_bad_2);
180 ATF_TP_ADD_TC(tp, ether_aton_r);
181 ATF_TP_ADD_TC(tp, ether_aton_r_bad);
182 ATF_TP_ADD_TC(tp, ether_aton);
183 ATF_TP_ADD_TC(tp, ether_aton_bad);
184 ATF_TP_ADD_TC(tp, ether_ntoa_r);
185 ATF_TP_ADD_TC(tp, ether_ntoa);
187 ATF_TP_ADD_TC(tp, ether_ntohost);
188 ATF_TP_ADD_TC(tp, ether_hostton);
191 return (atf_no_error());