aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 14:26:37 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 14:26:37 +0000
commit04b30ba3b88c721b81194cae9cb439ddba4712db (patch)
treec2e2d52edcb7d6834d771cfe62cabbf8e38c6134
parent3aa2d51cd6649911a84e943845237009f03efed6 (diff)
downloadbusybox-w32-04b30ba3b88c721b81194cae9cb439ddba4712db.tar.gz
busybox-w32-04b30ba3b88c721b81194cae9cb439ddba4712db.tar.bz2
busybox-w32-04b30ba3b88c721b81194cae9cb439ddba4712db.zip
ifconfig: preparatory patch, no code changes
-rw-r--r--networking/ifconfig.c84
-rw-r--r--networking/interface.c2
2 files changed, 43 insertions, 43 deletions
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 371f0fc94..c898de543 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -39,7 +39,7 @@
39#include "inet_common.h" 39#include "inet_common.h"
40#include "busybox.h" 40#include "busybox.h"
41 41
42#ifdef CONFIG_FEATURE_IFCONFIG_SLIP 42#if ENABLE_FEATURE_IFCONFIG_SLIP
43# include <net/if_slip.h> 43# include <net/if_slip.h>
44#endif 44#endif
45 45
@@ -62,7 +62,7 @@
62# define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ 62# define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
63#endif 63#endif
64 64
65#ifdef CONFIG_FEATURE_IPV6 65#if ENABLE_FEATURE_IPV6
66struct in6_ifreq { 66struct in6_ifreq {
67 struct in6_addr ifr6_addr; 67 struct in6_addr ifr6_addr;
68 uint32_t ifr6_prefixlen; 68 uint32_t ifr6_prefixlen;
@@ -113,7 +113,7 @@ struct in6_ifreq {
113#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */ 113#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
114#define A_SET_AFTER 0x40 /* Set a flag at the end. */ 114#define A_SET_AFTER 0x40 /* Set a flag at the end. */
115#define A_COLON_CHK 0x80 /* Is this needed? See below. */ 115#define A_COLON_CHK 0x80 /* Is this needed? See below. */
116#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 116#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
117#define A_HOSTNAME 0x100 /* Set if it is ip addr. */ 117#define A_HOSTNAME 0x100 /* Set if it is ip addr. */
118#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */ 118#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
119#else 119#else
@@ -170,7 +170,7 @@ struct arg1opt {
170 170
171struct options { 171struct options {
172 const char *name; 172 const char *name;
173#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 173#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
174 const unsigned int flags:6; 174 const unsigned int flags:6;
175 const unsigned int arg_flags:10; 175 const unsigned int arg_flags:10;
176#else 176#else
@@ -189,7 +189,7 @@ static const struct arg1opt Arg1Opt[] = {
189 {"SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)}, 189 {"SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)},
190 {"SIOCSIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask)}, 190 {"SIOCSIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask)},
191 {"SIOCSIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr)}, 191 {"SIOCSIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr)},
192#ifdef CONFIG_FEATURE_IFCONFIG_HW 192#if ENABLE_FEATURE_IFCONFIG_HW
193 {"SIOCSIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr)}, 193 {"SIOCSIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr)},
194#endif 194#endif
195 {"SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)}, 195 {"SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)},
@@ -199,13 +199,13 @@ static const struct arg1opt Arg1Opt[] = {
199#ifdef SIOCSOUTFILL 199#ifdef SIOCSOUTFILL
200 {"SIOCSOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data)}, 200 {"SIOCSOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data)},
201#endif 201#endif
202#ifdef CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 202#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
203 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start)}, 203 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start)},
204 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr)}, 204 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr)},
205 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq)}, 205 {"SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq)},
206#endif 206#endif
207 /* Last entry if for unmatched (possibly hostname) arg. */ 207 /* Last entry if for unmatched (possibly hostname) arg. */
208#ifdef CONFIG_FEATURE_IPV6 208#if ENABLE_FEATURE_IPV6
209 {"SIOCSIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */ 209 {"SIOCSIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */
210 {"SIOCDIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */ 210 {"SIOCDIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */
211#endif 211#endif
@@ -219,7 +219,7 @@ static const struct options OptArray[] = {
219 {"dstaddr", N_ARG, ARG_DSTADDR, 0}, 219 {"dstaddr", N_ARG, ARG_DSTADDR, 0},
220 {"netmask", N_ARG, ARG_NETMASK, 0}, 220 {"netmask", N_ARG, ARG_NETMASK, 0},
221 {"broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST}, 221 {"broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST},
222#ifdef CONFIG_FEATURE_IFCONFIG_HW 222#if ENABLE_FEATURE_IFCONFIG_HW
223 {"hw", N_ARG, ARG_HW, 0}, 223 {"hw", N_ARG, ARG_HW, 0},
224#endif 224#endif
225 {"pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT}, 225 {"pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT},
@@ -229,12 +229,12 @@ static const struct options OptArray[] = {
229#ifdef SIOCSOUTFILL 229#ifdef SIOCSOUTFILL
230 {"outfill", N_ARG, ARG_OUTFILL, 0}, 230 {"outfill", N_ARG, ARG_OUTFILL, 0},
231#endif 231#endif
232#ifdef CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 232#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
233 {"mem_start", N_ARG, ARG_MEM_START, 0}, 233 {"mem_start", N_ARG, ARG_MEM_START, 0},
234 {"io_addr", N_ARG, ARG_IO_ADDR, 0}, 234 {"io_addr", N_ARG, ARG_IO_ADDR, 0},
235 {"irq", N_ARG, ARG_IRQ, 0}, 235 {"irq", N_ARG, ARG_IRQ, 0},
236#endif 236#endif
237#ifdef CONFIG_FEATURE_IPV6 237#if ENABLE_FEATURE_IPV6
238 {"add", N_ARG, ARG_ADD_DEL, 0}, 238 {"add", N_ARG, ARG_ADD_DEL, 0},
239 {"del", N_ARG, ARG_ADD_DEL, 0}, 239 {"del", N_ARG, ARG_ADD_DEL, 0},
240#endif 240#endif
@@ -253,11 +253,11 @@ static const struct options OptArray[] = {
253 * A couple of prototypes. 253 * A couple of prototypes.
254 */ 254 */
255 255
256#ifdef CONFIG_FEATURE_IFCONFIG_HW 256#if ENABLE_FEATURE_IFCONFIG_HW
257static int in_ether(char *bufp, struct sockaddr *sap); 257static int in_ether(const char *bufp, struct sockaddr *sap);
258#endif 258#endif
259 259
260#ifdef CONFIG_FEATURE_IFCONFIG_STATUS 260#if ENABLE_FEATURE_IFCONFIG_STATUS
261extern int interface_opt_a; 261extern int interface_opt_a;
262extern int display_interfaces(char *ifname); 262extern int display_interfaces(char *ifname);
263#endif 263#endif
@@ -270,10 +270,10 @@ int ifconfig_main(int argc, char **argv)
270{ 270{
271 struct ifreq ifr; 271 struct ifreq ifr;
272 struct sockaddr_in sai; 272 struct sockaddr_in sai;
273#ifdef CONFIG_FEATURE_IPV6 273#if ENABLE_FEATURE_IPV6
274 struct sockaddr_in6 sai6; 274 struct sockaddr_in6 sai6;
275#endif 275#endif
276#ifdef CONFIG_FEATURE_IFCONFIG_HW 276#if ENABLE_FEATURE_IFCONFIG_HW
277 struct sockaddr sa; 277 struct sockaddr sa;
278#endif 278#endif
279 const struct arg1opt *a1op; 279 const struct arg1opt *a1op;
@@ -281,7 +281,7 @@ int ifconfig_main(int argc, char **argv)
281 int sockfd; /* socket fd we use to manipulate stuff with */ 281 int sockfd; /* socket fd we use to manipulate stuff with */
282 int goterr; 282 int goterr;
283 int selector; 283 int selector;
284#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 284#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
285 unsigned int mask; 285 unsigned int mask;
286 unsigned int did_flags; 286 unsigned int did_flags;
287 unsigned int sai_hostname, sai_netmask; 287 unsigned int sai_hostname, sai_netmask;
@@ -294,7 +294,7 @@ int ifconfig_main(int argc, char **argv)
294 294
295 goterr = 0; 295 goterr = 0;
296 did_flags = 0; 296 did_flags = 0;
297#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 297#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
298 sai_hostname = 0; 298 sai_hostname = 0;
299 sai_netmask = 0; 299 sai_netmask = 0;
300#endif 300#endif
@@ -303,7 +303,7 @@ int ifconfig_main(int argc, char **argv)
303 ++argv; 303 ++argv;
304 --argc; 304 --argc;
305 305
306#ifdef CONFIG_FEATURE_IFCONFIG_STATUS 306#if ENABLE_FEATURE_IFCONFIG_STATUS
307 if ((argc > 0) && (((*argv)[0] == '-') && ((*argv)[1] == 'a') && !(*argv)[2])) { 307 if ((argc > 0) && (((*argv)[0] == '-') && ((*argv)[1] == 'a') && !(*argv)[2])) {
308 interface_opt_a = 1; 308 interface_opt_a = 1;
309 --argc; 309 --argc;
@@ -312,11 +312,10 @@ int ifconfig_main(int argc, char **argv)
312#endif 312#endif
313 313
314 if (argc <= 1) { 314 if (argc <= 1) {
315#ifdef CONFIG_FEATURE_IFCONFIG_STATUS 315#if ENABLE_FEATURE_IFCONFIG_STATUS
316 return display_interfaces(argc ? *argv : NULL); 316 return display_interfaces(argc ? *argv : NULL);
317#else 317#else
318 bb_error_msg_and_die 318 bb_error_msg_and_die("no support for status display");
319 ("ifconfig was not compiled with interface status display support.");
320#endif 319#endif
321 } 320 }
322 321
@@ -336,7 +335,8 @@ int ifconfig_main(int argc, char **argv)
336 } 335 }
337 for (op = OptArray; op->name; op++) { /* Find table entry. */ 336 for (op = OptArray; op->name; op++) { /* Find table entry. */
338 if (strcmp(p, op->name) == 0) { /* If name matches... */ 337 if (strcmp(p, op->name) == 0) { /* If name matches... */
339 if ((mask &= op->flags)) { /* set the mask and go. */ 338 mask &= op->flags;
339 if (mask) { /* set the mask and go. */
340 goto FOUND_ARG; 340 goto FOUND_ARG;
341 } 341 }
342 /* If we get here, there was a valid arg with an */ 342 /* If we get here, there was a valid arg with an */
@@ -351,7 +351,7 @@ int ifconfig_main(int argc, char **argv)
351 mask = op->arg_flags; 351 mask = op->arg_flags;
352 goto HOSTNAME; 352 goto HOSTNAME;
353 353
354 FOUND_ARG: 354 FOUND_ARG:
355 if (mask & ARG_MASK) { 355 if (mask & ARG_MASK) {
356 mask = op->arg_flags; 356 mask = op->arg_flags;
357 a1op = Arg1Opt + (op - OptArray); 357 a1op = Arg1Opt + (op - OptArray);
@@ -366,19 +366,19 @@ int ifconfig_main(int argc, char **argv)
366 mask &= A_SET_AFTER; /* just for broadcast */ 366 mask &= A_SET_AFTER; /* just for broadcast */
367 } 367 }
368 } else { /* got an arg so process it */ 368 } else { /* got an arg so process it */
369 HOSTNAME: 369 HOSTNAME:
370 did_flags |= (mask & (A_NETMASK|A_HOSTNAME)); 370 did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
371 if (mask & A_CAST_HOST_COPY) { 371 if (mask & A_CAST_HOST_COPY) {
372#ifdef CONFIG_FEATURE_IFCONFIG_HW 372#if ENABLE_FEATURE_IFCONFIG_HW
373 if (mask & A_CAST_RESOLVE) { 373 if (mask & A_CAST_RESOLVE) {
374#endif 374#endif
375#ifdef CONFIG_FEATURE_IPV6 375#if ENABLE_FEATURE_IPV6
376 char *prefix; 376 char *prefix;
377 int prefix_len = 0; 377 int prefix_len = 0;
378#endif 378#endif
379 379
380 safe_strncpy(host, *argv, (sizeof host)); 380 safe_strncpy(host, *argv, (sizeof host));
381#ifdef CONFIG_FEATURE_IPV6 381#if ENABLE_FEATURE_IPV6
382 prefix = strchr(host, '/'); 382 prefix = strchr(host, '/');
383 if (prefix) { 383 if (prefix) {
384 if (safe_strtoi(prefix + 1, &prefix_len) || 384 if (safe_strtoi(prefix + 1, &prefix_len) ||
@@ -396,13 +396,13 @@ int ifconfig_main(int argc, char **argv)
396 if (!strcmp(host, bb_INET_default)) { 396 if (!strcmp(host, bb_INET_default)) {
397 /* Default is special, meaning 0.0.0.0. */ 397 /* Default is special, meaning 0.0.0.0. */
398 sai.sin_addr.s_addr = INADDR_ANY; 398 sai.sin_addr.s_addr = INADDR_ANY;
399#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 399#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
400 } else if (((host[0] == '+') && !host[1]) && (mask & A_BROADCAST) && 400 } else if (((host[0] == '+') && !host[1]) && (mask & A_BROADCAST) &&
401 (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)) { 401 (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)) {
402 /* + is special, meaning broadcast is derived. */ 402 /* + is special, meaning broadcast is derived. */
403 sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask); 403 sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
404#endif 404#endif
405#ifdef CONFIG_FEATURE_IPV6 405#if ENABLE_FEATURE_IPV6
406 } else if (inet_pton(AF_INET6, host, &sai6.sin6_addr) > 0) { 406 } else if (inet_pton(AF_INET6, host, &sai6.sin6_addr) > 0) {
407 int sockfd6; 407 int sockfd6;
408 struct in6_ifreq ifr6; 408 struct in6_ifreq ifr6;
@@ -430,15 +430,15 @@ int ifconfig_main(int argc, char **argv)
430#endif 430#endif
431 } else if (inet_aton(host, &sai.sin_addr) == 0) { 431 } else if (inet_aton(host, &sai.sin_addr) == 0) {
432 /* It's not a dotted quad. */ 432 /* It's not a dotted quad. */
433 struct hostent *hp; 433 struct hostent *hp = gethostbyname(host);
434 if ((hp = gethostbyname(host)) == (struct hostent *)NULL) { 434 if (!hp) {
435 ++goterr; 435 ++goterr;
436 continue; 436 continue;
437 } 437 }
438 memcpy((char *) &sai.sin_addr, (char *) hp->h_addr_list[0], 438 memcpy((char *) &sai.sin_addr, (char *) hp->h_addr_list[0],
439 sizeof(struct in_addr)); 439 sizeof(struct in_addr));
440 } 440 }
441#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS 441#if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
442 if (mask & A_HOSTNAME) { 442 if (mask & A_HOSTNAME) {
443 sai_hostname = sai.sin_addr.s_addr; 443 sai_hostname = sai.sin_addr.s_addr;
444 } 444 }
@@ -447,13 +447,13 @@ int ifconfig_main(int argc, char **argv)
447 } 447 }
448#endif 448#endif
449 p = (char *) &sai; 449 p = (char *) &sai;
450#ifdef CONFIG_FEATURE_IFCONFIG_HW 450#if ENABLE_FEATURE_IFCONFIG_HW
451 } else { /* A_CAST_HOST_COPY_IN_ETHER */ 451 } else { /* A_CAST_HOST_COPY_IN_ETHER */
452 /* This is the "hw" arg case. */ 452 /* This is the "hw" arg case. */
453 if (strcmp("ether", *argv) || (*++argv == NULL)) { 453 if (strcmp("ether", *argv) || (*++argv == NULL)) {
454 bb_show_usage(); 454 bb_show_usage();
455 } 455 }
456 safe_strncpy(host, *argv, (sizeof host)); 456 safe_strncpy(host, *argv, sizeof(host));
457 if (in_ether(host, &sa)) { 457 if (in_ether(host, &sa)) {
458 bb_error_msg("invalid hw-addr %s", host); 458 bb_error_msg("invalid hw-addr %s", host);
459 ++goterr; 459 ++goterr;
@@ -462,13 +462,13 @@ int ifconfig_main(int argc, char **argv)
462 p = (char *) &sa; 462 p = (char *) &sa;
463 } 463 }
464#endif 464#endif
465 memcpy((((char *) (&ifr)) + a1op->ifr_offset), 465 memcpy( (((char *)&ifr) + a1op->ifr_offset),
466 p, sizeof(struct sockaddr)); 466 p, sizeof(struct sockaddr));
467 } else { 467 } else {
468 unsigned long i = strtoul(*argv, NULL, 0); 468 unsigned long i = strtoul(*argv, NULL, 0);
469 469
470 p = ((char *) (&ifr)) + a1op->ifr_offset; 470 p = ((char *)&ifr) + a1op->ifr_offset;
471#ifdef CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 471#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
472 if (mask & A_MAP_TYPE) { 472 if (mask & A_MAP_TYPE) {
473 if (ioctl(sockfd, SIOCGIFMAP, &ifr) < 0) { 473 if (ioctl(sockfd, SIOCGIFMAP, &ifr) < 0) {
474 ++goterr; 474 ++goterr;
@@ -499,7 +499,7 @@ int ifconfig_main(int argc, char **argv)
499 if (mask & A_COLON_CHK) { 499 if (mask & A_COLON_CHK) {
500 /* 500 /*
501 * Don't do the set_flag() if the address is an alias with 501 * Don't do the set_flag() if the address is an alias with
502 * a - at the end, since it's deleted already! - Roman 502 * a '-' at the end, since it's deleted already! - Roman
503 * 503 *
504 * Should really use regex.h here, not sure though how well 504 * Should really use regex.h here, not sure though how well
505 * it'll go with the cross-platform support etc. 505 * it'll go with the cross-platform support etc.
@@ -540,7 +540,7 @@ int ifconfig_main(int argc, char **argv)
540 ++goterr; 540 ++goterr;
541 } 541 }
542 } 542 }
543 LOOP: 543 LOOP:
544 continue; 544 continue;
545 } /* end of while-loop */ 545 } /* end of while-loop */
546 546
@@ -548,9 +548,9 @@ int ifconfig_main(int argc, char **argv)
548 return goterr; 548 return goterr;
549} 549}
550 550
551#ifdef CONFIG_FEATURE_IFCONFIG_HW 551#if ENABLE_FEATURE_IFCONFIG_HW
552/* Input an Ethernet address and convert to binary. */ 552/* Input an Ethernet address and convert to binary. */
553static int in_ether(char *bufp, struct sockaddr *sap) 553static int in_ether(const char *bufp, struct sockaddr *sap)
554{ 554{
555 char *ptr; 555 char *ptr;
556 int i, j; 556 int i, j;
diff --git a/networking/interface.c b/networking/interface.c
index 8bbde7d43..25ff30bac 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -284,7 +284,7 @@ struct interface {
284}; 284};
285 285
286 286
287int interface_opt_a = 0; /* show all interfaces */ 287int interface_opt_a; /* show all interfaces */
288 288
289static struct interface *int_list, *int_last; 289static struct interface *int_list, *int_last;
290static int skfd = -1; /* generic raw socket desc. */ 290static int skfd = -1; /* generic raw socket desc. */