📄 gprs_ip.h
字号:
/* Ensure network structures aren't padded (DJGPP and VC) */
#define MAXDATA 1500 /* Maximum Ethernet data size */
#define MAXPACK (MAXDATA-8) /* Maximum packet size (incl. datalink hdr) */
#define MAXSEG (MAXDATA-40) /* Maximum TCP data ('segment') size */
/* Structure for one node */
typedef struct
{
unsigned long ip; /* IP addr */
unsigned short port; /* TCP or UDP port number */
} NODE;
/* ***** IP (Internet Protocol) header ***** */
typedef struct
{
unsigned char vhl, /* Version and header len */
service; /* Quality of IP service */
unsigned short len, /* Total len of IP datagram */
ident, /* Identification value */
frags; /* Flags & fragment offset */
unsigned char ttl, /* Time to live */
pcol; /* Protocol used in data area */
unsigned short check; /* Header checksum */
unsigned long sip, /* IP source addr */
dip; /* IP dest addr */
} IPHDR;
#define PICMP 1 /* Protocol type: ICMP */
#define PTCP 6 /* TCP */
#define PUDP 17 /* UDP */
/* ***** IP packet ('datagram') ***** */
#define MAXIP (MAXPACK-sizeof(IPHDR))
typedef struct
{
IPHDR i; /* IP header */
unsigned char ipdata[MAXIP]; /* Data area */
} IPKT;
/* ***** ICMP (Internet Control Message Protocol) header ***** */
typedef struct
{
unsigned char type, /* Message type */
codetype; /* Message code */
unsigned short check, /* Checksum */
ident, /* Identifier (possibly unused) */
seq; /* Sequence number (possibly unused) */
} ICMPHDR;
#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(ICMPHDR))
typedef struct icmp
{
IPHDR i; /* IP header */
ICMPHDR c; /* ICMP header */
unsigned char icmpdata[MAXICMP]; /* Data area */
} ICMPKT;
/* ***** UDP (User Datagram Protocol) header ***** */
typedef struct udph
{
unsigned short sport, /* Source port */
dport, /* Destination port */
len, /* Length of datagram + this header */
check; /* Checksum of data, header + pseudoheader */
} UDPHDR;
#define MAXUDP (MAXIP-sizeof(UDPHDR))
/* ***** UDP packet ('datagram') ***** */
typedef struct udp
{
IPHDR i; /* IP header */
UDPHDR u; /* UDP header */
unsigned char udpdata[MAXUDP]; /* Data area */
} UDPKT;
/* ***** Pseudo-header for UDP or TCP checksum calculation ***** */
/* The integers must be in hi-lo byte order for checksum */
typedef struct /* Pseudo-header... */
{
unsigned long srce, /* Source IP address */
dest; /* Destination IP address */
unsigned char z, /* Zero */
pcol; /* Protocol byte */
unsigned short len; /* UDP length field */
} PHDR;
/* ***** TCP (Transmission Control Protocol) header ***** */
typedef struct tcph
{
unsigned short sport, /* Source port */
dport; /* Destination port */
unsigned long seq, /* Sequence number */
ack; /* Ack number */
unsigned char hlen, /* TCP header len (num of bytes << 2) */
flags; /* Option flags */
unsigned short window, /* Flow control credit (num of bytes) */
check, /* Checksum */
urgent; /* Urgent data pointer */
} TCPHDR;
#define MAXTCP (MAXIP-sizeof(TCPHDR))
#define TFIN 0x01 /* Option flags: no more data */
#define TSYN 0x02 /* sync sequence nums */
#define TRST 0x04 /* reset connection */
#define TPUSH 0x08 /* push buffered data */
#define TACK 0x10 /* acknowledgement */
#define TURGE 0x20 /* urgent */
/* ***** TCP packet ('segment') ***** */
typedef struct tcp
{
IPHDR i; /* IP header */
TCPHDR t; /* TCP header */
unsigned char tcpdata[MAXTCP]; /* Data area (oversized) */
} TCPKT;
extern IPKT * ip_in; // 接收的IP 数据包
extern IPKT * ip_out; // 要发送的IP 数据包
extern NODE locnode; //本机的节点信息结构(ip,port)
/* Prototypes */
short is_ip(short len);
void make_ip(NODE *srcep, NODE *destp, unsigned char pcol, unsigned short dlen);
void swap_ip(IPKT * ip);
void getip_srce(NODE *np);
unsigned short getip_locdest(NODE *np);
short is_icmp(short len);
void make_icmp(NODE *srcep, NODE *destp, unsigned char type, unsigned char codetype,unsigned char *dat,unsigned short dlen);
//short icmp_unreach(NODE *srcep, NODE *destp, BYTE codetype);
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -