socket 各種頭數據結構及簡要說明
發布者: 許超 發表日期: 2006-06-12 18:44:51.153 原作者: supermgr
socket 各種頭數據結構,及簡要說明。
//DATATYPE
typedef signed char int8;
typedef signed short int16;
typedef signed long int32;
typedef signed long long int64;
typedef unsigned int uint;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
typedef float float32;
typedef double float64;
typedef wchar_t wchar;
//typedef void* ptr;
typedef int32 boolen;
//IP 頭結構
typedef
struct _x_iphdr
{
uint8 ver; //4 位頭結構長度 ,4 位 IP 版本號
uint8 tos; //8 位服務類型 TOS
uint16 len; //16 位總長度(字節)
uint16 ident; //16 位數據包標識
uint16 frag; //3 位標志位 /13 位偏移地址
uint8 ttl; //8 位生存時間 TTL (生命期)
uint8 proto; //8 位協議 (TCP, UDP 或其他 )
uint16 sum; //16 位 IP 頭結構校驗和
uint32 srcip; //32 位源 IP 地址
uint32 dstip; //32 位目的 IP 地址
}x_iphdr;
//TCP 偽頭結構
typedef
struct _x_tcphdrpsd
{
uint32 saddr; // 源地址
uint32 daddr; // 目的地址
uint8 mbz; // 沒用
uint8 proto; // 協議類型
uint16 tcpl; //TCP 長度
}x_tcphdrpsd;
//TCP 頭結構
typedef
struct _x_tcphdr
{
uint16 sport; //16 位源端口
uint16 dport; //16 位目的端口
uint32 seq; //32 位序列號
uint32 ack; //32 位確認號
uint8 len; //4 位頭結構長度 /6 位保留字
uint8 flag; //6 位標志位 (控制用)
uint16 win; //16 位窗口大小
uint16 sum; //16 位 TCP 校驗和
uint16 urp; //16 位緊急數據偏移量
}x_tcphdr;
//UDP 頭結構
typedef
struct _x_udphdr
{
uint16 sport; //16 位源端口
uint16 dport; //16 位目的端口
uint16 len; //16 位長度
uint16 sum; //16 位校驗和
}x_udphdr;
//ICMP 頭結構
typedef
struct _x_icmphdr
{
uint8 type; //8 位類型
uint8 code; //8 位代碼
uint16 cksum; //16 位校驗和
uint16 ident; // 識別號(一般用進程號作為識別號)
uint16 seq; // 報文序列號
uint32 tamp; // 時間戳
}x_icmphdr;
//IGMP 頭結構
typedef
struct _x_igmphdr
{
uint8 code; //8 位代碼
uint8 type; //8 位類型
uint16 res; // 沒用
uint16 cksum; //16 位校驗和
uint32 addr; //32 位組地址
}x_igmphdr;
posted on 2007-01-11 23:16
frank.sunny 閱讀(1638)
評論(1) 編輯 收藏 引用 所屬分類:
概念掃盲