]> git.ipfire.org Git - thirdparty/glibc.git/blame - inet/bug-if1.c
2004-06-19 Roland McGrath <roland@redhat.com>
[thirdparty/glibc.git] / inet / bug-if1.c
CommitLineData
5a6ae8da
UD
1/* Copyright (C) 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#include <errno.h>
21#include <limits.h>
22#include <stdio.h>
23#include <net/if.h>
24
25
26static int
27do_test (void)
28{
29 /* Get list of all interfaces. */
30 struct if_nameindex *il = if_nameindex ();
31 if (il == NULL)
32 {
33 puts ("cannot get interface list, maybe the system does not support networking; bailing out");
34 return 0;
35 }
36
37 /* Determine the highest interface number. */
38 unsigned int max = 0;
39 for (int cnt = 0; il[cnt].if_name != NULL; ++cnt)
40 if (il[cnt].if_index > max)
41 max = il[cnt].if_index;
42
43 /* Use the next higher value (if possible). */
44 if (max == UINT_MAX)
45 {
46 puts ("highest index too high; need more clever way to determine test index");
47 return 0;
48 }
49
50 char buf[IF_NAMESIZE];
51 char *cp = if_indextoname (max + 1, buf);
52 if (cp != NULL)
53 {
54 printf ("invalid index returned result \"%s\"\n", cp);
55 return 1;
56 }
57 else if (errno != ENXIO)
58 {
59 int err = errno;
60 char errbuf1[256];
61 char errbuf2[256];
62
63 printf ("errno = %d (%s), expected %d (%s)\n",
64 err, strerror_r (err, errbuf1, sizeof (errbuf1)),
65 ENXIO, strerror_r (ENXIO, errbuf2, sizeof (errbuf2)));
66 return 1;
67 }
68
69 return 0;
70}
71
72#define TEST_FUNCTION do_test ()
73#include "../test-skeleton.c"