📄 net1.h.bak
字号:
//-----------------------------------------------------------------------------
// NET.H
//
//-----------------------------------------------------------------------------
#ifndef __NET_H__
#define __NET_H__
typedef unsigned char UCHAR;
typedef unsigned short uint;
typedef unsigned int ulong;
// 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 8080
#define TFTP_PORT 69
// 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 //v2
#define IEEE_ETHERNET 6 //802.3
typedef __packed struct
{
ulong ipaddr;
UCHAR hwaddr[6];
UCHAR timer;
} ARP_CACHE;
typedef __packed struct
{
UCHAR * buf;
ulong ipaddr;
UCHAR proto_id;
uint len;
UCHAR timer;
} WAIT;
typedef __packed struct
{
uint hardware_type; //硬件地址类型
uint protocol_type; //协议类型
UCHAR hwaddr_len;
UCHAR ipaddr_len;
uint message_type;
UCHAR source_hwaddr[6];
ulong source_ipaddr;
UCHAR dest_hwaddr[6];
ulong dest_ipaddr;
} ARP_HEADER;
typedef __packed struct
{
UCHAR dest_hwaddr[6];
UCHAR source_hwaddr[6];
uint frame_type;
} ETH_HEADER;
typedef __packed struct
{
UCHAR ver_len;
UCHAR type_of_service;
uint total_length;
uint identifier;
uint fragment_info;
UCHAR time_to_live;
UCHAR protocol_id;
uint header_cksum;
ulong source_ipaddr;
ulong dest_ipaddr;
} IP_HEADER;
typedef __packed struct
{
UCHAR msg_type;
UCHAR msg_code;
uint checksum;
uint identifier;
uint sequence;
UCHAR echo_data;
} PING_HEADER;
typedef __packed struct
{
UCHAR msg_type;
UCHAR msg_code;
uint checksum;
ulong msg_data;
UCHAR echo_data;
} ICMP_ERR_HEADER;
typedef __packed struct
{
uint source_port;
uint dest_port;
uint length;
uint checksum;
UCHAR msg_data;
} UDP_HEADER;
typedef __packed struct
{
uint source_port;
uint dest_port;
ulong sequence;
ulong ack_number;
uint flags;
uint window;
uint checksum;
uint urgent_ptr;
UCHAR options;
} TCP_HEADER;
typedef __packed struct
{
ulong ipaddr; //收到IP报文的源IP地址,即对端发方的IP地址
uint port; //收到TCP报文的源端口,即对端发方的端口
ulong his_sequence; //收到TCP报文的发送序号,即对端发方的发送序号
ulong my_sequence; //本端的发送序号
ulong old_sequence; //对端老的发送序号,为了重传
ulong his_ack; //收到TCP报文的确认序号,即对端发方的确认序号
UCHAR timer;
UCHAR inactivity; //本连接剩余的非激活时间
UCHAR state; //TCP连接的11个状态;
char query[20];
} CONNECTION;
typedef __packed struct //伪头部,计算校验和用
{
ulong m_saddr; //源地址
ulong m_daddr; //目的地址
UCHAR m_mbz;
UCHAR m_ptcl; //协议类型
uint m_tcpl; //TCP长度
}PSD_HEADER;
#define TFTP_RRQ 01 // 读请求
#define TFTP_WRQ 02 // 写请求
#define TFTP_DATA 03 // 数据包
#define TFTP_ACK 04 // 确认包
#define TFTP_ERROR 05 // 错误代码
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -