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

📄 icmp.c

📁 此文档为采用FPGA实现的以太网MAC层
💻 C
字号:
#include "ip.h"#include "mac.h"#include "serial.h"#include "icmp.h"#include "mac_low.h"ICMPHEADER icmp_header;extern Uint16 data_buffer[100];extern PACKET_STRUCT txpacket;void icmp_process(ICMPHEADER *packet,Uint16 data_len, Uint16 src_ip_h, Uint16 src_ip_l){    Uint16 len;    //Test if PING    if (packet->type == ICMP_PING)    {       len = data_len - ICMP_SIZE/2;        //Len now holds payload length in words       //read back len*2 bytes       //mac_read(len,(Uint16 *) data_buffer);       icmp_handler(packet,data_len,src_ip_h,src_ip_l);    }}void icmp_handler(ICMPHEADER *packet,Uint16 data_len, Uint16 src_ip_h, Uint16 src_ip_l){    Uint16 len,*buf,x,*buf2;    Uint8 *tmpptr;    Uint32 word;    //Test if PING    if (packet->type == ICMP_PING)    {       //Modify packet and send out       packet->type = ICMP_ECHO;       packet->checksum = 0x0000;       len = data_len - ICMP_SIZE/2;        //Len now holds payload length in words       //Set buffer to point afer packet       //buf = (Uint16 *) (EMAC_RX_PTR + ETH_SIZE + IP_SIZE + ICMP_SIZE);       word = (Uint32) packet;       word += (ICMP_SIZE);       //dbg_string((Uint16 *) &word,2);       buf = (Uint16 *) (word);       //Fill in checksum       packet->checksum = ip_chksum2((Uint16 *) packet,ICMP_SIZE/2,buf,len);       //fill out data portion       //packet_reset();       //packet_add(data_buffer, len);       //packet_add((Uint16 *) packet,ICMP_SIZE/2);       //Copy data buffer to tx buffer       buf2 = (Uint16 *) (EMAC_TX_PTR+ICMP_DATA_OFFSET);       for (x=0;x<len;x++)       {          buf2[x]=buf[x];       }       //Copy header into Tx Buffer       buf2 = (Uint16 *) (EMAC_TX_PTR+ICMP_OFFSET);       buf = (Uint16 *) packet;       for (x=0;x<(ICMP_SIZE/2);x++)       {          buf2[x]=buf[x];       }       //Send back to IP layer       ip_send(src_ip_h,src_ip_l,data_len,PROTOCOL_ICMP);    }}

⌨️ 快捷键说明

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