1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)in_cksum.c	1.1 (2.10BSD Berkeley) 12/1/86
   7:  */
   8: #include "param.h"
   9: #include "../machine/seg.h"
  10: 
  11: #include "mbuf.h"
  12: #include "domain.h"
  13: #include "protosw.h"
  14: #include <netinet/in.h>
  15: #include <netinet/in_systm.h>
  16: 
  17: /*
  18:  * Checksum routine for Internet Protocol family headers.  This routine is
  19:  * very heavily used in the network code and should be rewritten for each
  20:  * CPU to be as fast as possible.
  21:  */
  22: 
  23: #ifdef DIAGNOSTIC
  24: int in_ckprint = 0;         /* print sums */
  25: #endif
  26: 
  27: in_cksum(m, len)
  28:     struct mbuf *m;
  29:     int len;
  30: {
  31:     register u_char *w;     /* known to be r4 */
  32:     register u_int mlen = 0;    /* known to be r3 */
  33:     register u_int sum = 0;     /* known to be r2 */
  34:     u_int plen = 0;
  35: 
  36: #ifdef DIAGNOSTIC
  37:     if (in_ckprint)
  38:         printf("ck m%o l%o", m, len);
  39: #endif
  40:     for (;;) {
  41:         /*
  42: 		 * Each trip around loop adds in
  43: 		 * words from one mbuf segment.
  44: 		 */
  45:         w = mtod(m, u_char *);
  46:         if (plen & 01) {
  47:             /*
  48: 			 * The last segment was an odd length, add the high
  49: 			 * order byte into the checksum.
  50: 			 */
  51:             sum = in_ckadd(sum,(*w++ << 8));
  52:             mlen = m->m_len - 1;
  53:             len--;
  54:         } else
  55:             mlen = m->m_len;
  56:         m = m->m_next;
  57:         if (len < mlen)
  58:             mlen = len;
  59:         len -= mlen;
  60:         plen = mlen;
  61:         if (mlen > 0)
  62:             in_ckbuf(); /* arguments already in registers */
  63:         if (len == 0)
  64:             break;
  65:         /*
  66: 		 * Locate the next block with some data.
  67: 		 */
  68:         for (;;) {
  69:             if (m == 0) {
  70:                 printf("cksum: out of data\n");
  71:                 goto done;
  72:             }
  73:             if (m->m_len)
  74:                 break;
  75:             m = m->m_next;
  76:         }
  77:     }
  78: done:
  79: #ifdef DIAGNOSTIC
  80:     if (in_ckprint)
  81:         printf(" s%o\n", ~sum);
  82: #endif
  83:     return(~sum);
  84: }

Defined functions

Defined variables

in_ckprint defined in line 24; used 2 times
Last modified: 1988-05-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2834
Valid CSS Valid XHTML 1.0 Strict