aboutsummaryrefslogtreecommitdiff
path: root/networking/ping.c
diff options
context:
space:
mode:
authorBaruch Siach <baruch@tkos.co.il>2011-09-07 17:52:37 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-09-07 17:55:40 +0200
commite8f36330d9bb27f9f7e66aa6f01ff92c07d86f62 (patch)
tree863018163a166cc690902d8027a3f04f9f812dd3 /networking/ping.c
parent8c84f7545cf08925edb23d94d9f6519b338267c6 (diff)
downloadbusybox-e8f36330d9bb27f9f7e66aa6f01ff92c07d86f62.tar.gz
networking: consolidate the IP checksum code. -129 bytes.
Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ping.c')
-rw-r--r--networking/ping.c31
1 files changed, 3 insertions, 28 deletions
diff --git a/networking/ping.c b/networking/ping.c
index efd4f210b..a1fd9dfb1 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -149,31 +149,6 @@ enum {
PINGINTERVAL = 1, /* 1 second */
};
-/* Common routines */
-
-static int in_cksum(unsigned short *buf, int sz)
-{
- int nleft = sz;
- int sum = 0;
- unsigned short *w = buf;
- unsigned short ans = 0;
-
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- if (nleft == 1) {
- *(unsigned char *) (&ans) = *(unsigned char *) w;
- sum += ans;
- }
-
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
- ans = ~sum;
- return ans;
-}
-
#if !ENABLE_FEATURE_FANCY_PING
/* Simple version */
@@ -201,7 +176,7 @@ static void ping4(len_and_sockaddr *lsa)
pkt = (struct icmp *) G.packet;
memset(pkt, 0, sizeof(G.packet));
pkt->icmp_type = ICMP_ECHO;
- pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(G.packet));
+ pkt->icmp_cksum = inet_cksum((uint16_t *) pkt, sizeof(G.packet));
xsendto(pingsock, G.packet, DEFDATALEN + ICMP_MINLEN, &lsa->u.sa, lsa->len);
@@ -493,7 +468,7 @@ static void sendping4(int junk UNUSED_PARAM)
/* No hton: we'll read it back on the same machine */
*(uint32_t*)&pkt->icmp_dun = monotonic_us();
- pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN);
+ pkt->icmp_cksum = inet_cksum((uint16_t *) pkt, datalen + ICMP_MINLEN);
sendping_tail(sendping4, ICMP_MINLEN);
}
@@ -512,7 +487,7 @@ static void sendping6(int junk UNUSED_PARAM)
/*if (datalen >= 4)*/
*(uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us();
- //TODO? pkt->icmp_cksum = in_cksum(...);
+ //TODO? pkt->icmp_cksum = inet_cksum(...);
sendping_tail(sendping6, sizeof(struct icmp6_hdr));
}