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

📄 ip.h

📁 实现在ARM上的ICP/IP功能的源代码。
💻 H
字号:


/* IP */
//#define IP_ENABLE_FORWARD	/* enable packet come in an forward act as a router */
#define IP_VERSION_4	4

#define IP_HEAD_MIN_LEN	20	/* ip head len with no option */

#define IP_INITIAL_LIFE 20

#define IP_PROTOCOL_TCP		0x06	
#define IP_PROTOCOL_ICMP	0x01
#define IP_PROTOCOL_UDP		0x11		//UDP protocol
#define IP_PROTO_UDP		0x11
/* caculate ip version of a packet */
#define IP_VERSION(pIPHead) (pIPHead->Ver_HeadLen>>4)

/* caculate ip head len of a packet.head len in Ver_HeadLen 
is mulitple of 4 byte */
#define IP_HEAD_LEN(pIPHead) ((pIPHead->Ver_HeadLen & 0x0f)*4)

typedef DWORD IP_ADDR;

__packed struct SIPHead
{
	/* Version 4 bits, HeadLength 4 bits. typical value is 0x45 */
	BYTE Ver_HeadLen;	

	/* Precedence(priority) 3 bits, Delay, Throughput, Reliability
	, reserved 2 bits. typical value 0x00 */
	BYTE ServeType;	

	WORD TotalLen;				/* all size of IP packet inlcude IPHead. 16 bits */
	WORD FragmentID;			/* 16 bits */

	/* Reserved 1 bit, May be fragmented 1 bit, Last fragment 1 bit, 
	Fragment offset 13 bits. typical 0x00 */
#define	IP_FRAGMENT_OFFSET_MASK	0x1FFF
	WORD FragmentFlag_Offset;	

	BYTE LifeLength;			/* ttl */
	BYTE Protocol;				/* eg. IP_PROTOCAL_TCP*/
	WORD CheckSum;				/* 16 bits */
	IP_ADDR IPScr;				/* 32 bits */
	IP_ADDR IPDest;
};

WORD CheckSum(WORD   * buff,WORD size,DWORD InSum)  ;
void IPInput(struct SMemHead   *MemHead)  ;
BOOL IPOutput(struct SMemHead   * MemHead)  ;

⌨️ 快捷键说明

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