aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-08-10 06:02:23 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-08-10 06:02:23 +0000
commit4fb0b517035ddc189bd696e3175bf18dbc37d441 (patch)
treed4a60afff2a00178ee98061428be703bd262267d
parent6c4250c0dc154cf52b49246c6b6489f5059d4192 (diff)
downloadbusybox-w32-4fb0b517035ddc189bd696e3175bf18dbc37d441.tar.gz
busybox-w32-4fb0b517035ddc189bd696e3175bf18dbc37d441.tar.bz2
busybox-w32-4fb0b517035ddc189bd696e3175bf18dbc37d441.zip
This corrects the _really_poor_ implementation of "broadcast +" handling
by ifconfig that someone had submitted. It fixes 1 bug, gets rid of the excessive bloating of a structure that is used in a static const array, and removes the implicit struct copys by keeping only the int type needed. It also turns this into a configurable feature (off by default).
-rw-r--r--Config.h6
-rw-r--r--ifconfig.c26
-rw-r--r--networking/ifconfig.c26
3 files changed, 19 insertions, 39 deletions
diff --git a/Config.h b/Config.h
index e6f5315f2..c46e2d282 100644
--- a/Config.h
+++ b/Config.h
@@ -319,7 +319,7 @@
319// Support for Minix filesystem, version 2 319// Support for Minix filesystem, version 2
320//#define BB_FEATURE_MINIX2 320//#define BB_FEATURE_MINIX2
321// 321//
322// Enable ifconfig status reporting output -- this feature adds 12k. 322// Enable ifconfig status reporting output -- this feature adds 7k.
323//#define BB_FEATURE_IFCONFIG_STATUS 323//#define BB_FEATURE_IFCONFIG_STATUS
324// 324//
325// Enable ifconfig slip-specific options "keepalive" and "outfill" 325// Enable ifconfig slip-specific options "keepalive" and "outfill"
@@ -331,6 +331,10 @@
331// Enable ifconfig option "hw". Currently works for only with "ether". 331// Enable ifconfig option "hw". Currently works for only with "ether".
332//#define BB_FEATURE_IFCONFIG_HW 332//#define BB_FEATURE_IFCONFIG_HW
333// 333//
334// Allows "broadcast +" to set broadcast automatically based on hostaddr
335// and netmask, at a cost of about 100 bytes of code (i386).
336//#define BB_FEATURE_IFCONFIG_BROADCAST_PLUS
337//
334// Enable busybox --install [-s] 338// Enable busybox --install [-s]
335// to create links (or symlinks) for all the commands that are 339// to create links (or symlinks) for all the commands that are
336// compiled into the binary. (needs /proc filesystem) 340// compiled into the binary. (needs /proc filesystem)
diff --git a/ifconfig.c b/ifconfig.c
index 7f3978a4a..c77ea04b1 100644
--- a/ifconfig.c
+++ b/ifconfig.c
@@ -15,7 +15,7 @@
15 * Foundation; either version 2 of the License, or (at 15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version. 16 * your option) any later version.
17 * 17 *
18 * $Id: ifconfig.c,v 1.11 2001/07/07 05:19:52 andersen Exp $ 18 * $Id: ifconfig.c,v 1.12 2001/08/10 06:02:23 mjn3 Exp $
19 * 19 *
20 */ 20 */
21 21
@@ -110,8 +110,6 @@
110#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */ 110#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
111#define A_SET_AFTER 0x40 /* Set a flag at the end. */ 111#define A_SET_AFTER 0x40 /* Set a flag at the end. */
112#define A_COLON_CHK 0x80 /* Is this needed? See below. */ 112#define A_COLON_CHK 0x80 /* Is this needed? See below. */
113#define A_HOSTNAME 0x100 /* Set if it is ip addr. */
114#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
115 113
116/* 114/*
117 * These defines are for dealing with the A_CAST_TYPE field. 115 * These defines are for dealing with the A_CAST_TYPE field.
@@ -141,12 +139,12 @@
141#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR) 139#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
142#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE) 140#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
143#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK) 141#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
144#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST) 142#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
145#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER) 143#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
146#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER) 144#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
147#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR) 145#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
148#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR) 146#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
149#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME) 147#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK)
150 148
151 149
152/* 150/*
@@ -162,7 +160,7 @@ struct arg1opt {
162struct options { 160struct options {
163 const char *name; 161 const char *name;
164 const unsigned char flags; 162 const unsigned char flags;
165 const unsigned int arg_flags; 163 const unsigned char arg_flags;
166 const unsigned short selector; 164 const unsigned short selector;
167}; 165};
168 166
@@ -248,7 +246,6 @@ int ifconfig_main(int argc, char **argv)
248{ 246{
249 struct ifreq ifr; 247 struct ifreq ifr;
250 struct sockaddr_in sai; 248 struct sockaddr_in sai;
251 struct sockaddr_in sai_hostname, sai_netmask;
252#ifdef BB_FEATURE_IFCONFIG_HW 249#ifdef BB_FEATURE_IFCONFIG_HW
253 struct sockaddr sa; 250 struct sockaddr sa;
254#endif 251#endif
@@ -259,8 +256,8 @@ int ifconfig_main(int argc, char **argv)
259 int selector; 256 int selector;
260 char *p; 257 char *p;
261 char host[128]; 258 char host[128];
262 unsigned int mask; 259 unsigned char mask;
263 unsigned int did_flags; 260 unsigned char did_flags;
264 261
265 goterr = 0; 262 goterr = 0;
266 did_flags = 0; 263 did_flags = 0;
@@ -334,7 +331,7 @@ int ifconfig_main(int argc, char **argv)
334 } 331 }
335 } else { /* got an arg so process it */ 332 } else { /* got an arg so process it */
336 HOSTNAME: 333 HOSTNAME:
337 did_flags |= (mask & (A_NETMASK|A_HOSTNAME)); 334 did_flags |= (mask & A_NETMASK);
338 if (mask & A_CAST_HOST_COPY) { 335 if (mask & A_CAST_HOST_COPY) {
339#ifdef BB_FEATURE_IFCONFIG_HW 336#ifdef BB_FEATURE_IFCONFIG_HW
340 if (mask & A_CAST_RESOLVE) { 337 if (mask & A_CAST_RESOLVE) {
@@ -345,20 +342,11 @@ int ifconfig_main(int argc, char **argv)
345 if (!strcmp(host, "default")) { 342 if (!strcmp(host, "default")) {
346 /* Default is special, meaning 0.0.0.0. */ 343 /* Default is special, meaning 0.0.0.0. */
347 sai.sin_addr.s_addr = INADDR_ANY; 344 sai.sin_addr.s_addr = INADDR_ANY;
348 } else if ((!strcmp(host, "+")) && (mask & A_BROADCAST) &&
349 (did_flags & (A_NETMASK|A_HOSTNAME))) {
350 /* + is special, meaning broadcast is derived. */
351 sai.sin_addr.s_addr = (~sai_netmask.sin_addr.s_addr) |
352 (sai_hostname.sin_addr.s_addr & sai_netmask.sin_addr.s_addr);
353 } else if (inet_aton(host, &sai.sin_addr) == 0) { 345 } else if (inet_aton(host, &sai.sin_addr) == 0) {
354 /* It's not a dotted quad. */ 346 /* It's not a dotted quad. */
355 ++goterr; 347 ++goterr;
356 continue; 348 continue;
357 } 349 }
358 if(mask & A_HOSTNAME)
359 sai_hostname = sai;
360 if(mask & A_NETMASK)
361 sai_netmask = sai;
362 p = (char *) &sai; 350 p = (char *) &sai;
363#ifdef BB_FEATURE_IFCONFIG_HW 351#ifdef BB_FEATURE_IFCONFIG_HW
364 } else { /* A_CAST_HOST_COPY_IN_ETHER */ 352 } else { /* A_CAST_HOST_COPY_IN_ETHER */
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 7f3978a4a..c77ea04b1 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -15,7 +15,7 @@
15 * Foundation; either version 2 of the License, or (at 15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version. 16 * your option) any later version.
17 * 17 *
18 * $Id: ifconfig.c,v 1.11 2001/07/07 05:19:52 andersen Exp $ 18 * $Id: ifconfig.c,v 1.12 2001/08/10 06:02:23 mjn3 Exp $
19 * 19 *
20 */ 20 */
21 21
@@ -110,8 +110,6 @@
110#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */ 110#define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
111#define A_SET_AFTER 0x40 /* Set a flag at the end. */ 111#define A_SET_AFTER 0x40 /* Set a flag at the end. */
112#define A_COLON_CHK 0x80 /* Is this needed? See below. */ 112#define A_COLON_CHK 0x80 /* Is this needed? See below. */
113#define A_HOSTNAME 0x100 /* Set if it is ip addr. */
114#define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
115 113
116/* 114/*
117 * These defines are for dealing with the A_CAST_TYPE field. 115 * These defines are for dealing with the A_CAST_TYPE field.
@@ -141,12 +139,12 @@
141#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR) 139#define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
142#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE) 140#define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
143#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK) 141#define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
144#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST) 142#define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
145#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER) 143#define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
146#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER) 144#define ARG_POINTOPOINT (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
147#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR) 145#define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
148#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR) 146#define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
149#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME) 147#define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK)
150 148
151 149
152/* 150/*
@@ -162,7 +160,7 @@ struct arg1opt {
162struct options { 160struct options {
163 const char *name; 161 const char *name;
164 const unsigned char flags; 162 const unsigned char flags;
165 const unsigned int arg_flags; 163 const unsigned char arg_flags;
166 const unsigned short selector; 164 const unsigned short selector;
167}; 165};
168 166
@@ -248,7 +246,6 @@ int ifconfig_main(int argc, char **argv)
248{ 246{
249 struct ifreq ifr; 247 struct ifreq ifr;
250 struct sockaddr_in sai; 248 struct sockaddr_in sai;
251 struct sockaddr_in sai_hostname, sai_netmask;
252#ifdef BB_FEATURE_IFCONFIG_HW 249#ifdef BB_FEATURE_IFCONFIG_HW
253 struct sockaddr sa; 250 struct sockaddr sa;
254#endif 251#endif
@@ -259,8 +256,8 @@ int ifconfig_main(int argc, char **argv)
259 int selector; 256 int selector;
260 char *p; 257 char *p;
261 char host[128]; 258 char host[128];
262 unsigned int mask; 259 unsigned char mask;
263 unsigned int did_flags; 260 unsigned char did_flags;
264 261
265 goterr = 0; 262 goterr = 0;
266 did_flags = 0; 263 did_flags = 0;
@@ -334,7 +331,7 @@ int ifconfig_main(int argc, char **argv)
334 } 331 }
335 } else { /* got an arg so process it */ 332 } else { /* got an arg so process it */
336 HOSTNAME: 333 HOSTNAME:
337 did_flags |= (mask & (A_NETMASK|A_HOSTNAME)); 334 did_flags |= (mask & A_NETMASK);
338 if (mask & A_CAST_HOST_COPY) { 335 if (mask & A_CAST_HOST_COPY) {
339#ifdef BB_FEATURE_IFCONFIG_HW 336#ifdef BB_FEATURE_IFCONFIG_HW
340 if (mask & A_CAST_RESOLVE) { 337 if (mask & A_CAST_RESOLVE) {
@@ -345,20 +342,11 @@ int ifconfig_main(int argc, char **argv)
345 if (!strcmp(host, "default")) { 342 if (!strcmp(host, "default")) {
346 /* Default is special, meaning 0.0.0.0. */ 343 /* Default is special, meaning 0.0.0.0. */
347 sai.sin_addr.s_addr = INADDR_ANY; 344 sai.sin_addr.s_addr = INADDR_ANY;
348 } else if ((!strcmp(host, "+")) && (mask & A_BROADCAST) &&
349 (did_flags & (A_NETMASK|A_HOSTNAME))) {
350 /* + is special, meaning broadcast is derived. */
351 sai.sin_addr.s_addr = (~sai_netmask.sin_addr.s_addr) |
352 (sai_hostname.sin_addr.s_addr & sai_netmask.sin_addr.s_addr);
353 } else if (inet_aton(host, &sai.sin_addr) == 0) { 345 } else if (inet_aton(host, &sai.sin_addr) == 0) {
354 /* It's not a dotted quad. */ 346 /* It's not a dotted quad. */
355 ++goterr; 347 ++goterr;
356 continue; 348 continue;
357 } 349 }
358 if(mask & A_HOSTNAME)
359 sai_hostname = sai;
360 if(mask & A_NETMASK)
361 sai_netmask = sai;
362 p = (char *) &sai; 350 p = (char *) &sai;
363#ifdef BB_FEATURE_IFCONFIG_HW 351#ifdef BB_FEATURE_IFCONFIG_HW
364 } else { /* A_CAST_HOST_COPY_IN_ETHER */ 352 } else { /* A_CAST_HOST_COPY_IN_ETHER */