icmp.c.svn-base

来自「数字广播系统的开发源码」· SVN-BASE 代码 · 共 60 行

SVN-BASE
60
字号
/*
 */

#include "GloblDef.h"
#include "TCPIPmem.h"
#include "IP.h"
#include "icmp.h"

#if ICMP_EN
/* MemHead->pStart is point to ICMP head */
void ICMPInput(struct SMemHead DT_XDATA *MemHead)	REENTRANT_MUL
{
	IP_ADDR ipaddr;
	struct SIPHead DT_XDATA *pIPHead;

	/* which type of icmp */
	switch(((struct SICMPEchoHead DT_XDATA *)(MemHead->pStart))->type)
	{
	case ICMP_TYPE_QUERY:
		
		/* chage type */
		((struct SICMPEchoHead DT_XDATA *)(MemHead->pStart))->type = ICMP_TYPE_REPLY;

		/* adjust checksum. refer to lwip: if change type from 8 to 0,
		for checksum, that is increasing 0x8000 and add flowed hight bit 
		to bit 0.*/
		if (((struct SICMPEchoHead DT_XDATA *)(MemHead->pStart))->CheckSum >= htons(0xffff - (((WORD)ICMP_TYPE_QUERY) << 8))) 
			((struct SICMPEchoHead DT_XDATA *)(MemHead->pStart))->CheckSum += htons(((WORD)ICMP_TYPE_QUERY) << 8) + 1;
		else
			((struct SICMPEchoHead DT_XDATA *)(MemHead->pStart))->CheckSum += htons(((WORD)ICMP_TYPE_QUERY) << 8);

		/*
		 *send this packet back, first fill some of IPHead field 
		 */

		/* dec pStart and get ip head */
		pIPHead = (struct SIPHead DT_XDATA *)(MemHead->pStart -= IP_HEAD_MIN_LEN);

		/* exchange ipdest and ipscr */
		ipaddr = pIPHead->IPDest;
		pIPHead->IPDest = pIPHead->IPScr;
		pIPHead->IPScr  = ipaddr;

		/* ip total length not change */

		/* protocol */
		pIPHead->Protocol = IP_PROTOCOL_ICMP;

		IPOutput(MemHead);

		/* whether send success or not free this packet */
		MemFree(MemHead);
		
		break;
	default:
		MemFree(MemHead);
	}
}

#endif

⌨️ 快捷键说明

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