]> sourceware.org Git - glibc.git/blame - inet/test_ifindex.c
Sparc string routines from Jakub.
[glibc.git] / inet / test_ifindex.c
CommitLineData
8f2ece69
UD
1/* Test interface name <-> index conversions.
2 Copyright (C) 1997 Free Software Foundation, Inc.
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
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
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
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include <errno.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <net/if.h>
26
27int
28main (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 /* The function is simply not implemented. */
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];
9a0a462c
UD
48 unsigned int ni;
49 int result;
8f2ece69
UD
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)));
9756dfe1
UD
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))
58 result = 0;
8f2ece69
UD
59 printf ("%10s", result ? "fail" : "okay");
60 printf ("\n");
61 failures += result;
62 }
63 if_freenameindex (idx);
64 exit (failures ? 1 : 0);
65}
This page took 0.061288 seconds and 5 git commands to generate.