ptclcsum()

ptclcsum()

概要

引数

実装

  196: ushort
  197: ptclcsum(Block *bp, int offset, int len)
  198: {
  199:         uchar *addr;
  200:         ulong losum, hisum;
  201:         ushort csum;
  202:         int odd, blocklen, x;
  203: 
  204:         /* Correct to front of data area */
  205:         while(bp != nil && offset && offset >= BLEN(bp)) {
  206:                 offset -= BLEN(bp);
  207:                 bp = bp->next;
  208:         }
  209:         if(bp == nil)
  210:                 return 0;
  211: 
  212:         addr = bp->rp + offset;
  213:         blocklen = BLEN(bp) - offset;
  214: 
  215:         if(bp->next == nil) {
  216:                 if(blocklen < len)
  217:                         len = blocklen;
  218:                 return ~ptclbsum(addr, len) & 0xffff;
  219:         }
  220: 
  221:         losum = 0;
  222:         hisum = 0;
  223: 
  224:         odd = 0;
  225:         while(len) {
  226:                 x = blocklen;
  227:                 if(len < x)
  228:                         x = len;
  229: 
  230:                 csum = ptclbsum(addr, x);
  231:                 if(odd)
  232:                         hisum += csum;
  233:                 else
  234:                         losum += csum;
  235:                 odd = (odd+x) & 1;
  236:                 len -= x;
  237: 
  238:                 bp = bp->next;
  239:                 if(bp == nil)
  240:                         break;
  241:                 blocklen = BLEN(bp);
  242:                 addr = bp->rp;
  243:         }
  244: 
  245:         losum += hisum>>8;
  246:         losum += (hisum&0xff)<<8;
  247:         while((csum = losum>>16) != 0)
  248:                 losum = csum + (losum & 0xffff);
  249: 
  250:         return ~losum & 0xffff;
  251: }