void checksumadjust(unsigned char *chksum, unsigned char *optr, int olen, unsigned char *nptr, int nlen) /* assuming: unsigned char is 8 bits, long is 32 bits. - chksum points to the chksum in the packet - optr points to the old data in the packet - nptr points to the new data in the packet */ { long x, old, new; x=chksum[0]*256+chksum[1]; x=~x; while (olen) { if (olen==1) { old=optr[0]*256+optr[1]; x-=old & 0xff00; if (x<=0) { x--; x&=0xffff; } break; } else { old=optr[0]*256+optr[1]; optr+=2; x-=old & 0xffff; if (x<=0) { x--; x&=0xffff; } olen-=2; } } while (nlen) { if (nlen==1) { new=nptr[0]*256+nptr[1]; x+=new & 0xff00; if (x & 0x10000) { x++; x&=0xffff; } break; } else { new=nptr[0]*256+nptr[1]; nptr+=2; x+=new & 0xffff; if (x & 0x10000) { x++; x&=0xffff; } nlen-=2; } } x=~x; chksum[0]=x/256; chksum[1]=x & 0xff; }