Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/networking/libiproute/ll_map.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/networking/libiproute/ll_map.c
r1765 r2725 1 1 /* vi: set sw=4 ts=4: */ 2 2 /* 3 * ll_map.c 3 * This program is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU General Public License 5 * as published by the Free Software Foundation; either version 6 * 2 of the License, or (at your option) any later version. 4 7 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 8 * 2 of the License, or (at your option) any later version. 9 * 10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 11 * 8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 12 9 */ 13 10 14 #include <net/if.h> 11 #include <net/if.h> /* struct ifreq and co. */ 15 12 16 13 #include "libbb.h" … … 28 25 }; 29 26 30 static struct idxmap * idxmap[16];27 static struct idxmap **idxmap; /* treat as *idxmap[16] */ 31 28 32 29 static struct idxmap *find_by_index(int idx) … … 34 31 struct idxmap *im; 35 32 36 for (im = idxmap[idx & 0xF]; im; im = im->next) 37 if (im->index == idx) 38 return im; 33 if (idxmap) 34 for (im = idxmap[idx & 0xF]; im; im = im->next) 35 if (im->index == idx) 36 return im; 39 37 return NULL; 40 38 } 41 39 42 int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) 40 int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM, 41 struct nlmsghdr *n, 42 void *arg UNUSED_PARAM) 43 43 { 44 44 int h; … … 58 58 return 0; 59 59 60 if (!idxmap) 61 idxmap = xzalloc(sizeof(idxmap[0]) * 16); 62 60 63 h = ifi->ifi_index & 0xF; 61 62 64 for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) 63 65 if (im->index == ifi->ifi_index) … … 74 76 int alen; 75 77 im->alen = alen = RTA_PAYLOAD(tb[IFLA_ADDRESS]); 76 if (alen > sizeof(im->addr))78 if (alen > (int)sizeof(im->addr)) 77 79 alen = sizeof(im->addr); 78 80 memcpy(im->addr, RTA_DATA(tb[IFLA_ADDRESS]), alen); … … 85 87 } 86 88 87 const char *ll_idx_n2a(int idx, char *buf)89 const char FAST_FUNC *ll_idx_n2a(int idx, char *buf) 88 90 { 89 91 struct idxmap *im; … … 99 101 100 102 101 const char *ll_index_to_name(int idx)103 const char FAST_FUNC *ll_index_to_name(int idx) 102 104 { 103 105 static char nbuf[16]; … … 120 122 #endif 121 123 122 unsigned ll_index_to_flags(int idx)124 unsigned FAST_FUNC ll_index_to_flags(int idx) 123 125 { 124 126 struct idxmap *im; … … 132 134 } 133 135 134 int xll_name_to_index(const char *constname)136 int FAST_FUNC xll_name_to_index(const char *name) 135 137 { 136 138 int ret = 0; … … 151 153 goto out; 152 154 } 153 for (i = 0; i < 16; i++) { 154 for (im = idxmap[i]; im; im = im->next) { 155 if (strcmp(im->name, name) == 0) { 156 icache = im->index; 157 strcpy(ncache, name); 158 ret = im->index; 159 goto out; 155 if (idxmap) { 156 for (i = 0; i < 16; i++) { 157 for (im = idxmap[i]; im; im = im->next) { 158 if (strcmp(im->name, name) == 0) { 159 icache = im->index; 160 strcpy(ncache, name); 161 ret = im->index; 162 goto out; 163 } 160 164 } 161 165 } … … 171 175 172 176 sock_fd = socket(AF_INET, SOCK_DGRAM, 0); 173 if (sock_fd ) {177 if (sock_fd >= 0) { 174 178 struct ifreq ifr; 175 179 int tmp; 176 180 177 strncpy (ifr.ifr_name, name, IFNAMSIZ);181 strncpy_IFNAMSIZ(ifr.ifr_name, name); 178 182 ifr.ifr_ifindex = -1; 179 183 tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); … … 187 191 /* out:*/ 188 192 if (ret <= 0) 189 bb_error_msg_and_die("can not find device \"%s\"", name);193 bb_error_msg_and_die("can't find device '%s'", name); 190 194 return ret; 191 195 } 192 196 193 int ll_init_map(struct rtnl_handle *rth)197 int FAST_FUNC ll_init_map(struct rtnl_handle *rth) 194 198 { 195 199 xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK); 196 xrtnl_dump_filter(rth, ll_remember_index, &idxmap);200 xrtnl_dump_filter(rth, ll_remember_index, NULL); 197 201 return 0; 198 202 }
Note:
See TracChangeset
for help on using the changeset viewer.