summaryrefslogtreecommitdiff
path: root/networking/libiproute/ll_map.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2007-04-12 11:34:39 +0000
committerBernhard Reutner-Fischer2007-04-12 11:34:39 +0000
commitb290889f0265e1278e8a868aa82a65bcc9099b0f (patch)
tree2fc8dcc3b7f525f61817417e32c2827b57e17b8a /networking/libiproute/ll_map.c
parent51742f4bb0c57a4d5063ece9437a2f34a42e52c8 (diff)
downloadbusybox-b290889f0265e1278e8a868aa82a65bcc9099b0f.zip
busybox-b290889f0265e1278e8a868aa82a65bcc9099b0f.tar.gz
- add xsendto and use where appropriate; shrink iplink; sanitize libiproute a bit.
-916 byte
Diffstat (limited to 'networking/libiproute/ll_map.c')
-rw-r--r--networking/libiproute/ll_map.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c
index a8fcd7f..e9a1616 100644
--- a/networking/libiproute/ll_map.c
+++ b/networking/libiproute/ll_map.c
@@ -128,7 +128,7 @@ unsigned ll_index_to_flags(int idx)
}
// TODO: caching is not warranted - no users which repeatedly call it
-int ll_name_to_index(char *name)
+int xll_name_to_index(const char * const name)
{
static char ncache[16];
static int icache;
@@ -136,17 +136,21 @@ int ll_name_to_index(char *name)
struct idxmap *im;
int sock_fd;
int i;
+ int ret = 0;
if (name == NULL)
- return 0;
- if (icache && strcmp(name, ncache) == 0)
- return icache;
+ goto out;
+ if (icache && strcmp(name, ncache) == 0) {
+ ret = icache;
+ goto out;
+ }
for (i = 0; i < 16; i++) {
for (im = idxmap[i]; im; im = im->next) {
if (strcmp(im->name, name) == 0) {
icache = im->index;
strcpy(ncache, name);
- return im->index;
+ ret = im->index;
+ goto out;
}
}
}
@@ -160,29 +164,26 @@ int ll_name_to_index(char *name)
sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sock_fd) {
struct ifreq ifr;
- int ret;
+ int tmp;
strncpy(ifr.ifr_name, name, IFNAMSIZ);
ifr.ifr_ifindex = -1;
- ret = ioctl(sock_fd, SIOCGIFINDEX, &ifr);
+ tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr);
close(sock_fd);
- if (ret >= 0)
+ 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 */
- return ifr.ifr_ifindex;
+ ret = ifr.ifr_ifindex;
}
-
- return 0;
+out:
+ if (ret <= 0)
+ bb_error_msg_and_die("cannot find device \"%s\"", name);
+ return ret;
}
int ll_init_map(struct rtnl_handle *rth)
{
- if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) {
- bb_perror_msg_and_die("cannot send dump request");
- }
-
- if (rtnl_dump_filter(rth, ll_remember_index, &idxmap, NULL, NULL) < 0) {
- bb_error_msg_and_die("dump terminated");
- }
+ xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK);
+ xrtnl_dump_filter(rth, ll_remember_index, &idxmap);
return 0;
}