This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <net/if.h>
22
23
24
25 #if HAVE_NET_IF_H && HAVE_IF_NAMEINDEX
26 # include "signature.h"
27 SIGNATURE_CHECK (if_freenameindex, void, (struct if_nameindex *));
28 SIGNATURE_CHECK (if_indextoname, char *, (unsigned int, char *));
29 SIGNATURE_CHECK (if_nameindex, struct if_nameindex *, (void));
30 SIGNATURE_CHECK (if_nametoindex, unsigned int, (const char *));
31 #endif
32
33 #include <stddef.h>
34 #include <stdio.h>
35
36 int
37 main (int argc, char *argv[])
38 {
39 #if HAVE_NET_IF_H && HAVE_IF_NAMEINDEX
40 struct if_nameindex *ifnp, *p;
41
42 p = ifnp = if_nameindex ();
43 if (ifnp == NULL)
44 {
45 fputs ("if_nameindex returned NULL\n", stderr);
46 return 1;
47 }
48
49 while (p->if_index)
50 {
51 unsigned int idx;
52 char buf[IF_NAMESIZE];
53 char *q;
54
55 if (argc > 1)
56 printf ("index %d name %s\n", p->if_index, p->if_name);
57
58 idx = if_nametoindex (p->if_name);
59 if (idx != p->if_index)
60 {
61 fprintf (stderr, "if_nametoindex (%s) = %d != %d\n",
62 p->if_name, idx, p->if_index);
63 return 1;
64 }
65
66 q = if_indextoname (p->if_index, buf);
67 if (q == NULL)
68 {
69 fprintf (stderr, "if_indextoname (%d) returned NULL\n", p->if_index);
70 return 1;
71 }
72 if (q != buf)
73 {
74 fprintf (stderr, "if_indextoname (%d) buffer mismatch?\n",
75 p->if_index);
76 return 1;
77 }
78 if (strcmp (p->if_name, q) != 0)
79 {
80 fprintf (stderr, "if_indextoname (%s) = %s ?!\n", p->if_name, q);
81 return 1;
82 }
83
84 p++;
85 }
86
87 if_freenameindex (ifnp);
88 #endif
89
90 #if !HAVE_NET_IF_H || HAVE_IF_NAMEINDEX
91 {
92 static struct if_nameindex ni;
93 return !IF_NAMESIZE + ni.if_index + !!ni.if_name;
94 }
95 #else
96 return 0;
97 #endif
98 }