home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / LCSUM.C < prev    next >
C/C++ Source or Header  |  1991-01-27  |  866b  |  34 lines

  1. /*
  2.  * Word aligned linear buffer checksum routine.  Called from mbuf checksum
  3.  * routine with simple args.  Intent is that this routine may be replaced
  4.  * by assembly language routine for speed if so desired. (On the PC, the
  5.  * replacement is in pcgen.asm.)
  6.  *
  7.  * Copyright 1991 Phil Karn, KA9Q
  8.  */
  9.  
  10. #if    (defined(MPU8086) || defined(MPU8080) || defined(vax))
  11. #define    LITTLE_ENDIAN    /* Low order bytes are first in memory */
  12. #endif            /* Almost all other machines are big-endian */
  13. #include "global.h"
  14. #include "ip.h"
  15.  
  16. int16
  17. lcsum(wp,len)
  18. register int16 *wp;
  19. register int16 len;
  20. {
  21.     register int32 sum = 0;
  22.     int16 result;
  23.  
  24.     while(len-- != 0)
  25.         sum += *wp++;
  26.     result = eac(sum);
  27. #ifdef    LITTLE_ENDIAN
  28.     /* Swap the result because of the (char *) to (int *) type punning */
  29.     result = (result << 8) | (result >> 8);
  30. #endif
  31.     return result;
  32. }
  33.  
  34.