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

📄 tcp_ip.h

📁 DSP2407控制8019芯片实现的网页服务器
💻 H
字号:
//-----------------------------------------------------------------------------
// NET.H
//
//-----------------------------------------------------------------------------


typedef unsigned char  				UCHAR;
typedef unsigned int 				UINT;
typedef unsigned long				ULONG;
typedef unsigned long				LONG;

#define NONE						0
#define GET_PAGE          		1
// Constants
#define TRUE      					1
#define ON								1
#define OK                    	1
#define FALSE     					0
#define OFF								0
#define MATCH							0
#define RET		   					0x0D
#define LF								0x0A
#define SPACE		 					0x20

// Port numbers
#define ECHO_PORT						7
#define DAYTIME_PORT					13
#define CHARGEN_PORT					19
#define TIME_PORT						37
#define HTTP_PORT  					80


// Event word bits
#define EVENT_ETH_ARRIVED			0x0001
#define EVENT_AGE_ARP_CACHE			0x0002
#define EVENT_TCP_RETRANSMIT		0x0004
#define EVENT_TCP_INACTIVITY		0x0008
#define EVENT_ARP_RETRANSMIT		0x0010
#define EVENT_READ_ANALOG			0x0020
#define EVENT_RS232_ARRIVED			0x0040


// Type number field in Ethernet frame
#define IP_PACKET             	0x0800
#define ARP_PACKET            	0x0806
#define RARP_PACKET				0x8035

// Protocol identifier field in IP datagram
#define ICMP_TYPE             	1
#define IGMP_TYPE				2
#define TCP_TYPE              	6
#define UDP_TYPE              	17

// Message type field in ARP messages 
#define ARP_REQUEST           	1
#define ARP_RESPONSE          	2
#define RARP_REQUEST		    3
#define RARP_RESPONSE         	4

// Hardware type field in ARP message
#define DIX_ETHERNET          	1
#define IEEE_ETHERNET         	6

// TCP states
#define STATE_CLOSED				0
#define STATE_LISTEN				1
#define STATE_SYN_RCVD				2
#define STATE_ESTABLISHED			3
#define STATE_CLOSE_WAIT			4
#define STATE_LAST_ACK				5
#define STATE_FIN_WAIT_1			6
#define STATE_FIN_WAIT_2			7
#define STATE_CLOSING				8
#define STATE_TIME_WAIT				9


// TCP flag bits
#define FLG_FIN						0x0001
#define FLG_SYN						0x0002
#define FLG_RST						0x0004
#define FLG_PSH						0x0008
#define FLG_ACK						0x0010
#define FLG_URG						0x0020


// Miscellaneous
#define NO_CONNECTION  			5 
#define TCP_TIMEOUT				4		// = 2 seconds
#define INACTIVITY_TIME			30		// = 15 seconds



typedef struct
{
   UCHAR IFindex;
   UCHAR hwaddr[6];
   UCHAR ipaddr[4];
   UCHAR type; 
} ARP_CACHE;


typedef struct
{
	UCHAR * buf;
	ULONG ipaddr;
	UCHAR proto_id;
	UINT  len;
	UCHAR timer;
} WAIT;


typedef struct
{
   UINT  hardware_type[2]; 
   UINT  protocol_type[2];           
   UCHAR hwaddr_len;
   UCHAR ipaddr_len;               
   UINT  message_type[2];
   UCHAR source_hwaddr[6];              
   UCHAR source_ipaddr[4];
   UCHAR dest_hwaddr[6];    
   UCHAR dest_ipaddr[4];
} ARP_HEADER;


typedef struct
{
  UCHAR dest_hwaddr[6];
  UCHAR source_hwaddr[6];
  UINT  frame_type[2];
} ETH_HEADER;


typedef struct
{
   UCHAR ver_len;
   UCHAR type_of_service;
   UINT  total_length[2];
   UINT  identifier[2];
   UINT  fragment_info[2];
   UCHAR time_to_live;
   UCHAR protocol_id;
   UINT  header_cksum[2];
   UINT source_ipaddr[4];
   UINT dest_ipaddr[4];
} IP_HEADER;


typedef struct
{
   UCHAR msg_type;
   UCHAR msg_code;
   UINT  checksum[2];
   UINT  identifier[2];
   UINT  sequence[2];
   UCHAR echo_data;
} PING_HEADER;


typedef struct
{
   UCHAR msg_type;
   UCHAR msg_code;
   UINT  checksum[2];
   UCHAR msg_data[4];
   UCHAR echo_data;
} ICMP_ERR_HEADER;


typedef struct 
{
   UINT  source_port;
   UINT  dest_port;
   UINT  length;
   UINT  checksum;
   UCHAR msg_data;
} UDP_HEADER;


typedef struct
{
   UINT  source_port[2];
   UINT  dest_port[2];
   UCHAR sequence[4];
   UCHAR ack_number[4];
   UINT  flags[2];
   UINT  window[2];
   UINT  checksum[2];
   UINT  urgent_ptr[2];
   UCHAR options;
} TCP_HEADER;


typedef struct
{
  UCHAR ipaddr[4];
  UINT  port[2];
  UCHAR his_sequence[4];
  UCHAR my_sequence[4];
  UCHAR old_sequence[4];
  UCHAR his_ack[4];
  UCHAR timer;
  UCHAR inactivity;	 
  UCHAR state;
  char  query[20];
} CONNECTION;

⌨️ 快捷键说明

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