⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.lst

📁 cs8900 c51应用
💻 LST
📖 第 1 页 / 共 3 页
字号:
 379                  SEND_NETWORK_B( (UINT8)(send_ip_packet.frags >> 8) );
 380                  SEND_NETWORK_B( (UINT8)send_ip_packet.frags );
 381                  SEND_NETWORK_B(send_ip_packet.ttl);
 382                  SEND_NETWORK_B(send_ip_packet.protocol);        
 383                  SEND_NETWORK_B( (UINT8)(send_ip_packet.checksum >> 8) );
 384                  SEND_NETWORK_B( (UINT8)send_ip_packet.checksum );
 385                  SEND_NETWORK_B( (UINT8)(send_ip_packet.sip >> 24) );
 386                  SEND_NETWORK_B( (UINT8)(send_ip_packet.sip >> 16) );
 387                  SEND_NETWORK_B( (UINT8)(send_ip_packet.sip >> 8) );
 388                  SEND_NETWORK_B( (UINT8)send_ip_packet.sip );
 389                  SEND_NETWORK_B( (UINT8)(send_ip_packet.dip >> 24) );
 390                  SEND_NETWORK_B( (UINT8)(send_ip_packet.dip >> 16) );
 391                  SEND_NETWORK_B( (UINT8)(send_ip_packet.dip >> 8) );
 392                  SEND_NETWORK_B( (UINT8)send_ip_packet.dip );
 393                  
 394                  /* Assemble data        */
 395                  
 396                  for(i=0; i<len; i++) {          
 397                          SEND_NETWORK_B(*dat++);
 398                          }
 399                  
 400                  /* Launch it            */
 401                  
 402                  NETWORK_COMPLETE_SEND( send_ip_packet.tlen + ETH_HEADER_LEN);
 403                  
 404                  return(len);
 405                  
 406                  
 407          }
 408          
 409          /** \brief Construct checksum of the IP header
 410           *      \author 
 411           *              \li Jari Lahti
 412           *      \date 08.07.2002
 413           *      \param frame pointer to ip_frame structure holding header information
 414           *              based on which checksum is calculated
 415           *      \return Calculated checksum
 416           *
 417           *      Checksum of the supplied IP datagram is calculated.
 418           *
C51 COMPILER V7.06   IP                                                                    11/26/2004 11:32:45 PAGE 8   

 419           */
 420          UINT32 ip_construct_cs (struct ip_frame* frame)
 421          {
 422                  UINT16 ip_cs;
 423                  UINT8 cs_cnt;
 424                  UINT8 olen;
 425                  UINT8 i;
 426                  
 427                  ip_cs = 0;
 428                  cs_cnt = 0;
 429                  
 430                  ip_cs = ip_checksum(ip_cs, frame->vihl, cs_cnt++);
 431                  ip_cs = ip_checksum(ip_cs, frame->tos, cs_cnt++);
 432                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->tlen >> 8), cs_cnt++);
 433                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->tlen, cs_cnt++);
 434                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->id >> 8), cs_cnt++);
 435                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->id, cs_cnt++);
 436                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->frags >> 8), cs_cnt++);
 437                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->frags, cs_cnt++);
 438                  ip_cs = ip_checksum(ip_cs, frame->ttl, cs_cnt++);
 439                  ip_cs = ip_checksum(ip_cs, frame->protocol, cs_cnt++);
 440                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 24), cs_cnt++);
 441                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 16), cs_cnt++);
 442                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 8), cs_cnt++);
 443                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->sip, cs_cnt++);
 444                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 24), cs_cnt++);
 445                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 16), cs_cnt++);
 446                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 8), cs_cnt++);
 447                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->dip, cs_cnt++);        
 448                  
 449                  /* Is there options?                            */
 450                          
 451                  olen = ((frame->vihl & 0x0F) << 2) - IP_MIN_HLEN;
 452                  
 453                  for( i=0; i<olen; i++)
 454                          ip_cs = ip_checksum(ip_cs, (UINT8)frame->opt[i], cs_cnt++);
 455                  
 456                  /* Take complement      */
 457                  
 458                  ip_cs = ~ ip_cs;
 459          
 460                  return(ip_cs);
 461          
 462          }
 463          
 464          /** \brief Check IP frame's checksum
 465           *      \author 
 466           *              \li Jari Lahti
 467           *      \date 11.06.2002
 468           *      \param frame pointer to IP frame to be checked
 469           *      \return
 470           *              \li 0 - checksum corrupted
 471           *              \li 1 - checksum OK
 472           *
 473           *      Checksum of an IP packet is calculated and compared with the received
 474           *      checksum. Error is signaled if there is discrepancy between them.
 475           *
 476           */
 477          UINT8 ip_check_cs (struct ip_frame* frame)
 478          {
 479                  UINT16 ip_cs;
 480                  UINT8 cs_cnt;
C51 COMPILER V7.06   IP                                                                    11/26/2004 11:32:45 PAGE 9   

 481                  UINT8 olen;
 482                  UINT8 i;
 483                  
 484                  ip_cs = 0;
 485                  cs_cnt = 0;
 486                  
 487                  ip_cs = ip_checksum(ip_cs, frame->vihl, cs_cnt++);
 488                  ip_cs = ip_checksum(ip_cs, frame->tos, cs_cnt++);
 489                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->tlen >> 8), cs_cnt++);
 490                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->tlen, cs_cnt++);
 491                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->id >> 8), cs_cnt++);
 492                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->id, cs_cnt++);
 493                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->frags >> 8), cs_cnt++);
 494                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->frags, cs_cnt++);
 495                  ip_cs = ip_checksum(ip_cs, frame->ttl, cs_cnt++);
 496                  ip_cs = ip_checksum(ip_cs, frame->protocol, cs_cnt++);
 497                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->checksum >> 8), cs_cnt++);
 498                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->checksum, cs_cnt++);
 499                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 24), cs_cnt++);
 500                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 16), cs_cnt++);
 501                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->sip >> 8), cs_cnt++);
 502                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->sip, cs_cnt++);
 503                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 24), cs_cnt++);
 504                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 16), cs_cnt++);
 505                  ip_cs = ip_checksum(ip_cs, (UINT8)(frame->dip >> 8), cs_cnt++);
 506                  ip_cs = ip_checksum(ip_cs, (UINT8)frame->dip, cs_cnt++);        
 507                  
 508                  /* Is there options?                            */
 509                          
 510                  olen = ((frame->vihl & 0x0F) << 2) - IP_MIN_HLEN;
 511                  
 512                  for( i=0; i<olen; i++)
 513                          ip_cs = ip_checksum(ip_cs, (UINT8)frame->opt[i], cs_cnt++);
 514                  
 515                  /* Analyze the result   */
 516                  
 517                  ip_cs = ~ ip_cs;
 518                  
 519                  if(ip_cs == IP_GOOD_CS)
 520                          return 1;
 521                  
 522                  /* Fuck, it failed!     */
 523                  
 524                  return 0;
 525                  
 526          
 527          }
 528          
 529          /** \brief Used for constructuing IP checksum
 530           *      \author 
 531           *              \li Jari Lahti
 532           *      \date 24.02.2002
 533           *      \param cs last checksum value
 534           *      \param dat byte to be added to checksum
 535           *      \param count byte indicating whether dat is MSB or LSB byte
 536           *      \return new checksum value
 537           *
 538           *      Based on count value, dat byte is added to checksum either as a MSB
 539           *      or a LSB byte and the new checksum value is then returned.
 540           *
 541           */
 542          UINT16 ip_checksum (UINT16 cs, UINT8 dat, UINT8 count)
C51 COMPILER V7.06   IP                                                                    11/26/2004 11:32:45 PAGE 10  

 543          {
 544                  UINT8 b = dat;
 545                  UINT8 cs_l;
 546                  UINT8 cs_h;
 547                  
 548                  cs_h = (UINT8)(cs >> 8); 
 549                  cs_l = (UINT8)cs;
 550          
 551                  if( count & 0x01 ) {
 552                          /* We are processing LSB        */
 553                          
 554                          if( (cs_l = cs_l + b) < b ) {
 555                                  if( ++cs_h == 0 )
 556                                          cs_l++;
 557                          }
 558                          
 559                  } else {
 560                          /* We are processing MSB        */
 561                          
 562                          if( (cs_h = cs_h + b) < b )     {
 563                                  if( ++cs_l == 0 )
 564                                          cs_h++;
 565                          }
 566                  }
 567          
 568                  return( ( (UINT16)cs_h << 8 ) + cs_l);
 569          
 570          }
 571          

C51 COMPILATION COMPLETE.  6 WARNING(S),  1 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -