vinit changed for new vn_if
[unix-history] / usr / src / sys / netns / ns_cksum.c
index 504f8b3..3dcc62e 100644 (file)
@@ -1,24 +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.
  *
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)ns_cksum.c  7.4 (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).
  *
@@ -57,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;
@@ -106,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) {
@@ -154,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);
        }