1 /* if_nameindex.c: test the if_nameindex() function
3 * Copyright (C) 2006 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
12 static char ifname[IF_NAMESIZE];
14 static void test_if_nameindex(void)
17 struct if_nameindex *ret;
22 perror("if_nameindex()");
26 printf("--- if_nameindex()\n");
27 for (i=0; ret[i].if_name; ++i)
28 printf("%i: %s\n", ret[i].if_index, ret[i].if_name);
30 if_freenameindex(ret);
33 static void test_if_indextoname(void)
35 if (if_indextoname(1, ifname) == NULL) {
36 perror("if_nameindex()");
40 printf("if_indextoname(1) = %s\n", ifname);
43 static void test_if_nametoindex(void)
45 int ifindex = if_nametoindex(ifname);
48 perror("if_nametoindex()");
52 printf("if_nametoindex(%s) = %i\n", ifname, ifindex);
58 test_if_indextoname();
59 test_if_nametoindex();