come up with common version with ifdefs for big or little endian
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Tue, 30 Apr 1991 09:23:53 +0000 (01:23 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Tue, 30 Apr 1991 09:23:53 +0000 (01:23 -0800)
SCCS-vsn: sys/netns/ns_cksum.c 7.7

usr/src/sys/netns/ns_cksum.c

index b43c7b0..871abbb 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ns_cksum.c  7.6 (Berkeley) %G%
+ *     @(#)ns_cksum.c  7.7 (Berkeley) %G%
  */
 
 #include "sys/param.h"
  */
 
 #include "sys/param.h"
@@ -48,7 +48,11 @@ ns_cksum(m, len)
                         * There is a byte left from the last segment;
                         * ones-complement add it into the checksum.
                         */
                         * There is a byte left from the last segment;
                         * ones-complement add it into the checksum.
                         */
-                       sum  += *(u_char *)w; /* Big-Endian, else << 8 */
+#if BYTE_ORDER == BIG_ENDIAN
+                       sum  += *(u_char *)w;
+#else
+                       sum  += *(u_char *)w << 8;
+#endif
                        sum += sum;
                        w = (u_short *)(1 + (char *)w);
                        mlen = m->m_len - 1;
                        sum += sum;
                        w = (u_short *)(1 + (char *)w);
                        mlen = m->m_len - 1;
@@ -97,9 +101,15 @@ ns_cksum(m, len)
                }
                goto commoncase;
 uuuuglyy:
                }
                goto commoncase;
 uuuuglyy:
-/* Big-Endian; else reverse ww and vv */
+#if BYTE_ORDER == BIG_ENDIAN
 #define ww(n) (((u_char *)w)[n + n + 1])
 #define vv(n) (((u_char *)w)[n + n])
 #define ww(n) (((u_char *)w)[n + n + 1])
 #define vv(n) (((u_char *)w)[n + n])
+#else
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define vv(n) (((u_char *)w)[n + n + 1])
+#define ww(n) (((u_char *)w)[n + n])
+#endif
+#endif
                sum2 = 0;
 #ifndef TINY
                while ((mlen -= 32) >= 0) {
                sum2 = 0;
 #ifndef TINY
                while ((mlen -= 32) >= 0) {
@@ -145,7 +155,11 @@ uuuuglyy:
                sum += (sum2 << 8);
 commoncase:
                if (mlen == -1) {
                sum += (sum2 << 8);
 commoncase:
                if (mlen == -1) {
-                       sum += *(u_char *)w << 8; /* Big-Endian, else no << 8 */
+#if BYTE_ORDER == BIG_ENDIAN
+                       sum += *(u_char *)w << 8;
+#else
+                       sum += *(u_char *)w;
+#endif
                }
                FOLD(sum);
        }
                }
                FOLD(sum);
        }