diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-01 02:32:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-01 02:32:23 +0000 |
commit | cfe2936a73a286aee8f8b0336212e996ad4d9f95 (patch) | |
tree | eb53675c656475ac02a2ce12f0709a371511d570 /networking/nameif.c | |
parent | 9ef1a5ddc1710ab68a654d5f010f22d3bbe0e947 (diff) | |
download | busybox-w32-cfe2936a73a286aee8f8b0336212e996ad4d9f95.tar.gz busybox-w32-cfe2936a73a286aee8f8b0336212e996ad4d9f95.tar.bz2 busybox-w32-cfe2936a73a286aee8f8b0336212e996ad4d9f95.zip |
nameif: shrink (by Vladimir)
function old new delta
nameif_main 668 636 -32
Diffstat (limited to '')
-rw-r--r-- | networking/nameif.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/networking/nameif.c b/networking/nameif.c index 12c08f13b..75829fac3 100644 --- a/networking/nameif.c +++ b/networking/nameif.c | |||
@@ -136,13 +136,11 @@ int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
136 | int nameif_main(int argc, char **argv) | 136 | int nameif_main(int argc, char **argv) |
137 | { | 137 | { |
138 | ethtable_t *clist = NULL; | 138 | ethtable_t *clist = NULL; |
139 | FILE *ifh; | ||
140 | const char *fname = "/etc/mactab"; | 139 | const char *fname = "/etc/mactab"; |
141 | char *line; | ||
142 | char *line_ptr; | ||
143 | int linenum; | ||
144 | int ctl_sk; | 140 | int ctl_sk; |
145 | ethtable_t *ch; | 141 | ethtable_t *ch; |
142 | parser_t *parser; | ||
143 | char *token[2]; | ||
146 | 144 | ||
147 | if (1 & getopt32(argv, "sc:", &fname)) { | 145 | if (1 & getopt32(argv, "sc:", &fname)) { |
148 | openlog(applet_name, 0, LOG_LOCAL0); | 146 | openlog(applet_name, 0, LOG_LOCAL0); |
@@ -160,35 +158,26 @@ int nameif_main(int argc, char **argv) | |||
160 | prepend_new_eth_table(&clist, ifname, *argv++); | 158 | prepend_new_eth_table(&clist, ifname, *argv++); |
161 | } | 159 | } |
162 | } else { | 160 | } else { |
163 | char *tokens[2]; | 161 | parser = config_open(fname); |
164 | struct parser_t *parser = config_open(fname); | 162 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) |
165 | while (config_read(parser, tokens, 2, 2, "# \t", PARSE_NORMAL)) | 163 | prepend_new_eth_table(&clist, token[0], token[1]); |
166 | prepend_new_eth_table(&clist, tokens[0], tokens[1]); | ||
167 | config_close(parser); | 164 | config_close(parser); |
168 | } | 165 | } |
169 | 166 | ||
170 | ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); | 167 | ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); |
171 | ifh = xfopen_for_read("/proc/net/dev"); | 168 | parser = config_open2("/proc/net/dev", xfopen_for_read); |
172 | 169 | ||
173 | linenum = 0; | 170 | while (clist && config_read(parser, token, 2, 2, "\0: \t", PARSE_NORMAL)) { |
174 | while (clist) { | ||
175 | struct ifreq ifr; | 171 | struct ifreq ifr; |
176 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 172 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
177 | struct ethtool_drvinfo drvinfo; | 173 | struct ethtool_drvinfo drvinfo; |
178 | #endif | 174 | #endif |
179 | 175 | if (parser->lineno < 2) | |
180 | line = xmalloc_fgets(ifh); | 176 | continue; /* Skip the first two lines */ |
181 | if (line == NULL) | ||
182 | break; /* Seems like we're done */ | ||
183 | if (linenum++ < 2 ) | ||
184 | goto next_line; /* Skip the first two lines */ | ||
185 | 177 | ||
186 | /* Find the current interface name and copy it to ifr.ifr_name */ | 178 | /* Find the current interface name and copy it to ifr.ifr_name */ |
187 | line_ptr = skip_whitespace(line); | ||
188 | *strpbrk(line_ptr, " \t\n:") = '\0'; | ||
189 | |||
190 | memset(&ifr, 0, sizeof(struct ifreq)); | 179 | memset(&ifr, 0, sizeof(struct ifreq)); |
191 | strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name)); | 180 | strncpy(ifr.ifr_name, token[0], sizeof(ifr.ifr_name)); |
192 | 181 | ||
193 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 182 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
194 | /* Check for driver etc. */ | 183 | /* Check for driver etc. */ |
@@ -211,11 +200,12 @@ int nameif_main(int argc, char **argv) | |||
211 | if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0) | 200 | if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0) |
212 | continue; | 201 | continue; |
213 | /* if we came here, all selectors have matched */ | 202 | /* if we came here, all selectors have matched */ |
214 | goto found; | 203 | break; |
215 | } | 204 | } |
216 | /* Nothing found for current interface */ | 205 | /* Nothing found for current interface */ |
217 | goto next_line; | 206 | if (!ch) |
218 | found: | 207 | continue; |
208 | |||
219 | if (strcmp(ifr.ifr_name, ch->ifname) != 0) { | 209 | if (strcmp(ifr.ifr_name, ch->ifname) != 0) { |
220 | strcpy(ifr.ifr_newname, ch->ifname); | 210 | strcpy(ifr.ifr_newname, ch->ifname); |
221 | ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr, | 211 | ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr, |
@@ -228,16 +218,14 @@ int nameif_main(int argc, char **argv) | |||
228 | else | 218 | else |
229 | clist = ch->next; | 219 | clist = ch->next; |
230 | if (ch->next != NULL) | 220 | if (ch->next != NULL) |
231 | ch->next->prev = ch->prev; | 221 | ch->next->prev = ch->prev; |
232 | if (ENABLE_FEATURE_CLEAN_UP) | 222 | if (ENABLE_FEATURE_CLEAN_UP) |
233 | delete_eth_table(ch); | 223 | delete_eth_table(ch); |
234 | next_line: | ||
235 | free(line); | ||
236 | } | 224 | } |
237 | if (ENABLE_FEATURE_CLEAN_UP) { | 225 | if (ENABLE_FEATURE_CLEAN_UP) { |
238 | for (ch = clist; ch; ch = ch->next) | 226 | for (ch = clist; ch; ch = ch->next) |
239 | delete_eth_table(ch); | 227 | delete_eth_table(ch); |
240 | fclose(ifh); | 228 | config_close(parser); |
241 | }; | 229 | }; |
242 | 230 | ||
243 | return 0; | 231 | return 0; |