libiproute: handle table ids larger than 255
[oweals/busybox.git] / networking / libiproute / ll_map.c
index feb6e8d22ae3c9e961f1d3fee1c6dee6da861d89..af9eb46f7e542d704fda89cc8a7a31e51b8e7bab 100644 (file)
@@ -86,7 +86,8 @@ int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM,
        return 0;
 }
 
-const char FAST_FUNC *ll_idx_n2a(int idx, char *buf)
+static
+const char FAST_FUNC *ll_idx_n2a(int idx/*, char *buf*/)
 {
        struct idxmap *im;
 
@@ -95,15 +96,15 @@ const char FAST_FUNC *ll_idx_n2a(int idx, char *buf)
        im = find_by_index(idx);
        if (im)
                return im->name;
-       snprintf(buf, 16, "if%d", idx);
-       return buf;
+       //snprintf(buf, 16, "if%d", idx);
+       //return buf;
+       return auto_string(xasprintf("if%d", idx));
 }
 
 const char FAST_FUNC *ll_index_to_name(int idx)
 {
-       static char nbuf[16];
-
-       return ll_idx_n2a(idx, nbuf);
+       //static char nbuf[16];
+       return ll_idx_n2a(idx/*, nbuf*/);
 }
 
 #ifdef UNUSED
@@ -135,7 +136,6 @@ unsigned FAST_FUNC ll_index_to_flags(int idx)
 int FAST_FUNC xll_name_to_index(const char *name)
 {
        int ret = 0;
-       int sock_fd;
 
 /* caching is not warranted - no users which repeatedly call it */
 #ifdef UNUSED
@@ -163,30 +163,8 @@ int FAST_FUNC xll_name_to_index(const char *name)
                        }
                }
        }
-       /* We have not found the interface in our cache, but the kernel
-        * may still know about it. One reason is that we may be using
-        * module on-demand loading, which means that the kernel will
-        * load the module and make the interface exist only when
-        * we explicitely request it (check for dev_load() in net/core/dev.c).
-        * I can think of other similar scenario, but they are less common...
-        * Jean II */
 #endif
-
-       sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
-       if (sock_fd >= 0) {
-               struct ifreq ifr;
-               int tmp;
-
-               strncpy_IFNAMSIZ(ifr.ifr_name, name);
-               ifr.ifr_ifindex = -1;
-               tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr);
-               close(sock_fd);
-               if (tmp >= 0)
-                       /* In theory, we should redump the interface list
-                        * to update our cache, this is left as an exercise
-                        * to the reader... Jean II */
-                       ret = ifr.ifr_ifindex;
-       }
+       ret = if_nametoindex(name);
 /* out:*/
        if (ret <= 0)
                bb_error_msg_and_die("can't find device '%s'", name);