1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <errno.h>
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include <string.h>
25: #include <net/if.h>
26:
27: static int
28: do_test (void)
29: {
30: int failures = 0;
31: struct if_nameindex *idx = if_nameindex (), *p;
32: if (idx == NULL)
33: {
34: if (errno != ENOSYS)
35: {
36: printf ("Couldn't get any interfaces.\n");
37: exit (1);
38: }
39:
40: exit (0);
41: }
42:
43: printf ("Idx Name | Idx Name\n");
44:
45: for (p = idx; p->if_index || p->if_name; ++p)
46: {
47: char buf[IFNAMSIZ];
48: unsigned int ni;
49: int result;
50: printf ("%3d %15s | ", p->if_index, p->if_name);
51: printf ("%3d", ni = if_nametoindex (p->if_name));
52: printf ("%15s", if_indextoname (p->if_index, buf));
53: result = (ni != p->if_index || (strcmp (buf, p->if_name)));
54: if (ni == p->if_index)
55:
56:
57: if (p->if_index == if_nametoindex (buf))
58: result = 0;
59: printf ("%10s", result ? "fail" : "okay");
60: printf ("\n");
61: failures += result;
62: }
63: if_freenameindex (idx);
64: return failures ? 1 : 0;
65: }
66:
67: #define TEST_FUNCTION do_test ()
68: #include "../test-skeleton.c"