aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:26:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:26:06 +0000
commit60e3dd60160e0a3192fd0f2ed02cf6407ef36ed4 (patch)
tree0abb108acf46dca26a938114da4fb41dfa0717df
parent035aae584111cd92af37a124160dbcb9e810d84c (diff)
downloadbusybox-w32-60e3dd60160e0a3192fd0f2ed02cf6407ef36ed4.tar.gz
busybox-w32-60e3dd60160e0a3192fd0f2ed02cf6407ef36ed4.tar.bz2
busybox-w32-60e3dd60160e0a3192fd0f2ed02cf6407ef36ed4.zip
zcip: convert lots of zero-initialized locals
in zcip_main() to statics in bss.
-rw-r--r--networking/zcip.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/networking/zcip.c b/networking/zcip.c
index 176bc0101..e781a5882 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -72,11 +72,6 @@ enum {
72 DEFEND 72 DEFEND
73}; 73};
74 74
75/* Implicitly zero-initialized */
76static const struct in_addr null_ip;
77static const struct ether_addr null_addr;
78static int verbose;
79
80#define DBG(fmt,args...) \ 75#define DBG(fmt,args...) \
81 do { } while (0) 76 do { } while (0)
82#define VDBG DBG 77#define VDBG DBG
@@ -188,28 +183,35 @@ static unsigned ATTRIBUTE_ALWAYS_INLINE ms_rdelay(unsigned secs)
188 * main program 183 * main program
189 */ 184 */
190 185
186/* Used to be auto variables on main() stack, but
187 * most of them were zero-inited. Moving them to bss
188 * is more space-efficient.
189 */
190static const struct in_addr null_ip; // = { 0 };
191static const struct ether_addr null_addr; // = { {0, 0, 0, 0, 0, 0} };
192
193static struct sockaddr saddr; // memset(0);
194static struct in_addr ip; // = { 0 };
195static struct ifreq ifr; //memset(0);
196
197static char *intf; // = NULL;
198static char *script; // = NULL;
199static suseconds_t timeout; // = 0; // milliseconds
200static unsigned conflicts; // = 0;
201static unsigned nprobes; // = 0;
202static unsigned nclaims; // = 0;
203static int ready; // = 0;
204static int quit; // = 0;
205static int foreground; // = 0;
206static int verbose; // = 0;
207static int state = PROBE;
208
191int zcip_main(int argc, char *argv[]) 209int zcip_main(int argc, char *argv[])
192{ 210{
193 char *intf = NULL; 211 struct ether_addr eth_addr;
194 char *script = NULL;
195 int quit = 0;
196 int foreground = 0;
197
198 char *why; 212 char *why;
199 struct sockaddr saddr;
200 struct ether_addr addr;
201 struct in_addr ip = { 0 };
202 int fd; 213 int fd;
203 int ready = 0;
204 suseconds_t timeout = 0; // milliseconds
205 unsigned conflicts = 0;
206 unsigned nprobes = 0;
207 unsigned nclaims = 0;
208 int t; 214 int t;
209 int state = PROBE;
210
211 struct ifreq ifr;
212 unsigned short seed[3];
213 215
214 // parse commandline: prog [options] ifname script 216 // parse commandline: prog [options] ifname script
215 while ((t = getopt(argc, argv, "fqr:v")) != EOF) { 217 while ((t = getopt(argc, argv, "fqr:v")) != EOF) {
@@ -249,7 +251,7 @@ int zcip_main(int argc, char *argv[])
249 return EXIT_FAILURE; 251 return EXIT_FAILURE;
250 252
251 // initialize saddr 253 // initialize saddr
252 memset(&saddr, 0, sizeof (saddr)); 254 //memset(&saddr, 0, sizeof (saddr));
253 safe_strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data)); 255 safe_strncpy(saddr.sa_data, intf, sizeof (saddr.sa_data));
254 256
255 // open an ARP socket 257 // open an ARP socket
@@ -258,21 +260,21 @@ int zcip_main(int argc, char *argv[])
258 xbind(fd, &saddr, sizeof (saddr); 260 xbind(fd, &saddr, sizeof (saddr);
259 261
260 // get the interface's ethernet address 262 // get the interface's ethernet address
261 memset(&ifr, 0, sizeof (ifr)); 263 //memset(&ifr, 0, sizeof (ifr));
262 strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name)); 264 strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name));
263 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { 265 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
264 foreground = 1; 266 foreground = 1;
265 why = "get ethernet address"; 267 why = "get ethernet address";
266 goto bad; 268 goto bad;
267 } 269 }
268 memcpy(&addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); 270 memcpy(&eth_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
269 271
270 // start with some stable ip address, either a function of 272 // start with some stable ip address, either a function of
271 // the hardware address or else the last address we used. 273 // the hardware address or else the last address we used.
272 // NOTE: the sequence of addresses we try changes only 274 // NOTE: the sequence of addresses we try changes only
273 // depending on when we detect conflicts. 275 // depending on when we detect conflicts.
274 memcpy(seed, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); 276 // (SVID 3 bogon: who says that "short" is always 16 bits?)
275 seed48(seed); 277 seed48( (unsigned short*)&ifr.ifr_hwaddr.sa_data );
276 if (ip.s_addr == 0) 278 if (ip.s_addr == 0)
277 pick(&ip); 279 pick(&ip);
278 280
@@ -299,13 +301,13 @@ int zcip_main(int argc, char *argv[])
299 struct timeval tv1; 301 struct timeval tv1;
300 struct arp_packet p; 302 struct arp_packet p;
301 303
304 int source_ip_conflict = 0;
305 int target_ip_conflict = 0;
306
302 fds[0].fd = fd; 307 fds[0].fd = fd;
303 fds[0].events = POLLIN; 308 fds[0].events = POLLIN;
304 fds[0].revents = 0; 309 fds[0].revents = 0;
305 310
306 int source_ip_conflict = 0;
307 int target_ip_conflict = 0;
308
309 // poll, being ready to adjust current timeout 311 // poll, being ready to adjust current timeout
310 if (!timeout) { 312 if (!timeout) {
311 timeout = ms_rdelay(PROBE_WAIT); 313 timeout = ms_rdelay(PROBE_WAIT);
@@ -338,7 +340,7 @@ int zcip_main(int argc, char *argv[])
338 VDBG("probe/%d %s@%s\n", 340 VDBG("probe/%d %s@%s\n",
339 nprobes, intf, inet_ntoa(ip)); 341 nprobes, intf, inet_ntoa(ip));
340 (void)arp(fd, &saddr, ARPOP_REQUEST, 342 (void)arp(fd, &saddr, ARPOP_REQUEST,
341 &addr, null_ip, 343 &eth_addr, null_ip,
342 &null_addr, ip); 344 &null_addr, ip);
343 timeout = PROBE_MIN * 1000; 345 timeout = PROBE_MIN * 1000;
344 timeout += ms_rdelay(PROBE_MAX 346 timeout += ms_rdelay(PROBE_MAX
@@ -351,8 +353,8 @@ int zcip_main(int argc, char *argv[])
351 VDBG("announce/%d %s@%s\n", 353 VDBG("announce/%d %s@%s\n",
352 nclaims, intf, inet_ntoa(ip)); 354 nclaims, intf, inet_ntoa(ip));
353 (void)arp(fd, &saddr, ARPOP_REQUEST, 355 (void)arp(fd, &saddr, ARPOP_REQUEST,
354 &addr, ip, 356 &eth_addr, ip,
355 &addr, ip); 357 &eth_addr, ip);
356 timeout = ANNOUNCE_INTERVAL * 1000; 358 timeout = ANNOUNCE_INTERVAL * 1000;
357 } 359 }
358 break; 360 break;
@@ -364,8 +366,8 @@ int zcip_main(int argc, char *argv[])
364 VDBG("announce/%d %s@%s\n", 366 VDBG("announce/%d %s@%s\n",
365 nclaims, intf, inet_ntoa(ip)); 367 nclaims, intf, inet_ntoa(ip));
366 (void)arp(fd, &saddr, ARPOP_REQUEST, 368 (void)arp(fd, &saddr, ARPOP_REQUEST,
367 &addr, ip, 369 &eth_addr, ip,
368 &addr, ip); 370 &eth_addr, ip);
369 timeout = ANNOUNCE_INTERVAL * 1000; 371 timeout = ANNOUNCE_INTERVAL * 1000;
370 break; 372 break;
371 case ANNOUNCE: 373 case ANNOUNCE:
@@ -376,8 +378,8 @@ int zcip_main(int argc, char *argv[])
376 VDBG("announce/%d %s@%s\n", 378 VDBG("announce/%d %s@%s\n",
377 nclaims, intf, inet_ntoa(ip)); 379 nclaims, intf, inet_ntoa(ip));
378 (void)arp(fd, &saddr, ARPOP_REQUEST, 380 (void)arp(fd, &saddr, ARPOP_REQUEST,
379 &addr, ip, 381 &eth_addr, ip,
380 &addr, ip); 382 &eth_addr, ip);
381 timeout = ANNOUNCE_INTERVAL * 1000; 383 timeout = ANNOUNCE_INTERVAL * 1000;
382 } 384 }
383 else { 385 else {
@@ -477,12 +479,12 @@ int zcip_main(int argc, char *argv[])
477 continue; 479 continue;
478 480
479 if (memcmp(p.arp.arp_spa, &ip.s_addr, sizeof(struct in_addr)) == 0 && 481 if (memcmp(p.arp.arp_spa, &ip.s_addr, sizeof(struct in_addr)) == 0 &&
480 memcmp(&addr, &p.arp.arp_sha, ETH_ALEN) != 0) { 482 memcmp(&eth_addr, &p.arp.arp_sha, ETH_ALEN) != 0) {
481 source_ip_conflict = 1; 483 source_ip_conflict = 1;
482 } 484 }
483 if (memcmp(p.arp.arp_tpa, &ip.s_addr, sizeof(struct in_addr)) == 0 && 485 if (memcmp(p.arp.arp_tpa, &ip.s_addr, sizeof(struct in_addr)) == 0 &&
484 p.arp.arp_op == htons(ARPOP_REQUEST) && 486 p.arp.arp_op == htons(ARPOP_REQUEST) &&
485 memcmp(&addr, &p.arp.arp_tha, ETH_ALEN) != 0) { 487 memcmp(&eth_addr, &p.arp.arp_tha, ETH_ALEN) != 0) {
486 target_ip_conflict = 1; 488 target_ip_conflict = 1;
487 } 489 }
488 490
@@ -516,8 +518,8 @@ int zcip_main(int argc, char *argv[])
516 timeout = DEFEND_INTERVAL * 1000; 518 timeout = DEFEND_INTERVAL * 1000;
517 (void)arp(fd, &saddr, 519 (void)arp(fd, &saddr,
518 ARPOP_REQUEST, 520 ARPOP_REQUEST,
519 &addr, ip, 521 &eth_addr, ip,
520 &addr, ip); 522 &eth_addr, ip);
521 } 523 }
522 break; 524 break;
523 case DEFEND: 525 case DEFEND: