icmp.c

来自「Pic Nic 16f877/18f452控制 rtl8019as 原代码」· C语言 代码 · 共 44 行

C
44
字号
/*
 * icmp.c
 *
 * ICMP Response Routines
 *
 */

void icmpResponse() {

   int16 prev_chksum;
   int8 i, j;

   //Prepare Ethernet Packet
   load_ethernet_header();   // Load MAC source and destination addresses

   //Prepare IP header and send it to the NIC
   load_IP_header(60, ICMP); // load IP header
   chksum=0;

   //Write the ICMP Type in the NIC transmit Buffer
   outportw(NIC_DATA, (int16)icmp_code);  // Type = 0 (echo reply)

   //Compute Checksum and write it to NIC
   calc_chksum (icmp_identifier);
   calc_chksum (icmp_sequence);

   for (i=0; i<32; i+=2) {
      calc_chksum (make16(Buffer[i],Buffer[i+1]));
   }

   outportw(NIC_DATA, ~chksum);

   //Write final details to nic and send the icmp answer
   outportw(NIC_DATA,icmp_identifier);
   outportw(NIC_DATA,icmp_sequence);

   writeNicTxBuffer(Buffer, 32);
   sendPacket(74);

   lcd_pos_xy(16,1);
   printf(lcd_escreve, "I");

}

⌨️ 快捷键说明

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