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

📄 icmp.c

📁 实用的程序代码
💻 C
字号:
/* * ICMP layer specific functions */#include <net/xilsock.h>#include <string.h>/* * icmp packet handler - handles only echo requests (ping program requests) * "buf" is an IP datagram */int xilnet_icmp(unsigned char* buf, int len) {      struct xilnet_icmp_hdr *icmph = (struct xilnet_icmp_hdr*) (buf+IP_HDR_LEN*4);      if ((icmph->type == ICMP_ECHO_REQ_TYPE) && (icmph->code == ICMP_ECHO_CODE)) {      xilnet_icmp_echo_reply( buf, len);	   }   return 0;}void xilnet_icmp_echo_reply(unsigned char *buf, int len) {     short w0, w1, w2, w3;   struct xilnet_icmp_hdr* icmp_req = (struct xilnet_icmp_hdr*) (buf + IP_HDR_LEN*4);   struct xilnet_icmp_hdr* icmp_reply = (struct xilnet_icmp_hdr*)(sendbuf+LINK_HDR_LEN+IP_HDR_LEN*4);   char * icmp_buf = &sendbuf[LINK_HDR_LEN+IP_HDR_LEN*4];      icmp_reply->type = ICMP_ECHO_REPLY_TYPE;   icmp_reply->code = ICMP_ECHO_CODE;   icmp_reply->check_sum = 0;   icmp_reply->ident = icmp_req->ident;   icmp_reply->seq_no = icmp_req->seq_no;   icmp_reply->check_sum = xilnet_ip_calc_chksum(sendbuf + LINK_HDR_LEN+(IP_HDR_LEN*4), ICMP_HDR_LEN);      // call ip   xilnet_ip_header(sendbuf+LINK_HDR_LEN, ICMP_HDR_LEN+(IP_HDR_LEN*4), IP_PROTO_ICMP, (buf+IP_SADDR_BASE) );      // call ethernet   xilnet_eth_send_frame(sendbuf, len+ICMP_HDR_LEN+IP_HDR_LEN*4+ETH_HDR_LEN, (buf+IP_SADDR_BASE), NULL, ETH_PROTO_IP);   }

⌨️ 快捷键说明

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