vinit changed for new vn_if
[unix-history] / usr / src / sys / netns / ns_cksum.c
index e5ff957..3dcc62e 100644 (file)
@@ -1,14 +1,15 @@
 /*
 /*
- * Copyright (c) 1982, 1988 Regents of the University of California.
+ * Copyright (c) 1982, 1992 Regents of the University of California.
  * All rights reserved.
  *
  * %sccs.include.redist.c%
  *
  * All rights reserved.
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ns_cksum.c  7.5 (Berkeley) %G%
+ *     @(#)ns_cksum.c  7.9 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "mbuf.h"
  */
 
 #include "param.h"
 #include "mbuf.h"
+
 /*
  * Checksum routine for Network Systems Protocol Packets (Big-Endian).
  *
 /*
  * Checksum routine for Network Systems Protocol Packets (Big-Endian).
  *
@@ -47,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;
@@ -96,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) {
@@ -144,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);
        }