📄 icmp.c
字号:
/*********************************************************************************
* icmp.c v1.00 icmp协议程序 *
* 版权(c) 2004- 北京百科融创科技有限公司 *
* 设计者: 赵治心 *
* 邮箱: ourui.wl@263.net *
**********************************************************************************/
#include "stdio.h"
#include "tcp_ip.h"
#include "global.h"
#include "8019head.h"
void ping_send(UCHAR * inbuf, UCHAR *ipaddr, UINT len)
{
int i;
PING_HEADER * ping_in;
PING_HEADER * ping_out;
UCHAR * outbuf;
outbuf=(UCHAR *)SendBuffer;
ping_in = (PING_HEADER *)(inbuf + 34);
// Ping response message payload starts at offset 34
ping_out = (PING_HEADER *)(outbuf + 34);
ping_out->msg_type = 0;
ping_out->msg_code = 0;
ping_out->checksum[0] = 0;
ping_out->checksum[1] = 0;
ping_out->identifier[0] = ping_in->identifier[0];
ping_out->identifier[1] = ping_in->identifier[1];
ping_out->sequence[0] = ping_in->sequence[0];
ping_out->sequence[1] = ping_in->sequence[1];
for(i=0;i<len-8;i++)
*(outbuf+i+42)=*(inbuf+i+42);
// Compute checksum over the ICMP header plus
// optional data and insert complement
i = ~cksum(outbuf + 34, len);
ping_out->checksum[0] = (i&0xff00)>>8;
ping_out->checksum[1] = i&0x00ff;
ip_send(outbuf, ipaddr, ICMP_TYPE, len);
}
void icmp_rcve(UCHAR * inbuf, UINT len)
{
IP_HEADER * ip;
UCHAR msg_type;
UINT temp;
// Allow for 14 bytes eth header
ip = (IP_HEADER *)(inbuf + 14);
temp = cksum(inbuf + 34, len);
if (temp != 0xFFFF)
return;
// Switch on the message type
msg_type = *(inbuf + 34);
switch(msg_type)
{
case 3:
break;
case 8:
ping_send(inbuf, sed_desIPAddr, len);
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -