Skip to content

Commit a0c572d

Browse files
committed
tests/posix: add testcase for if_nameindex
1 parent db96e68 commit a0c572d

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ all_test_cases = [
159159
'posix/wcscoll_l',
160160
'posix/wcsxfrm_l',
161161
'posix/aio',
162+
'posix/if_nameindex',
162163
'glibc/getopt',
163164
'glibc/ffsl-ffsll',
164165
'glibc/error_message_count',

tests/posix/if_nameindex.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
#include <net/if.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
6+
int main(void) {
7+
struct if_nameindex *ni;
8+
9+
ni = if_nameindex();
10+
assert(ni != NULL);
11+
12+
for (struct if_nameindex *i = ni; !(i->if_index == 0 && i->if_name == NULL); i++) {
13+
fprintf(stderr, "[%d] '%s'\n", i->if_index, i->if_name);
14+
assert(i->if_index > 0);
15+
assert(i->if_name != NULL);
16+
assert(strlen(i->if_name) > 0);
17+
}
18+
19+
if_freenameindex(ni);
20+
21+
return 0;
22+
}

0 commit comments

Comments
 (0)