www.pudn.com > TcpIpOn8051.rar > IP.H
#define MAXDATA 1500 // Maximum Ethernet data size
#define MAXPACK (MAXDATA+14) // Maximum packet size (incl. datalink hdr)
#define MAXSEG (MAXDATA-40) // Maximum TCP data ('segment') size
#define BCASTIP 0xffffffff // Broadcast IP address
#define PCOL_ARP 0x0806 // Protocol type: ARP
#define PCOL_IP 0x0800 // IP
#define HTYPE 0x0001 // Hardware type: ethernet
#define DLENGTH 14
typedef struct{
BYTE flag;
ip destip;
BYTE num;
DWORD starttime;
WORD ttl;
BYTE arpsenf;
}arpreqbuf;
#define ARP_TTL 50
#define ARP_REQNUM 3
typedef struct{
BYTE vershlen; //协议和头部长度
BYTE servicetype; //服务类型
WORD totallen; //总长度
WORD identification; //标识
WORD fragment; //标志(4),片偏移量
BYTE ttl; //寿命
BYTE type; //协议
WORD checksum; //首部校验和
ip srcip; //源IP
ip destip; //目的IP
}ipheader;
#define PICMP 1 // Protocol type: ICMP
#define PTCP 6 // TCP
#define PUDP 17 // UDP
/* ***** IP packet ('datagram') ***** */
#define MAXIP (MAXDATA-sizeof(ipheader))
typedef struct{
ipheader i;
BYTE ipdata[MAXIP];
}ippacket;
/*********IP packet send struct**********/
typedef struct{
BYTE flag; //the flag of ip send buffer flag,0:not use 1:in use
void *net_buf; //ip send buffer head
BYTE buf_num; //the number of ip send buffer
ip dest_ip; //dest ip
BYTE p_col; //protcal
WORD lenn; //lengh
DWORD starttime; //start time
WORD ttl; //TTL
}ippack_senflag;
#define IPBUF_TTL 200
#define IP_TTL 100
#define FRAGTRIES 8 /* Number of attempts to match a fragment 匹配次数*/
#define NFRAGS 3 /* No of fragments in buffer 匹配缓冲区数量*/
typedef struct { /* Fragment buffer structure */
WORD tries; /* Number of times to attempt a match 次数记录*/
WORD ident; /* IP ident field 标识*/
DWORD sip; /* Source IP address 源ip*/
WORD oset; /* Offset in IP data area 偏移量*/
WORD len; /* Length of fragment 长度*/
BYTE fragdata[MAXIP]; /* Fragment data 数据*/
}fragbuffer;
typedef struct{
BYTE type;
BYTE icode;
WORD check;
WORD ident;
WORD seq;
}icmpheader;
#define ICREQ 8 // Message type: echo request
#define ICREP 0 // echo reply
#define ICUNREACH 3 // destination unreachable
#define ICQUENCH 4 // source quench
#define UNREACH_NET 0 // Destination Unreachable codes: network
#define UNREACH_HOST 1 // host
#define UNREACH_PORT 3 // port
#define UNREACH_FRAG 4 // fragmentation needed, but disable flag set
/* ***** ICMP packet ('datagram') ***** */
#define MAXICMP (MAXIP-sizeof(icmpheader))
typedef struct
{
ipheader i;
icmpheader c;
BYTE icmpdata[MAXICMP];
}icmppacket;
/* ***** UDP (User Datagram Protocol) header ***** */
typedef struct udph
{
WORD sport, // Source port
dport, // Destination port
len, // Length of datagram + this header
check; // Checksum of data, header + pseudoheader
}udpheader;
#define MAXUDP (MAXIP-sizeof(udpheader))
/* ***** UDP packet ('datagram') ***** */
typedef struct udp
{
ipheader i; // IP header
udpheader u; // UDP header
BYTE udpdata[MAXUDP]; // Data area
}udppacket;
/* ***** Pseudo-header for UDP or TCP checksum calculation ***** */
/* The integers must be in hi-lo byte order for checksum */
typedef struct // Pseudo-header...
{
DWORD srce, // Source IP address
dest; // Destination IP address
BYTE z, // Zero
pcol; // Protocol byte
WORD len; // UDP length field
}pheader;
/*EOF*/