]>
Commit | Line | Data |
---|---|---|
8f2ece69 | 1 | /* Test interface name <-> index conversions. |
688903eb | 2 | Copyright (C) 1997-2018 Free Software Foundation, Inc. |
8f2ece69 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Philip Blundell <Philip.Blundell@pobox.com>. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
8f2ece69 UD |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
8f2ece69 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
8f2ece69 UD |
19 | |
20 | #include <errno.h> | |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <net/if.h> | |
25 | ||
c9738df4 UD |
26 | static int |
27 | do_test (void) | |
8f2ece69 UD |
28 | { |
29 | int failures = 0; | |
30 | struct if_nameindex *idx = if_nameindex (), *p; | |
31 | if (idx == NULL) | |
32 | { | |
33 | if (errno != ENOSYS) | |
34 | { | |
35 | printf ("Couldn't get any interfaces.\n"); | |
36 | exit (1); | |
37 | } | |
38 | /* The function is simply not implemented. */ | |
39 | exit (0); | |
40 | } | |
41 | ||
42 | printf ("Idx Name | Idx Name\n"); | |
43 | ||
44 | for (p = idx; p->if_index || p->if_name; ++p) | |
45 | { | |
46 | char buf[IFNAMSIZ]; | |
9a0a462c UD |
47 | unsigned int ni; |
48 | int result; | |
8f2ece69 UD |
49 | printf ("%3d %15s | ", p->if_index, p->if_name); |
50 | printf ("%3d", ni = if_nametoindex (p->if_name)); | |
51 | printf ("%15s", if_indextoname (p->if_index, buf)); | |
52 | result = (ni != p->if_index || (strcmp (buf, p->if_name))); | |
9756dfe1 UD |
53 | if (ni == p->if_index) |
54 | /* We have to make sure that this is not an alias with the | |
55 | same interface number. */ | |
56 | if (p->if_index == if_nametoindex (buf)) | |
57 | result = 0; | |
8f2ece69 UD |
58 | printf ("%10s", result ? "fail" : "okay"); |
59 | printf ("\n"); | |
60 | failures += result; | |
61 | } | |
62 | if_freenameindex (idx); | |
bf4de8f3 | 63 | return failures ? 1 : 0; |
8f2ece69 | 64 | } |
c9738df4 UD |
65 | |
66 | #define TEST_FUNCTION do_test () | |
67 | #include "../test-skeleton.c" |