Index: inet_chksum.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/inet_chksum.c,v
retrieving revision 1.4
diff -u -p -r1.4 inet_chksum.c
--- inet_chksum.c	10 Mar 2008 16:12:31 -0000	1.4
+++ inet_chksum.c	11 Mar 2008 20:26:22 -0000
@@ -41,8 +41,6 @@
 #include "lwip/inet_chksum.h"
 #include "lwip/inet.h"
 
-#include <string.h>
-
 /* These are some reference implementations of the checksum algorithm, with the
  * aim of being simple, correct and fully portable. Checksumming is the
  * first thing you would want to optimize for your platform. If you create
@@ -106,9 +104,7 @@ lwip_standard_chksum(void *dataptr, u16_
   }
   /* add deferred carry bits */
   acc = (acc >> 16) + (acc & 0x0000ffffUL);
-  if ((acc & 0xffff0000) != 0) {
-    acc = (acc >> 16) + (acc & 0x0000ffffUL);
-  }
+  acc = (acc >> 16) + (acc & 0x0000ffffUL);
   /* This maybe a little confusing: reorder sum using htons()
      instead of ntohs() since it has a little less call overhead.
      The caller must invert bits for Internet sum ! */
@@ -161,8 +157,8 @@ lwip_standard_chksum(void *dataptr, int 
   sum += t;
 
   /*  Fold 32-bit sum to 16 bits */
-  while ((sum >> 16) != 0)
-    sum = (sum & 0xffff) + (sum >> 16);
+  sum = (sum & 0xffff) + (sum >> 16);
+  sum = (sum & 0xffff) + (sum >> 16);
 
   /* Swap if alignment was odd */
   if (odd)
@@ -238,8 +234,8 @@ lwip_standard_chksum(void *dataptr, int 
 
   sum += t;                     /* add end bytes */
 
-  while ((sum >> 16) != 0)      /* combine halves */
-    sum = (sum >> 16) + (sum & 0xffff);
+  sum = (sum >> 16) + (sum & 0xffff);/* combine halves */
+  sum = (sum >> 16) + (sum & 0xffff);
 
   if (odd)
     sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
@@ -277,9 +273,7 @@ inet_chksum_pseudo(struct pbuf *p,
       (void *)q, (void *)q->next));
     acc += LWIP_CHKSUM(q->payload, q->len);
     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
-    while ((acc >> 16) != 0) {
-      acc = (acc & 0xffffUL) + (acc >> 16);
-    }
+    acc = (acc & 0xffffUL) + (acc >> 16);
     if (q->len % 2 != 0) {
       swapped = 1 - swapped;
       acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
@@ -296,14 +290,13 @@ inet_chksum_pseudo(struct pbuf *p,
   acc += ((dest->addr >> 16) & 0xffffUL);
   acc += (u32_t)htons((u16_t)proto);
   acc += (u32_t)htons(proto_len);
-
-  while ((acc >> 16) != 0) {
-    acc = (acc & 0xffffUL) + (acc >> 16);
-  }
+  acc = (acc & 0xffffUL) + (acc >> 16);
+  acc = (acc & 0xffffUL) + (acc >> 16);
   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
   return (u16_t)~(acc & 0xffffUL);
 }
 
+#if CHECKSUM_CHECK_UDP || CHECKSUM_GEN_UDP
 /* inet_chksum_pseudo:
  *
  * Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain.
@@ -340,9 +333,7 @@ inet_chksum_pseudo_partial(struct pbuf *
     chksum_len -= chklen;
     LWIP_ASSERT("delete me", chksum_len < 0x7fff);
     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
-    while ((acc >> 16) != 0) {
-      acc = (acc & 0xffffUL) + (acc >> 16);
-    }
+    acc = (acc & 0xffffUL) + (acc >> 16);
     if (q->len % 2 != 0) {
       swapped = 1 - swapped;
       acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
@@ -359,13 +350,12 @@ inet_chksum_pseudo_partial(struct pbuf *
   acc += ((dest->addr >> 16) & 0xffffUL);
   acc += (u32_t)htons((u16_t)proto);
   acc += (u32_t)htons(proto_len);
-
-  while ((acc >> 16) != 0) {
-    acc = (acc & 0xffffUL) + (acc >> 16);
-  }
+  acc = (acc & 0xffffUL) + (acc >> 16);
+  acc = (acc & 0xffffUL) + (acc >> 16);
   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
   return (u16_t)~(acc & 0xffffUL);
 }
+#endif
 
 /* inet_chksum:
  *
@@ -380,13 +370,7 @@ inet_chksum_pseudo_partial(struct pbuf *
 u16_t
 inet_chksum(void *dataptr, u16_t len)
 {
-  u32_t acc;
-
-  acc = LWIP_CHKSUM(dataptr, len);
-  while ((acc >> 16) != 0) {
-    acc = (acc & 0xffff) + (acc >> 16);
-  }
-  return (u16_t)~(acc & 0xffff);
+  return ~LWIP_CHKSUM(dataptr, len);
 }
 
 /**
@@ -407,9 +391,7 @@ inet_chksum_pbuf(struct pbuf *p)
   swapped = 0;
   for(q = p; q != NULL; q = q->next) {
     acc += LWIP_CHKSUM(q->payload, q->len);
-    while ((acc >> 16) != 0) {
-      acc = (acc & 0xffffUL) + (acc >> 16);
-    }
+    acc = (acc & 0xffffUL) + (acc >> 16);
     if (q->len % 2 != 0) {
       swapped = 1 - swapped;
       acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
