diff options
-rw-r--r-- | networking/ping.c | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/networking/ping.c b/networking/ping.c index 9db3180f1..6b5045eb3 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -235,27 +235,51 @@ enum { | |||
235 | }; | 235 | }; |
236 | 236 | ||
237 | 237 | ||
238 | static union { | 238 | struct globals { |
239 | struct sockaddr sa; | 239 | int pingsock; |
240 | struct sockaddr_in sin; | 240 | len_and_sockaddr *source_lsa; |
241 | unsigned datalen; | ||
242 | int if_index; | ||
243 | unsigned long ntransmitted, nreceived, nrepeats, pingcount; | ||
244 | uint16_t myid; | ||
245 | unsigned tmin, tmax; | ||
246 | unsigned long tsum; | ||
247 | const char *hostname; | ||
248 | const char *dotted; | ||
249 | union { | ||
250 | struct sockaddr sa; | ||
251 | struct sockaddr_in sin; | ||
241 | #if ENABLE_PING6 | 252 | #if ENABLE_PING6 |
242 | struct sockaddr_in6 sin6; | 253 | struct sockaddr_in6 sin6; |
243 | #endif | 254 | #endif |
244 | } pingaddr; | 255 | } pingaddr; |
245 | static len_and_sockaddr *source_lsa; | 256 | char rcvd_tbl[MAX_DUP_CHK / 8]; |
246 | static int pingsock = -1; | 257 | }; |
247 | static unsigned datalen; /* intentionally uninitialized to work around gcc bug */ | 258 | #define G (*(struct globals*)&bb_common_bufsiz1) |
248 | 259 | #define pingsock (G.pingsock ) | |
249 | static int if_index; | 260 | #define source_lsa (G.source_lsa ) |
250 | 261 | #define datalen (G.datalen ) | |
251 | static unsigned long ntransmitted, nreceived, nrepeats, pingcount; | 262 | #define if_index (G.if_index ) |
252 | static uint16_t myid; | 263 | #define ntransmitted (G.ntransmitted) |
253 | static unsigned tmin = UINT_MAX, tmax; | 264 | #define nreceived (G.nreceived ) |
254 | static unsigned long tsum; | 265 | #define nrepeats (G.nrepeats ) |
255 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 266 | #define pingcount (G.pingcount ) |
267 | #define myid (G.myid ) | ||
268 | #define tmin (G.tmin ) | ||
269 | #define tmax (G.tmax ) | ||
270 | #define tsum (G.tsum ) | ||
271 | #define hostname (G.hostname ) | ||
272 | #define dotted (G.dotted ) | ||
273 | #define pingaddr (G.pingaddr ) | ||
274 | #define rcvd_tbl (G.rcvd_tbl ) | ||
275 | void BUG_ping_globals_too_big(void); | ||
276 | #define INIT_G() do { \ | ||
277 | if (sizeof(G) > COMMON_BUFSIZE) \ | ||
278 | BUG_ping_globals_too_big(); \ | ||
279 | pingsock = -1; \ | ||
280 | tmin = UINT_MAX; \ | ||
281 | } while (0) | ||
256 | 282 | ||
257 | static const char *hostname; | ||
258 | static const char *dotted; | ||
259 | 283 | ||
260 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ | 284 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ |
261 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ | 285 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ |
@@ -652,6 +676,8 @@ int ping_main(int argc, char **argv) | |||
652 | char *opt_c, *opt_s, *opt_I; | 676 | char *opt_c, *opt_s, *opt_I; |
653 | USE_PING6(sa_family_t af = AF_UNSPEC;) | 677 | USE_PING6(sa_family_t af = AF_UNSPEC;) |
654 | 678 | ||
679 | INIT_G(); | ||
680 | |||
655 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ | 681 | datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */ |
656 | 682 | ||
657 | /* exactly one argument needed, -v and -q don't mix */ | 683 | /* exactly one argument needed, -v and -q don't mix */ |