/*
 * Calculate a new fcs given the current fcs and the new data.
 */
__u16 pppfcs16(fcs, cp, len)
register __u16 fcs;
register unsigned char *cp;
register int len;
{
  while (len--)
    fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
  return (fcs);
}/*
 * generate CRC16
 */
__u16 gen_fcs16(unsigned char *cp, int len)
{
__u16 fcs;  /* add on output */
  fcs = pppfcs16(PPP_INITFCS, cp, len);
  fcs ^= 0xffff;             /* complement */  return fcs;
/*
  cp[len] = (fcs & 0x00ff);  //  least significant byte first
  cp[len+1] = ((fcs >> 8) & 0x00ff);
*/
}/*
 * check received data block
 */
__u16 chk_fcs16(unsigned char *cp, int len)
{
__u16 fcs;  fcs = pppfcs16(PPP_INITFCS, cp, len);
  return fcs;/*
  if (fcs == PPP_GOODFCS)
return SUCCESS;
*/
}

解决方案 »

  1.   

    很簡單就可翻譯, 但你給的資料不全, 現在的代碼修改後無法中 delphi 中編繹過!!
      

  2.   

    我知道简单,可我不会呀,主要是指针运算后才自身加1,在delphi中不知道如何处理,希望能把整个的程序转义过来,不要片断,否则还是不行。谢谢。
      

  3.   

    function pppfcs16( fcs : Word;
                      cp : PByte;
                    len : integer ) :   Word ;
    begin
      pppfcs16 := fcs;
      while (len > 0) do
      begin
        fcs := fcs shr 8;
        fcs := fcs xor fcstab[(fcs xor cp^) and $ff];
        Inc(cp, 1);
        Dec(len);
      end;
      pppfcs16 := fcs;
    end;function gen_fcs16(cp : PByte; len : integer) : Word;
    var
      fcs : Word;begin
      fcs := pppfcs16(PPP_INITFCS, cp, len);
      fcs := fcs xor $ffff;
      Result := fcs;
    end;function chk_fcs16(cp : PByte; len : integer) : Word;
    var
      fcs : Word;
    begin
      fcs := pppfcs16(PPP_INITFCS, cp, len);
      Result := fcs;
    end;