summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko2013-06-28 01:33:47 +0200
committerDenys Vlasenko2013-06-28 01:33:47 +0200
commit26a7e2ecbf76db06cf0754a0664eaa68e3cae53a (patch)
treea129e196bd1dfc8f40461064c08bb7b4e0533020 /networking
parent59f46676a9c03303809f40d1a27c4d2e9e640697 (diff)
downloadbusybox-26a7e2ecbf76db06cf0754a0664eaa68e3cae53a.zip
busybox-26a7e2ecbf76db06cf0754a0664eaa68e3cae53a.tar.gz
ping: code shrink
function old new delta unpack_tail 262 243 -19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/ping.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 8c08c80..f27e214 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -372,7 +372,7 @@ struct globals {
struct sockaddr_in6 sin6;
#endif
} pingaddr;
- char rcvd_tbl[MAX_DUP_CHK / 8];
+ unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define if_index (G.if_index )
@@ -402,13 +402,11 @@ void BUG_ping_globals_too_big(void);
} while (0)
-#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
-#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
-#define SET(bit) (A(bit) |= B(bit))
-#define CLR(bit) (A(bit) &= (~B(bit)))
-#define TST(bit) (A(bit) & B(bit))
-
-/**************************************************************************/
+#define BYTE(bit) rcvd_tbl[(bit)>>3]
+#define MASK(bit) (1 << ((bit) & 7))
+#define SET(bit) (BYTE(bit) |= MASK(bit))
+#define CLR(bit) (BYTE(bit) &= (~MASK(bit)))
+#define TST(bit) (BYTE(bit) & MASK(bit))
static void print_stats_and_exit(int junk) NORETURN;
static void print_stats_and_exit(int junk UNUSED_PARAM)
@@ -578,11 +576,10 @@ static void unpack_tail(int sz, uint32_t *tp,
const char *from_str,
uint16_t recv_seq, int ttl)
{
+ unsigned char *b, m;
const char *dupmsg = " (DUP!)";
unsigned triptime = triptime; /* for gcc */
- ++G.nreceived;
-
if (tp) {
/* (int32_t) cast is for hypothetical 64-bit unsigned */
/* (doesn't hurt 32-bit real-world anyway) */
@@ -594,11 +591,15 @@ static void unpack_tail(int sz, uint32_t *tp,
tmax = triptime;
}
- if (TST(recv_seq % MAX_DUP_CHK)) {
+ b = &BYTE(recv_seq % MAX_DUP_CHK);
+ m = MASK(recv_seq % MAX_DUP_CHK);
+ /*if TST(recv_seq % MAX_DUP_CHK):*/
+ if (*b & m) {
++G.nrepeats;
- --G.nreceived;
} else {
- SET(recv_seq % MAX_DUP_CHK);
+ /*SET(recv_seq % MAX_DUP_CHK):*/
+ *b |= m;
+ ++G.nreceived;
dupmsg += 7;
}