]>
git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/check_ifaddrs.c
4 #include "../src/lldpd.h"
6 #define DUMP "ifdump.txt"
8 /* This is not a real test. It should dump into a file the list of interfaces */
11 addr_string (struct sockaddr
*sa
) {
16 switch (sa
->sa_family
) {
18 res
= inet_ntop(AF_INET
,
19 &((struct sockaddr_in
*)sa
)->sin_addr
,
23 res
= inet_ntop(AF_INET6
,
24 &((struct sockaddr_in6
*)sa
)->sin6_addr
,
32 snprintf(buf
, 64, "<%4d>", sa
->sa_family
);
37 memcpy(buf
+ 21, "[...]", strlen("[...]") + 1);
41 START_TEST (test_ifaddrs
)
43 struct ifaddrs
*ifap
, *ifa
;
46 if (getifaddrs(&ifap
) < 0) {
47 fail("unable to get interface list");
50 dump
= fopen(DUMP
, "w+");
52 fail("unable to open dump file " DUMP
);
56 "Name Flags Address Netmask Broadcast/Destination\n");
57 for (ifa
= ifap
; ifa
; ifa
= ifa
->ifa_next
) {
58 fprintf(dump
, "%-15s%#.5x ",
59 ifa
->ifa_name
, ifa
->ifa_flags
);
60 fprintf(dump
, "%-26s ",
61 addr_string(ifa
->ifa_addr
));
62 fprintf(dump
, "%-26s ",
63 addr_string(ifa
->ifa_netmask
));
64 fprintf(dump
, "%-26s\n",
65 addr_string(ifa
->ifa_broadaddr
));
74 Suite
*s
= suite_create("getifaddrs");
76 /* Single objects packing/unpacking */
77 TCase
*tc_core
= tcase_create("getifaddrs");
78 tcase_add_test(tc_core
, test_ifaddrs
);
79 suite_add_tcase(s
, tc_core
);
88 Suite
*s
= ifaddrs_suite ();
89 SRunner
*sr
= srunner_create (s
);
90 srunner_run_all (sr
, CK_ENV
);
91 number_failed
= srunner_ntests_failed (sr
);
93 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;