diff options
author | Baruch Siach | 2011-09-07 17:52:37 +0200 |
---|---|---|
committer | Denys Vlasenko | 2011-09-07 17:55:40 +0200 |
commit | e8f36330d9bb27f9f7e66aa6f01ff92c07d86f62 (patch) | |
tree | 863018163a166cc690902d8027a3f04f9f812dd3 /networking/traceroute.c | |
parent | 8c84f7545cf08925edb23d94d9f6519b338267c6 (diff) | |
download | busybox-e8f36330d9bb27f9f7e66aa6f01ff92c07d86f62.zip busybox-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/traceroute.c')
-rw-r--r-- | networking/traceroute.c | 35 |
1 files changed, 1 insertions, 34 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c index c321035..d197e54 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -418,39 +418,6 @@ wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timest return read_len; } -/* - * Checksum routine for Internet Protocol family headers (C Version) - */ -static uint16_t -in_cksum(uint16_t *addr, int len) -{ - int nleft = len; - uint16_t *w = addr; - uint16_t answer; - int sum = 0; - - /* - * Our algorithm is simple, using a 32 bit accumulator (sum), - * we add sequential 16 bit words to it, and at the end, fold - * back all the carry bits from the top 16 bits into the lower - * 16 bits. - */ - while (nleft > 1) { - sum += *w++; - nleft -= 2; - } - - /* mop up an odd byte, if necessary */ - if (nleft == 1) - sum += *(unsigned char *)w; - - /* add back carry outs from top 16 bits to low 16 bits */ - sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ - sum += (sum >> 16); /* add carry */ - answer = ~sum; /* truncate to 16 bits */ - return answer; -} - static void send_probe(int seq, int ttl) { @@ -477,7 +444,7 @@ send_probe(int seq, int ttl) /* Always calculate checksum for icmp packets */ outicmp->icmp_cksum = 0; - outicmp->icmp_cksum = in_cksum((uint16_t *)outicmp, + outicmp->icmp_cksum = inet_cksum((uint16_t *)outicmp, packlen - (sizeof(*outip) + optlen)); if (outicmp->icmp_cksum == 0) outicmp->icmp_cksum = 0xffff; |