千家信息网

网络协议结构体-02

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,/*********************************************/#define ETHER_ADDR_LEN 6 //NIC物理地址占6字节#define MAXDATA
千家信息网最后更新 2026年10月31日网络协议结构体-02


/*********************************************/

#define ETHER_ADDR_LEN 6 //NIC物理地址占6字节
#define MAXDATA 10240
/*

数据包中的TCP包头,IP包头,UDP包头,ARP包,Ethernet包等.
以及各种表.路由寻址表,地址解析协议表DNS表等
*/

#define ETHERTYPE_IP 0x0800 //IP Protocal
#define ETHERTYPE_ARP 0x0806 //Address Resolution Protocal
#define ETHERTYPE_REVARP 0x0835 //Reverse Address Resolution Protocal 逆地址解析协议
/*********************************************/


//ethernet
typedef struct ether_header
{
u_char ether_dhost[ETHER_ADDR_LEN];
u_char ether_shost[ETHER_ADDR_LEN];
u_short ether_type;
}ETH_HEADER;


//arp
typedef struct arphdr
{
u_short ar_hrd;
u_short ar_pro;
u_char ar_hln;
u_char ar_pln;
u_short ar_op;
}ARP_HEADER;

//IP报头
typedef struct ip
{
u_int ip_v:4; //version(版本)
u_int ip_hl:4; //header length(报头长度)
u_char ip_tos;
u_short ip_len;
u_short ip_id;
u_short ip_off;
u_char ip_ttl;
u_char ip_p;
u_short ip_sum;
struct in_addr ip_src;
struct in_addr ip_dst;
}IP_HEADER;



//TCP报头结构体
typedef struct tcphdr
{
u_short th_sport;
u_short th_dport;
u_int th_seq;
u_int th_ack;
u_int th_off:4;
u_int th_x2:4;
u_char th_flags;
u_short th_win;
u_short th_sum;
u_short th_urp;
}TCP_HEADER;

#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20

//UDP报头结构体*/
typedef struct udphdr
{
u_short uh_sport;
u_short uh_dport;
u_short uh_ulen;
u_short uh_sum;
}UDP_HEADER;


/*ARP与ETHERNET生成的报头*/
typedef struct ether_arp
{
struct arphdr ea_hdr;
u_char arp_sha[ETHER_ADDR_LEN];
u_char arp_spa[4];
u_char arp_tha[ETHER_ADDR_LEN];
u_char arp_tpa[4];
}ETH_ARP;

#define arp_hrd ea_hdr.ar_hrd
#define arp_pro ea_hdr.ar_pro
#define arp_hln ea_hdr.ar_hln
#define arp_pln ea_hdr.ar_pln
#define arp_op ea_hdr.ar_op
#define ARPHRD 1


//tcp与ip生成的报头
typedef struct packet_tcp
{
struct ip ip;
struct tcphdr tcp;
u_char data[MAXDATA];
}TCP_IP;


//udp与ip生成的报头
typedef struct packet_udp
{
struct ip ip;
struct udphdr udp;
}UDP_IP;


//ICMP的各种形式
//icmpx,x==icmp_type;
//icmp报文(能到达目的地,响应-请求包)
struct icmp8
{
u_char icmp_type; //type of message(报文类型)
u_char icmp_code; //type sub code(报文类型子码)
u_short icmp_cksum;
u_short icmp_id;
u_short icmp_seq;
char icmp_data[1];
};


//icmp报文(能返回目的地,响应-应答包)
struct icmp0
{
u_char icmp_type; //type of message(报文类型)
u_char icmp_code; //type sub code(报文类型子码)
u_short icmp_cksum;
u_short icmp_id;
u_short icmp_seq;
char icmp_data[1];
};


//icmp报文(不能到达目的地)
struct icmp3
{
u_char icmp_type; //type of message(报文类型)
u_char icmp_code; //type sub code(报文类型子码),例如:0网络原因不能到达,1主机原因不能到达...
u_short icmp_cksum;
u_short icmp_pmvoid;
u_short icmp_nextmtu;
char icmp_data[1];
};


//icmp报文(重发结构体)
struct icmp5
{
u_char icmp_type; //type of message(报文类型)
u_char icmp_code; //type sub code(报文类型子码)
u_short icmp_cksum;
struct in_addr icmp_gwaddr;
char icmp_data[1];
};

struct icmp11
{
u_char icmp_type; //type of message(报文类型)
u_char icmp_code; //type sub code(报文类型子码)
u_short icmp_cksum;
u_int icmp_void;
char icmp_data[1];
};

报文 类型 报头 结构 地址 目的 目的地 包头 生成 原因 网络 主机 字节 形式 数据 版本 物理 路由 长度 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 哈尔滨大商圈互联网科技有限公司 互联网科技产业 互联网科技工作委员会副主任毛军 西安互联网科技 紫鲸互联网科技 深圳天众互联网科技公司 甘肃拓世互联网科技有限公司 南平创想时代互联网科技有限公司 荆州市昕露互联网络科技有限公司 互联网科技产业特征 华夏恒生互联网科技013171 皮皮虾互联网科技有限公司 浙南科技城互联网大厦招聘 西安有哪些互联网高科技企业 中国互联网公司的科技投入 悟空问答互联网科技 盐城市攀科互联网科技有限公司 河南商务圈互联网科技有限公司 科技美学互联网 艺术 每日互联网科技新闻 互联网络科技有限公司 为想互联网科技 央行互联网金融科技公司 北京华百购互联网科技有限公司 上海宁丞科技互联网 广州市恰铎互联网科技有限公司 天津腾达互联网科技有限公司 深圳互联网科技的发展 互联网硬科技公司 科技互联网经济论坛
0