1 /* Test interface name <-> index conversions.
2 Copyright (C) 1997, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Philip Blundell <Philip.Blundell@pobox.com>.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
31 struct if_nameindex
*idx
= if_nameindex (), *p
;
36 printf ("Couldn't get any interfaces.\n");
39 /* The function is simply not implemented. */
43 printf ("Idx Name | Idx Name\n");
45 for (p
= idx
; p
->if_index
|| p
->if_name
; ++p
)
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 /* We have to make sure that this is not an alias with the
56 same interface number. */
57 if (p
->if_index
== if_nametoindex (buf
))
59 printf ("%10s", result
? "fail" : "okay");
63 if_freenameindex (idx
);
64 return failures
? 1 : 0;