]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-socket-util.c
Merge pull request #7388 from keszybz/doc-tweak
[thirdparty/systemd.git] / src / test / test-socket-util.c
CommitLineData
c182135d
RC
1/***
2 This file is part of systemd
3
4 Copyright 2014 Ronny Chevalier
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
b5efdb8a 20#include "alloc-util.h"
07630cea 21#include "async.h"
3ffd4af2 22#include "fd-util.h"
3b653205 23#include "in-addr-util.h"
059f6c42 24#include "log.h"
07630cea
LP
25#include "macro.h"
26#include "socket-util.h"
27#include "string-util.h"
28#include "util.h"
c182135d 29
ef76dff2
LP
30static void test_ifname_valid(void) {
31 assert(ifname_valid("foo"));
32 assert(ifname_valid("eth0"));
33
34 assert(!ifname_valid("0"));
35 assert(!ifname_valid("99"));
36 assert(ifname_valid("a99"));
37 assert(ifname_valid("99a"));
38
39 assert(!ifname_valid(NULL));
40 assert(!ifname_valid(""));
41 assert(!ifname_valid(" "));
42 assert(!ifname_valid(" foo"));
43 assert(!ifname_valid("bar\n"));
44 assert(!ifname_valid("."));
45 assert(!ifname_valid(".."));
46 assert(ifname_valid("foo.bar"));
7ed95830 47 assert(!ifname_valid("x:y"));
ef76dff2
LP
48
49 assert(ifname_valid("xxxxxxxxxxxxxxx"));
50 assert(!ifname_valid("xxxxxxxxxxxxxxxx"));
51}
52
c182135d
RC
53static void test_socket_address_parse(void) {
54 SocketAddress a;
55
56 assert_se(socket_address_parse(&a, "junk") < 0);
57 assert_se(socket_address_parse(&a, "192.168.1.1") < 0);
58 assert_se(socket_address_parse(&a, ".168.1.1") < 0);
59 assert_se(socket_address_parse(&a, "989.168.1.1") < 0);
60 assert_se(socket_address_parse(&a, "192.168.1.1:65536") < 0);
61 assert_se(socket_address_parse(&a, "192.168.1.1:0") < 0);
62 assert_se(socket_address_parse(&a, "0") < 0);
63 assert_se(socket_address_parse(&a, "65536") < 0);
64
65 assert_se(socket_address_parse(&a, "65535") >= 0);
66
4ebc62ec
MB
67 /* The checks below will pass even if ipv6 is disabled in
68 * kernel. The underlying glibc's inet_pton() is just a string
69 * parser and doesn't make any syscalls. */
70
71 assert_se(socket_address_parse(&a, "[::1]") < 0);
72 assert_se(socket_address_parse(&a, "[::1]8888") < 0);
73 assert_se(socket_address_parse(&a, "::1") < 0);
74 assert_se(socket_address_parse(&a, "[::1]:0") < 0);
75 assert_se(socket_address_parse(&a, "[::1]:65536") < 0);
76 assert_se(socket_address_parse(&a, "[a:b:1]:8888") < 0);
77
78 assert_se(socket_address_parse(&a, "8888") >= 0);
79 assert_se(a.sockaddr.sa.sa_family == (socket_ipv6_is_supported() ? AF_INET6 : AF_INET));
80
81 assert_se(socket_address_parse(&a, "[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888") >= 0);
82 assert_se(a.sockaddr.sa.sa_family == AF_INET6);
83
84 assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
85 assert_se(a.sockaddr.sa.sa_family == AF_INET6);
c182135d
RC
86
87 assert_se(socket_address_parse(&a, "192.168.1.254:8888") >= 0);
88 assert_se(a.sockaddr.sa.sa_family == AF_INET);
89
90 assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
91 assert_se(a.sockaddr.sa.sa_family == AF_UNIX);
92
93 assert_se(socket_address_parse(&a, "@abstract") >= 0);
94 assert_se(a.sockaddr.sa.sa_family == AF_UNIX);
0fc0f14b
SH
95
96 assert_se(socket_address_parse(&a, "vsock::1234") >= 0);
97 assert_se(a.sockaddr.sa.sa_family == AF_VSOCK);
98 assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0);
99 assert_se(a.sockaddr.sa.sa_family == AF_VSOCK);
100 assert_se(socket_address_parse(&a, "vsock:2:1234x") < 0);
101 assert_se(socket_address_parse(&a, "vsock:2x:1234") < 0);
102 assert_se(socket_address_parse(&a, "vsock:2") < 0);
c182135d
RC
103}
104
105static void test_socket_address_parse_netlink(void) {
106 SocketAddress a;
107
108 assert_se(socket_address_parse_netlink(&a, "junk") < 0);
109 assert_se(socket_address_parse_netlink(&a, "") < 0);
110
111 assert_se(socket_address_parse_netlink(&a, "route") >= 0);
112 assert_se(socket_address_parse_netlink(&a, "route 10") >= 0);
113 assert_se(a.sockaddr.sa.sa_family == AF_NETLINK);
114 assert_se(a.protocol == NETLINK_ROUTE);
115}
116
117static void test_socket_address_equal(void) {
118 SocketAddress a;
119 SocketAddress b;
120
121 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
122 assert_se(socket_address_parse(&b, "192.168.1.1:888") >= 0);
123 assert_se(!socket_address_equal(&a, &b));
124
125 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
126 assert_se(socket_address_parse(&b, "192.16.1.1:8888") >= 0);
127 assert_se(!socket_address_equal(&a, &b));
128
129 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
130 assert_se(socket_address_parse(&b, "8888") >= 0);
131 assert_se(!socket_address_equal(&a, &b));
132
133 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
134 assert_se(socket_address_parse(&b, "/foo/bar/") >= 0);
135 assert_se(!socket_address_equal(&a, &b));
136
137 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
138 assert_se(socket_address_parse(&b, "192.168.1.1:8888") >= 0);
139 assert_se(socket_address_equal(&a, &b));
140
141 assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
142 assert_se(socket_address_parse(&b, "/foo/bar") >= 0);
143 assert_se(socket_address_equal(&a, &b));
144
145 assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
146 assert_se(socket_address_parse(&b, "[::1]:8888") >= 0);
147 assert_se(socket_address_equal(&a, &b));
148
149 assert_se(socket_address_parse(&a, "@abstract") >= 0);
150 assert_se(socket_address_parse(&b, "@abstract") >= 0);
151 assert_se(socket_address_equal(&a, &b));
152
153 assert_se(socket_address_parse_netlink(&a, "firewall") >= 0);
154 assert_se(socket_address_parse_netlink(&b, "firewall") >= 0);
155 assert_se(socket_address_equal(&a, &b));
0fc0f14b
SH
156
157 assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0);
158 assert_se(socket_address_parse(&b, "vsock:2:1234") >= 0);
159 assert_se(socket_address_equal(&a, &b));
160 assert_se(socket_address_parse(&b, "vsock:2:1235") >= 0);
161 assert_se(!socket_address_equal(&a, &b));
162 assert_se(socket_address_parse(&b, "vsock:3:1234") >= 0);
163 assert_se(!socket_address_equal(&a, &b));
c182135d
RC
164}
165
166static void test_socket_address_get_path(void) {
167 SocketAddress a;
168
169 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
170 assert_se(!socket_address_get_path(&a));
171
172 assert_se(socket_address_parse(&a, "@abstract") >= 0);
173 assert_se(!socket_address_get_path(&a));
174
175 assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
176 assert_se(!socket_address_get_path(&a));
177
178 assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
179 assert_se(streq(socket_address_get_path(&a), "/foo/bar"));
0fc0f14b
SH
180
181 assert_se(socket_address_parse(&a, "vsock:2:1234") >= 0);
182 assert_se(!socket_address_get_path(&a));
c182135d
RC
183}
184
43dc0043
RC
185static void test_socket_address_is(void) {
186 SocketAddress a;
187
188 assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
189 assert_se(socket_address_is(&a, "192.168.1.1:8888", SOCK_STREAM));
190 assert_se(!socket_address_is(&a, "route", SOCK_STREAM));
191 assert_se(!socket_address_is(&a, "192.168.1.1:8888", SOCK_RAW));
192}
193
194static void test_socket_address_is_netlink(void) {
195 SocketAddress a;
196
197 assert_se(socket_address_parse_netlink(&a, "route 10") >= 0);
198 assert_se(socket_address_is_netlink(&a, "route 10"));
199 assert_se(!socket_address_is_netlink(&a, "192.168.1.1:8888"));
200 assert_se(!socket_address_is_netlink(&a, "route 1"));
201}
202
e7639886
DM
203static void test_in_addr_is_null(void) {
204
205 union in_addr_union i = {};
206
207 assert_se(in_addr_is_null(AF_INET, &i) == true);
208 assert_se(in_addr_is_null(AF_INET6, &i) == true);
209
210 i.in.s_addr = 0x1000000;
211 assert_se(in_addr_is_null(AF_INET, &i) == false);
212 assert_se(in_addr_is_null(AF_INET6, &i) == false);
213
214 assert_se(in_addr_is_null(-1, &i) == -EAFNOSUPPORT);
215}
216
059f6c42
LP
217static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigned apl, const char *b, unsigned bpl, int result) {
218 union in_addr_union ua, ub;
219
220 assert_se(in_addr_from_string(f, a, &ua) >= 0);
221 assert_se(in_addr_from_string(f, b, &ub) >= 0);
222
223 assert_se(in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result);
224}
225
226static void test_in_addr_prefix_intersect(void) {
227
228 test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 32, "255.255.255.254", 32, 0);
229 test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 0, "255.255.255.255", 32, 1);
230 test_in_addr_prefix_intersect_one(AF_INET, "0.0.0.0", 0, "47.11.8.15", 32, 1);
231
232 test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.1", 24, 1);
233 test_in_addr_prefix_intersect_one(AF_INET, "2.2.2.2", 24, "1.1.1.1", 24, 0);
234
235 test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.127", 25, 1);
236 test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 24, "1.1.1.127", 26, 1);
237 test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 25, "1.1.1.127", 25, 1);
238 test_in_addr_prefix_intersect_one(AF_INET, "1.1.1.1", 25, "1.1.1.255", 25, 0);
239
240 test_in_addr_prefix_intersect_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe", 128, 0);
241 test_in_addr_prefix_intersect_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, 1);
242 test_in_addr_prefix_intersect_one(AF_INET6, "::", 0, "beef:beef:beef:beef:beef:beef:beef:beef", 128, 1);
243
244 test_in_addr_prefix_intersect_one(AF_INET6, "1::2", 64, "1::2", 64, 1);
245 test_in_addr_prefix_intersect_one(AF_INET6, "2::2", 64, "1::2", 64, 0);
246
247 test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 120, "1::007f", 121, 1);
248 test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 120, "1::007f", 122, 1);
249 test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 121, "1::007f", 121, 1);
250 test_in_addr_prefix_intersect_one(AF_INET6, "1::1", 121, "1::00ff", 121, 0);
251}
252
253static void test_in_addr_prefix_next_one(unsigned f, const char *before, unsigned pl, const char *after) {
254 union in_addr_union ubefore, uafter, t;
255
256 assert_se(in_addr_from_string(f, before, &ubefore) >= 0);
257
258 t = ubefore;
259 assert_se((in_addr_prefix_next(f, &t, pl) > 0) == !!after);
260
261 if (after) {
262 assert_se(in_addr_from_string(f, after, &uafter) >= 0);
263 assert_se(in_addr_equal(f, &t, &uafter) > 0);
264 }
265}
266
267static void test_in_addr_prefix_next(void) {
268
269 test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 24, "192.168.1.0");
270 test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 16, "192.169.0.0");
271 test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 20, "192.168.16.0");
272
273 test_in_addr_prefix_next_one(AF_INET, "0.0.0.0", 32, "0.0.0.1");
274 test_in_addr_prefix_next_one(AF_INET, "255.255.255.255", 32, NULL);
275 test_in_addr_prefix_next_one(AF_INET, "255.255.255.0", 24, NULL);
276
277 test_in_addr_prefix_next_one(AF_INET6, "4400::", 128, "4400::0001");
278 test_in_addr_prefix_next_one(AF_INET6, "4400::", 120, "4400::0100");
279 test_in_addr_prefix_next_one(AF_INET6, "4400::", 127, "4400::0002");
280 test_in_addr_prefix_next_one(AF_INET6, "4400::", 8, "4500::");
281 test_in_addr_prefix_next_one(AF_INET6, "4400::", 7, "4600::");
282
283 test_in_addr_prefix_next_one(AF_INET6, "::", 128, "::1");
284
285 test_in_addr_prefix_next_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, NULL);
286 test_in_addr_prefix_next_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00", 120, NULL);
287
288}
289
07916bea
RC
290static void test_in_addr_to_string_one(int f, const char *addr) {
291 union in_addr_union ua;
292 _cleanup_free_ char *r = NULL;
293
294 assert_se(in_addr_from_string(f, addr, &ua) >= 0);
295 assert_se(in_addr_to_string(f, &ua, &r) >= 0);
296 printf("test_in_addr_to_string_one: %s == %s\n", addr, r);
297 assert_se(streq(addr, r));
298}
299
300static void test_in_addr_to_string(void) {
301 test_in_addr_to_string_one(AF_INET, "192.168.0.1");
302 test_in_addr_to_string_one(AF_INET, "10.11.12.13");
303 test_in_addr_to_string_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
304 test_in_addr_to_string_one(AF_INET6, "::1");
305 test_in_addr_to_string_one(AF_INET6, "fe80::");
306}
307
2817157b
LP
308static void test_in_addr_ifindex_to_string_one(int f, const char *a, int ifindex, const char *b) {
309 _cleanup_free_ char *r = NULL;
310 union in_addr_union ua, uuaa;
311 int ff, ifindex2;
312
313 assert_se(in_addr_from_string(f, a, &ua) >= 0);
314 assert_se(in_addr_ifindex_to_string(f, &ua, ifindex, &r) >= 0);
315 printf("test_in_addr_ifindex_to_string_one: %s == %s\n", b, r);
316 assert_se(streq(b, r));
317
318 assert_se(in_addr_ifindex_from_string_auto(b, &ff, &uuaa, &ifindex2) >= 0);
319 assert_se(ff == f);
320 assert_se(in_addr_equal(f, &ua, &uuaa));
321 assert_se(ifindex2 == ifindex || ifindex2 == 0);
322}
323
324static void test_in_addr_ifindex_to_string(void) {
325 test_in_addr_ifindex_to_string_one(AF_INET, "192.168.0.1", 7, "192.168.0.1");
326 test_in_addr_ifindex_to_string_one(AF_INET, "10.11.12.13", 9, "10.11.12.13");
327 test_in_addr_ifindex_to_string_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 10, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
328 test_in_addr_ifindex_to_string_one(AF_INET6, "::1", 11, "::1");
329 test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::", 12, "fe80::%12");
330 test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::", 0, "fe80::");
331 test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::14", 12, "fe80::14%12");
332 test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::15", -7, "fe80::15");
333 test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::16", LOOPBACK_IFINDEX, "fe80::16%1");
334}
335
336static void test_in_addr_ifindex_from_string_auto(void) {
337 int family, ifindex;
338 union in_addr_union ua;
339
340 /* Most in_addr_ifindex_from_string_auto() invocations have already been tested above, but let's test some more */
341
342 assert_se(in_addr_ifindex_from_string_auto("fe80::17", &family, &ua, &ifindex) >= 0);
343 assert_se(family == AF_INET6);
344 assert_se(ifindex == 0);
345
346 assert_se(in_addr_ifindex_from_string_auto("fe80::18%19", &family, &ua, &ifindex) >= 0);
347 assert_se(family == AF_INET6);
348 assert_se(ifindex == 19);
349
350 assert_se(in_addr_ifindex_from_string_auto("fe80::18%lo", &family, &ua, &ifindex) >= 0);
351 assert_se(family == AF_INET6);
352 assert_se(ifindex == LOOPBACK_IFINDEX);
353
354 assert_se(in_addr_ifindex_from_string_auto("fe80::19%thisinterfacecantexist", &family, &ua, &ifindex) == -ENODEV);
355}
356
b31f535c
ZJS
357static void *connect_thread(void *arg) {
358 union sockaddr_union *sa = arg;
359 _cleanup_close_ int fd = -1;
360
361 fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
bdf7026e 362 assert_se(fd >= 0);
b31f535c
ZJS
363
364 assert_se(connect(fd, &sa->sa, sizeof(sa->in)) == 0);
365
366 return NULL;
367}
368
369static void test_nameinfo_pretty(void) {
eda8090b 370 _cleanup_free_ char *stdin_name = NULL, *localhost = NULL;
b31f535c
ZJS
371
372 union sockaddr_union s = {
373 .in.sin_family = AF_INET,
374 .in.sin_port = 0,
8e38570e 375 .in.sin_addr.s_addr = htobe32(INADDR_ANY),
b31f535c
ZJS
376 };
377 int r;
378
379 union sockaddr_union c = {};
380 socklen_t slen = sizeof(c.in), clen = sizeof(c.in);
381
eda8090b
TA
382 _cleanup_close_ int sfd = -1, cfd = -1;
383 r = getnameinfo_pretty(STDIN_FILENO, &stdin_name);
da927ba9 384 log_info_errno(r, "No connection remote: %m");
b31f535c
ZJS
385
386 assert_se(r < 0);
387
388 sfd = socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0);
bdf7026e 389 assert_se(sfd >= 0);
b31f535c
ZJS
390
391 assert_se(bind(sfd, &s.sa, sizeof(s.in)) == 0);
392
393 /* find out the port number */
394 assert_se(getsockname(sfd, &s.sa, &slen) == 0);
395
396 assert_se(listen(sfd, 1) == 0);
397
398 assert_se(asynchronous_job(connect_thread, &s) == 0);
399
400 log_debug("Accepting new connection on fd:%d", sfd);
401 cfd = accept4(sfd, &c.sa, &clen, SOCK_CLOEXEC);
bdf7026e 402 assert_se(cfd >= 0);
b31f535c
ZJS
403
404 r = getnameinfo_pretty(cfd, &localhost);
405 log_info("Connection from %s", localhost);
bdf7026e 406 assert_se(r == 0);
b31f535c
ZJS
407}
408
43dc0043
RC
409static void test_sockaddr_equal(void) {
410 union sockaddr_union a = {
411 .in.sin_family = AF_INET,
412 .in.sin_port = 0,
8e38570e 413 .in.sin_addr.s_addr = htobe32(INADDR_ANY),
43dc0043
RC
414 };
415 union sockaddr_union b = {
416 .in.sin_family = AF_INET,
417 .in.sin_port = 0,
8e38570e 418 .in.sin_addr.s_addr = htobe32(INADDR_ANY),
43dc0043
RC
419 };
420 union sockaddr_union c = {
421 .in.sin_family = AF_INET,
422 .in.sin_port = 0,
8e38570e 423 .in.sin_addr.s_addr = htobe32(1234),
43dc0043
RC
424 };
425 union sockaddr_union d = {
426 .in6.sin6_family = AF_INET6,
427 .in6.sin6_port = 0,
428 .in6.sin6_addr = IN6ADDR_ANY_INIT,
429 };
0fc0f14b
SH
430 union sockaddr_union e = {
431 .vm.svm_family = AF_VSOCK,
432 .vm.svm_port = 0,
433 .vm.svm_cid = VMADDR_CID_ANY,
434 };
43dc0043
RC
435 assert_se(sockaddr_equal(&a, &a));
436 assert_se(sockaddr_equal(&a, &b));
437 assert_se(sockaddr_equal(&d, &d));
0fc0f14b 438 assert_se(sockaddr_equal(&e, &e));
43dc0043
RC
439 assert_se(!sockaddr_equal(&a, &c));
440 assert_se(!sockaddr_equal(&b, &c));
0fc0f14b 441 assert_se(!sockaddr_equal(&a, &e));
43dc0043
RC
442}
443
fc2fffe7
LP
444static void test_sockaddr_un_len(void) {
445 static const struct sockaddr_un fs = {
446 .sun_family = AF_UNIX,
447 .sun_path = "/foo/bar/waldo",
448 };
449
450 static const struct sockaddr_un abstract = {
451 .sun_family = AF_UNIX,
452 .sun_path = "\0foobar",
453 };
454
455 assert_se(SOCKADDR_UN_LEN(fs) == offsetof(struct sockaddr_un, sun_path) + strlen(fs.sun_path));
456 assert_se(SOCKADDR_UN_LEN(abstract) == offsetof(struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1));
457}
458
1703b203
SS
459static void test_in_addr_is_multicast(void) {
460 union in_addr_union a, b;
461 int f;
462
463 assert_se(in_addr_from_string_auto("192.168.3.11", &f, &a) >= 0);
464 assert_se(in_addr_is_multicast(f, &a) == 0);
465
466 assert_se(in_addr_from_string_auto("224.0.0.1", &f, &a) >= 0);
467 assert_se(in_addr_is_multicast(f, &a) == 1);
468
469 assert_se(in_addr_from_string_auto("FF01:0:0:0:0:0:0:1", &f, &b) >= 0);
470 assert_se(in_addr_is_multicast(f, &b) == 1);
471
472 assert_se(in_addr_from_string_auto("2001:db8::c:69b:aeff:fe53:743e", &f, &b) >= 0);
473 assert_se(in_addr_is_multicast(f, &b) == 0);
474}
475
c182135d 476int main(int argc, char *argv[]) {
059f6c42
LP
477
478 log_set_max_level(LOG_DEBUG);
479
ef76dff2
LP
480 test_ifname_valid();
481
c182135d
RC
482 test_socket_address_parse();
483 test_socket_address_parse_netlink();
484 test_socket_address_equal();
485 test_socket_address_get_path();
43dc0043
RC
486 test_socket_address_is();
487 test_socket_address_is_netlink();
059f6c42 488
e7639886 489 test_in_addr_is_null();
059f6c42
LP
490 test_in_addr_prefix_intersect();
491 test_in_addr_prefix_next();
07916bea 492 test_in_addr_to_string();
2817157b
LP
493 test_in_addr_ifindex_to_string();
494 test_in_addr_ifindex_from_string_auto();
059f6c42 495
b31f535c
ZJS
496 test_nameinfo_pretty();
497
43dc0043
RC
498 test_sockaddr_equal();
499
fc2fffe7
LP
500 test_sockaddr_un_len();
501
1703b203
SS
502 test_in_addr_is_multicast();
503
059f6c42 504 return 0;
c182135d 505}