From 0de70f2020c1820d6c46e993fd8a5c4c309c8648 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Sat, 12 Jun 2004 08:41:18 +0000 Subject: Stephen Hemminger from osdl dot org writes: Rather than copy more code back into the bridge-utilities, how about applying this change to uClibc? I hate when packages get cluttered for workarounds for other incompatibilities. The problem is that SIOCGIFCONF only lists interfaces that have IP addresses, so it doesn't find the other interfaces that are being used for bridging. It could be fixed in the kernel to return all interfaces, but then something else might break; and still it mean a kernel update for the 2.4 users. The whole use of ifindex in the bridge API is a bad idea. But we probably have to live with it for compatibility. Patch against uClibc 0.9.26 --- libc/inet/if_nametoindex.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libc/inet/if_nametoindex.c b/libc/inet/if_nametoindex.c index a697419b6..45b319f97 100644 --- a/libc/inet/if_nametoindex.c +++ b/libc/inet/if_nametoindex.c @@ -148,6 +148,27 @@ struct if_nameindex * if_nameindex (void) char * if_indextoname (unsigned int ifindex, char *ifname) { +#ifdef SIOCGIFNAME + /* Use ioctl to avoid searching the list. */ + struct ifreq ifr; + int fd, saved_errno; + + fd = __opensock (); + + if (fd < 0) + return NULL; + + ifr.ifr_ifindex = ifindex; + if (ioctl (fd, SIOCGIFNAME, &ifr) < 0) { + saved_errno = errno; + close (fd); + __set_errno (saved_errno); + return NULL; + } + close (fd); + + return strncpy (ifname, ifr.ifr_name, IFNAMSIZ); +#else struct if_nameindex *idx; struct if_nameindex *p; char *result = NULL; @@ -163,5 +184,6 @@ char * if_indextoname (unsigned int ifindex, char *ifname) if_freenameindex (idx); } return result; +#endif } -- cgit v1.2.3