//IP協議族協議頭結構(含 c聲明 和 rfc 字符圖示)
//Jurassic 2003.3.6 created.
/*++
TCP Header Format
????????????????????????????????????
??? 0?????????????????? 1?????????????????? 2?????????????????? 3???
??? 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |????????? Source Port????????? |?????? Destination Port??????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |??????????????????????? Sequence Number??????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |??????????????????? Acknowledgment Number????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |? Data |?????????? |U|A|P|R|S|F|?????????????????????????????? |
?? | Offset| Reserved? |R|C|S|S|Y|I|??????????? Window???????????? |
?? |?????? |?????????? |G|K|H|T|N|N|?????????????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |?????????? Checksum??????????? |???????? Urgent Pointer??????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |??????????????????? Options??????????????????? |??? Padding??? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |???????????????????????????? data????????????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+??????????????????????????? TCP Header Format
RFC-793
--*/
typedef?
struct _tcphdr
{
unsigned short source; //原端口地址
unsigned short dest; //目的端口地址
unsigned long seq; //序號
unsigned long ack_seq; //確認號
unsigned short doff:4; //首部長度
unsigned short resl:4; //保留
unsigned short cwr:1; //控制
unsigned short ece:1;
unsigned short urg:1;
unsigned short ack:1;
unsigned short psh:1;
unsigned short rst:1;
unsigned short syn:1;
unsigned short fin:1;
unsigned short window;
unsigned short check;
unsigned short urg_ptr;}tcphdr;

/*++
IP Header Format??? 0?????????????????? 1?????????????????? 2?????????????????? 3???
??? 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |Version|? IHL? |Type of Service|????????? Total Length???????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |???????? Identification??????? |Flags|????? Fragment Offset??? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |? Time to Live |??? Protocol?? |???????? Header Checksum?????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |?????????????????????? Source Address????????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |??????????????????? Destination Address??????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |??????????????????? Options??????????????????? |??? Padding??? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+IP Header FormatRFC-791????????????????????????????
--*/
typedef
struct _iphdr
{
unsigned char version:4; //版本
unsigned char ihl:4; //首部長度
unsigned char tos; //服務類型
unsigned short tot_len; //總長度
unsigned short id; //標志
unsigned short frag_off; //分片偏移
unsigned char ttl; //生存時間
unsigned char protocol; //協議
unsigned char check; //檢驗和
unsigned long saddr; //源IP地址
unsigned long daaddr; //目的IP地址
}iphdr;
/*++
UDP Header Format
????????????????? 0????? 7 8???? 15 16??? 23 24??? 31?
???????????????? +--------+--------+--------+--------+
???????????????? |????????? source address?????????? |
???????????????? +--------+--------+--------+--------+
???????????????? |??????? destination address??????? |
???????????????? +--------+--------+--------+--------+
???????????????? |? zero? |protocol|?? UDP length??? |
???????????????? +--------+--------+--------+--------+

UDP Header Format
RFC-768
--*/
typedef
struct _udphdr
{
unsigned short source;
unsigned short dest;
unsigned short len;
unsigned short check;}udphdr;
/*++
ICMP Header Format??? 0?????????????????? 1?????????????????? 2?????????????????? 3
??? 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |???? Type????? |???? Code????? |????????? Checksum???????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |???????????????????????????? unused??????????????????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |????? Internet Header + 64 bits of Original Data Datagram????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ICMP Header FormatRFC-792
--*/
typedef
struct _icmphdr
{
unsigned char type; //類型
unsigned char code; //代碼
unsigned short checksum; //校驗和
union
{
struct?
{
unsigned short id; //標識符
unsigned short sequence; //序號
}echo;

unsigned long gateway; //目標路由器的IP地址

struct?
{
unsigned short unused; //
unsigned short mtu;
}frag;
} un;}icmphdr;

/*++
IGMP Header Format??? 0?????????????????? 1?????????????????? 2?????????????????? 3????
??? 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1??
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+?
?? |???? Type????? |???? Code????? |?????????? Checksum??????????? |?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+?
?? |????????????????????????? Identifier?????????????????????????? |?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+?
?? |???????????????????????? Group Address???????????????????????? |?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+?
?? |?????????????????????????????????????????????????????????????? |?
?? +???????????????????????? Access Key??????????????????????????? +?
?? |?????????????????????????????????????????????????????????????? |?
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+?

IGMP Header FormatRFC-988
--*/
typedef
struct _igmphdr
{
unsigned char type;
unsigned char code; /* For newer IGMP */
unsigned short csum;
unsigned long group;}igmphdr;

/*++
IPv6 Header Format?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? | Ver.? | IHL?? |?? TOS???????? |?? Total Length??????????????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |???? Identification??????????? |Flags|?? Fragment Offset?????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |1|1|1|1|1|0| Offset| Reserved? | Source IP address part 1????? |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? |1|1|1|1|1|0| Offset| Reserved? | Destination IP address part 1 |
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? :??????????????????????????? Options??????????????????????????? :
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? : SADDR Code??? |Len adr. part 2| Source IP address part 2????? :
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? : DADDR Code??? |Len adr. part 2| Destination IP address part 2 :
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
?? :??????????????????????????? Data?????????????????????????????? :
?? +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+IPv6 Header Format?? RFC-1365
--*/
typedef
struct _ipv6hdr
{
unsigned char version:4;
unsigned char priority:4;
unsigned char flow_lbl[3];
unsigned short payload_len;
unsigned char nexthdr;
unsigned char hop_limit;
//struct in6_addr saddr;
//struct in6_addr daddr;}ipv6hdr;
[/code]
當然,為了口中餐,為了未來貼身mm,為了給她備房備車:),不得不停了下來。
下面的是未整理的結構。有時間的話,我會繼續整理,也歡迎網友補充。[code]
/*
?* This is an Ethernet frame header.
?*/
typedef?
struct _ethhdr?
{
//unsigned char h_dest[ETH_ALEN]; // destination eth addr
//unsigned char h_source[ETH_ALEN]; // source ether addr
//unsigned short h_proto; // packet type ID field}ethhdr;
// FDDI
/* Define 802.2 Type 1 header */
//struct fddi_8022_1_hdr
// {
// __u8 dsap; /* destination service access point */
// __u8 ssap; /* source service access point */
// __u8 ctrl; /* control byte #1 */
// } __attribute__ ((packed));
//
///* Define 802.2 Type 2 header */
//struct fddi_8022_2_hdr
// {
// __u8 dsap; /* destination service access point */
// __u8 ssap; /* source service access point */
// __u8 ctrl_1; /* control byte #1 */
// __u8 ctrl_2; /* control byte #2 */
// } __attribute__ ((packed));
//
///* Define 802.2 SNAP header */
//#define FDDI_K_OUI_LEN 3
//struct fddi_snap_hdr
// {
// __u8 dsap; /* always 0xAA */
// __u8 ssap; /* always 0xAA */
// __u8 ctrl; /* always 0x03 */
// __u8 oui[FDDI_K_OUI_LEN]; /* organizational universal id */
// __u16 ethertype; /* packet type ID field */
// } __attribute__ ((packed));
//
///* Define FDDI LLC frame header */
//struct fddihdr
// {
// __u8 fc; /* frame control */
// __u8 daddr[FDDI_K_ALEN]; /* destination address */
// __u8 saddr[FDDI_K_ALEN]; /* source address */
// union
// {
// struct fddi_8022_1_hdr llc_8022_1;
// struct fddi_8022_2_hdr llc_8022_2;
// struct fddi_snap_hdr llc_snap;
// } hdr;
// } __attribute__ ((packed));