c语⾔编程题报⽂解析,C语⾔解析HTTP_POST PCAP 格式包
(邮件发送)
1、
C语⾔实现PCAP⽂件分析
实现步骤:1)⽤Wireshark软件抓包得到test.pcap⽂件2)程序:分析pcap⽂件头
->
分析pcap_pkt头
->
分析帧头 ->
分析ip头
->
分析tcp头
->
分析http信息
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "netinet/in.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "arpa/inet.h"
#include "time.h"
#define BUFSIZE
10240
#define STRSIZE
1024
typedef long
bpf_int32;
typedef unsigned long
bpf_u_int32;
typedef unsigned short
u_short;
u_int32;
typedef unsigned short u_int16;
typedef unsigned char u_int8;
//pacp⽂件头结构体struct
pcap_file_header
{
bpf_u_int32 magic;
u_short version_major; u_short version_minor; bpf_int32 thiszone;
bpf_u_int32 sigfigs;
bpf_u_int32 snaplen; bpf_u_int32 linktype; };
//时间戳
struct
time_val
{
long tv_sec;
long tv_usec;
};
//pcap数据包头结构体struct
pcap_pkthdr
{
struct time_val ts;
bpf_u_int32
caplen;
bpf_u_int32 len;
};
typedef struct FramHeader_t
{
//Pcap捕获的数据帧头u_int8 DstMAC[6];
//⽬的MAC地址
u_int8 SrcMAC[6];
//源MAC地址
u_short FrameType;
//帧类型
}
FramHeader_t;
//IP数据报头
typedef struct IPHeader_t
{ //IP数据报头
u_int8 Ver_HLen;
//版本+报头长度
u_int8 TOS;  //服务类型u_int16 TotalLen;
//总长度
u_int16 ID;
//标识
u_int16 Flag_Segment; //标志+⽚偏移
u_int8 TTL;  //⽣存周期u_int8 Protocol;
//协议类型
u_int16 Checksum;
//头部校验和
u_int32 SrcIP;
//源IP地址
u_int32 DstIP;
}
IPHeader_t;
//TCP数据报头
typedef struct
TCPHeader_t
{ //TCP数据报头
u_int16 SrcPort;
//源端⼝
u_int16 DstPort;
//⽬的端⼝
u_int32 SeqNO;
//序号
u_int32 AckNO;
//确认号
u_int8 HeaderLen; //数据报头的长度(4
bit) + 保留(4 bit)
u_int8 Flags;
//标识TCP不同的控制消息
u_int16 Window;
//窗⼝⼤⼩
u_int16 Checksum;
//校验和
u_int16 UrgentPointer;
//紧急指针
}TCPHeader_t;
//
void match_http(FILE *fp, char
*head_str, char *tail_str, char *buf, int total_len); //查 http 信息函数
void urldecode(char *p);
//
int main()
{
*file_header;
struct pcap_pkthdr
*ptk_header;
IPHeader_t
*ip_header;
TCPHeader_t
*tcp_header;
FILE *fp,
*output;
编程语言下载
int  pkt_offset, i=0;
int ip_len, http_len,
ip_proto;
int src_port, dst_port,
tcp_flags;
char buf[BUFSIZE],
my_time[STRSIZE];
char src_ip[STRSIZE],
dst_ip[STRSIZE];
characcount[STRSIZE],
sendto[BUFSIZE],subject[BUFSIZE],sendcc[BUFSIZE],content[BUFSIZE]; //初始化
file_header = (struct
pcap_file_header *)malloc(sizeof(struct
pcap_file_header));
ptk_header  =
(struct pcap_pkthdr *)malloc(sizeof(struct
pcap_pkthdr));
ip_header = (IPHeader_t
*)malloc(sizeof(IPHeader_t));
tcp_header = (TCPHeader_t
*)malloc(sizeof(TCPHeader_t));
memset(buf, 0,
sizeof(buf));

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。