diff options
author | Ron Yorston <rmy@pobox.com> | 2015-10-21 16:57:25 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-24 22:04:36 +0200 |
commit | 8814431aca695a43b2e164a6620ea0a3274ce678 (patch) | |
tree | ae0b3f470b296ceea659d490d90ff77d50145306 | |
parent | 6d777b75ed322ea5ef0d1674ddfee1b5713cb04f (diff) | |
download | busybox-w32-8814431aca695a43b2e164a6620ea0a3274ce678.tar.gz busybox-w32-8814431aca695a43b2e164a6620ea0a3274ce678.tar.bz2 busybox-w32-8814431aca695a43b2e164a6620ea0a3274ce678.zip |
libiproute: use if_nametoindex
Saves 87 bytes. Assuming, of course, all platforms have it.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/libiproute/ll_map.c | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c index e2b85fc7b..af9eb46f7 100644 --- a/networking/libiproute/ll_map.c +++ b/networking/libiproute/ll_map.c | |||
@@ -136,7 +136,6 @@ unsigned FAST_FUNC ll_index_to_flags(int idx) | |||
136 | int FAST_FUNC xll_name_to_index(const char *name) | 136 | int FAST_FUNC xll_name_to_index(const char *name) |
137 | { | 137 | { |
138 | int ret = 0; | 138 | int ret = 0; |
139 | int sock_fd; | ||
140 | 139 | ||
141 | /* caching is not warranted - no users which repeatedly call it */ | 140 | /* caching is not warranted - no users which repeatedly call it */ |
142 | #ifdef UNUSED | 141 | #ifdef UNUSED |
@@ -164,30 +163,8 @@ int FAST_FUNC xll_name_to_index(const char *name) | |||
164 | } | 163 | } |
165 | } | 164 | } |
166 | } | 165 | } |
167 | /* We have not found the interface in our cache, but the kernel | ||
168 | * may still know about it. One reason is that we may be using | ||
169 | * module on-demand loading, which means that the kernel will | ||
170 | * load the module and make the interface exist only when | ||
171 | * we explicitely request it (check for dev_load() in net/core/dev.c). | ||
172 | * I can think of other similar scenario, but they are less common... | ||
173 | * Jean II */ | ||
174 | #endif | 166 | #endif |
175 | 167 | ret = if_nametoindex(name); | |
176 | sock_fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
177 | if (sock_fd >= 0) { | ||
178 | struct ifreq ifr; | ||
179 | int tmp; | ||
180 | |||
181 | strncpy_IFNAMSIZ(ifr.ifr_name, name); | ||
182 | ifr.ifr_ifindex = -1; | ||
183 | tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); | ||
184 | close(sock_fd); | ||
185 | if (tmp >= 0) | ||
186 | /* In theory, we should redump the interface list | ||
187 | * to update our cache, this is left as an exercise | ||
188 | * to the reader... Jean II */ | ||
189 | ret = ifr.ifr_ifindex; | ||
190 | } | ||
191 | /* out:*/ | 168 | /* out:*/ |
192 | if (ret <= 0) | 169 | if (ret <= 0) |
193 | bb_error_msg_and_die("can't find device '%s'", name); | 170 | bb_error_msg_and_die("can't find device '%s'", name); |