home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 8 / boot-disc-1997-04.iso / PDA_Soft / Psion / comms / p3nfs / nfsd / crc.c next >
Text File  |  1996-03-17  |  591b  |  47 lines

  1. int
  2. docrc16_1(crc, c)
  3.   int crc;
  4.   unsigned char c;
  5. {
  6.   int acc, i;
  7.  
  8.   acc = crc;
  9.   acc ^= c << 8;
  10.   for(i = 0; i < 8; i++)
  11.     if(acc & 0x8000)
  12.       {
  13.     acc <<= 1;
  14.     acc ^= 0x1021;
  15.       }
  16.     else
  17.       {
  18.     acc <<= 1;
  19.       }
  20.   return acc & 0xffff;
  21. }
  22.  
  23. int
  24. docrc16(ptr, len)
  25.   unsigned char *ptr;
  26.   int len;
  27. {
  28.   int acc, i;
  29.  
  30.   acc = 0;
  31.   while(len--)
  32.     {
  33.       acc ^= *ptr++ << 8;
  34.       for(i = 0; i < 8; i++)
  35.         if(acc & 0x8000)
  36.       {
  37.         acc <<= 1;
  38.         acc ^= 0x1021;
  39.       }
  40.     else
  41.       {
  42.         acc <<= 1;
  43.       }
  44.     }
  45.   return acc & 0xffff;
  46. }
  47.