⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp_get.h

📁 通过完成接收IP层提交的报文
💻 H
字号:
/*ethernet header*/
typedef struct ether_header
{
    u_char ether_dhost[6];   /* 以太网目的地址 */
    u_char ether_shost[6];   /* 源以太网地址 */
    u_short ether_type;    /* 以太网类型 */
	u_char ver_ihl;  /* Version (4 bits) + Internet header length (4 bits)*/
    u_char tos; 
}ethernet_header;

/* 4 bytes IP address */
typedef struct ip_address
{
 u_char byte1;
 u_char byte2;
 u_char byte3;
 u_char byte4;
}ip_address;

/* IPv4 header */
typedef struct ip_header
{
 u_char ver_ihl;  /* Version (4 bits) + Internet header length (4 bits)*/
 u_char tos;      /* Type of service */
 u_short tlen;    /* Total length */
 u_short identification; /* Identification */ 
 u_short flags_fo;       /* Flags (3 bits) + Fragment offset (13 bits)*/
 u_char ttl;      /* Time to live */
 u_char proto;    /* Protocol */
 u_short crc;     /* Header checksum */
 ip_address saddr;/* Source address */
 ip_address daddr;/* Destination address */
 u_int op_pad;    /* Option + Padding */
}ip_header;

///记录每个到来的tcp数据报的信息;
typedef struct tcpfrag
{ 
  u_short sport;   /* Source port */
  u_short dport;   /* Destination port */
  u_long  seq;
  u_long  ack;
  u_short headlen_6res_6flag;
  u_short winsize;
  u_short checksum;
  u_short urgentptr;
  u_int op_pad;    /* Option + Padding */
}tcpfrag;


//应用层程序注册函数中所需的结构体;
typedef struct tcp_register
{
  ip_address saddr;	/* Source address */
  u_short sport;	/* Source port */
  ip_address daddr;	/* Destination address */ 
  u_short dport;	/* Destination port */
  void 	(* app_process)(short int link_posi, short int applen);
}tcp_register;

//描述tcp连接状态的tcp连接表的结构体;
///描述某个tcp连接的当前状态
typedef struct tcp_linker
{
  u_short      nullflag;
  u_short     linkstate;
  ip_address  saddr;/* Source address */
  u_short     sport;   /* Source port */
  ip_address  daddr;/* Destination address */ 
  u_short     dport;   /* Destination port */
  void 	   (* app_process)(short int link_posi, short int applen);
  u_long      curr_seq;
  u_long      next_seq;
  const u_char * uppkt;
  u_long      disorder_seq[10];
  u_long      disorder_ack[10];
  u_short     disorder_sum;
  const u_char * disorder_pkt[10];  ////缓存未按序到达的tcp分片;
}tcp_linker;

#define newtcpreg()  (tcp_register *)malloc(sizeof(tcp_register))
#define newtcplinkptr()  (tcp_linker *)malloc(sizeof(tcp_linker))
#define newtcpfragptr()  (tcpfrag *)malloc(sizeof(tcpfrag))

#define newudpptr()  (udpinfo *)malloc(sizeof(udpinfo))
#define newfragptr() (fraginfo *)malloc(sizeof(fraginfo))

/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
void firstinit();
void  tcp_register_func();//应用层程序注册函数
short int find_tcpreg(ip_header* ih, const u_char *pkt_data);
short int find_tcplink(ip_header* ih, const u_char *pkt_data);
///tcp数据报处理函数;
short int tcp_reassemble(ip_header* ih, const u_char *pkt_data, short int link_posi);
short int upmore_func(ip_header* ih, const u_char *pkt_data, short int link_posi);
void ftp_print(short int link_posi, short int applen);
void http_print(short int link_posi, short int applen);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -