summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/if_index.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-06-07 00:02:14 +0000
committerUlrich Drepper <drepper@redhat.com>1999-06-07 00:02:14 +0000
commit9a8fcca0b33c26759134a545ac45251df53418a3 (patch)
tree981351d75ac1c612d7f356b0438ec5f1a3227c12 /sysdeps/unix/sysv/linux/if_index.c
parente0082312bcfdce398099d58add30cc02b79f129b (diff)
Update.
* sysdeps/unix/sysv/linux/kernel-features.h: Define __ASSUME_SIOCGIFNAME for kernel >= 2.1.50. * sysdeps/unix/sysv/linux/if_index.c: Correct typo (SIOGIFNAME -> SIOCGIFNAME) and use __ASSUME_SIOCGIFNAME. * sysdeps/libm-ieee754/w_j0.c: Remove __ from symbol definitions. * sysdeps/libm-ieee754/w_j0f.c: Likewise. * sysdeps/libm-ieee754/w_j0l.c: Likewise. * sysdeps/libm-ieee754/w_j1.c: Likewise. * sysdeps/libm-ieee754/w_j1f.c: Likewise. * sysdeps/libm-ieee754/w_j1l.c: Likewise. * sysdeps/libm-ieee754/w_jn.c: Likewise. * sysdeps/libm-ieee754/w_jnf.c: Likewise. * sysdeps/libm-ieee754/w_jnl.c: Likewise. * stdio-common.c: Correct typos. * math/libm-test.c (jn_test): Adjust delta. (y1_test): Likewise. (yn_test): Likewise. * elf/do-lookup.h: It should never happen that if we expect a versioned symbol from a file the file has no version table. This should have been checked in dl-version.c. * elf/dl-lookup.c: Include assert.h.
Diffstat (limited to 'sysdeps/unix/sysv/linux/if_index.c')
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index 9b3db6abfb..67fba93cd4 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -26,6 +26,8 @@
#include <sys/ioctl.h>
#include <bits/libc-lock.h>
+#include "kernel-features.h"
+
/* Try to get a socket to talk to the kernel. */
#if defined SIOGIFINDEX || defined SIOGIFNAME
static int
@@ -120,8 +122,12 @@ if_nameindex (void)
unsigned int nifs, i;
int rq_len;
struct if_nameindex *idx = NULL;
+# if __ASSUME_SIOCGIFNAME == 0
static int old_siocgifconf;
-#define RQ_IFS 4
+# else
+# define old_siocgifconf 0
+# endif
+# define RQ_IFS 4
if (fd < 0)
return NULL;
@@ -136,7 +142,9 @@ if_nameindex (void)
ifc.ifc_len = 0;
if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
{
+# if __ASSUME_SIOCGIFNAME == 0
old_siocgifconf = 1;
+# endif
rq_len = RQ_IFS * sizeof (struct ifreq);
}
else
@@ -199,24 +207,31 @@ if_nameindex (void)
char *
if_indextoname (unsigned int ifindex, char *ifname)
{
-#ifndef SIOGIFINDEX
+#if !defined SIOGIFINDEX && __ASSUME_SIOCGIFNAME == 0
__set_errno (ENOSYS);
return NULL;
#else
+# if __ASSUME_SIOCGIFNAME == 0
struct if_nameindex *idx;
struct if_nameindex *p;
char *result = NULL;
+# endif
-#ifdef SIOGIFNAME
+# if defined SIOCGIFNAME || __ASSUME_SIOCGIFNAME > 0
/* We may be able to do the conversion directly, rather than searching a
list. This ioctl is not present in kernels before version 2.1.50. */
struct ifreq ifr;
int fd;
- static int siogifname_works_not;
+# if __ASSUME_SIOCGIFNAME == 0
+ static int siocgifname_works_not;
- if (!siogifname_works_not)
+ if (!siocgifname_works_not)
+# endif
{
+# if __ASSUME_SIOCGIFNAME == 0
int serrno = errno;
+# endif
+ int status;
fd = opensock ();
@@ -224,23 +239,27 @@ if_indextoname (unsigned int ifindex, char *ifname)
return NULL;
ifr.ifr_ifindex = ifindex;
- if (__ioctl (fd, SIOGIFNAME, &ifr) < 0)
+ status = __ioctl (fd, SIOCGIFNAME, &ifr);
+
+ __close (fd);
+
+# if __ASSUME_SIOCGIFNAME == 0
+ if (status < 0)
{
if (errno == EINVAL)
- siogifname_works_not = 1; /* Don't make the same mistake twice. */
+ siocgifname_works_not = 1; /* Don't make the same mistake twice. */
}
else
- {
- __close (fd);
- return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
- }
-
- __close (fd);
+ return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
__set_errno (serrno);
+# else
+ return status < 0 ? NULL : strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
+# endif
}
-#endif
+# endif
+# if __ASSUME_SIOCGIFNAME == 0
idx = if_nameindex ();
if (idx != NULL)
@@ -255,5 +274,6 @@ if_indextoname (unsigned int ifindex, char *ifname)
if_freenameindex (idx);
}
return result;
+# endif
#endif
}