我用Winpcap+MFC+VC做一个小程序,现在可以捕获了流经网卡的数据包(比如满足TCP协议或UDP协议的),包头部分我可以分析了,能得到诸如源IP、目的IP、使用协议等等信息,但是数据包的数据部分我不会分析。我现在只希望可以分析http应用的各种信息(比如URL等),请问我该怎么做呢?
请说的详细点,谢谢!
请说的详细点,谢谢!
解决方案 »
- 如何将Listctrl中多个记录保存到txt文件中
- 各位高人,小弟一直在用C#,有一段代码要移植到VC上,无从下手,在word内实现程序插入表格,代码如下
- 应大家要求散分
- HttpQueryInfo问题,有力的出力,有钱的就不用出钱了`~~
- 怪,内存泄露在什么地方?
- 大家觉得考同济大学的软件工程硕士(在职)怎么样?
- 如何将CString类变量转换为WCHAR* 类变量?
- webbrowser组件问题(专题讨论)
- Tifflib 中文说明?
- 请教omnihttpd.obj : error LNK2001: unresolved external symbol _closesocket@4我调试了好长时间也不行
- vs2010 在不同操作系统下编译问题
- struct 里的 cstring 赋值会出错
Ip_Header* ipHeader;
Tcp_Header* tcpHeader;
unsigned int ipHeaderLen;
unsigned short sport, dport;
//Ethernet frame
Ether_Header* eh = (Ether_Header*)pkt_data;
//获得IP数据包头部的位置
ipHeader = (Ip_Header*)(pkt_data + 14); //length of ethernet header
CString sDSTIP = _T("");
sDSTIP.Format("%d.%d.%d.%d",ipHeader->ipSourceByte.byte1,ipHeader->ipSourceByte.byte2
,ipHeader->ipSourceByte.byte3,ipHeader->ipSourceByte.byte4);//不是本机发送的包,不予处理,直接返回
if(sSelectAdapterIP != sDSTIP)
return;//获得TCP首部的位置
ipHeaderLen = (ipHeader->iphVerLen & 0xf) * 4; //length of ip header
tcpHeader = (Tcp_Header*)(pkt_data + 14 + ipHeaderLen);// 将端口信息从网络型转变为主机顺序
sport = ntohs(tcpHeader->sourcePort);
dport = ntohs(tcpHeader->destinationPort);UCHAR Flags = tcpHeader->flags; //得到Tcp数据部分的位置
unsigned int TcpHeadLen = ((tcpHeader->headerLen_unUsed & 0xf0) >> 4) * 4; // 高4位表示数据偏移
unsigned char* HttpData = (unsigned char*)tcpHeader+TcpHeadLen;unsigned int IpLength = ntohs(ipHeader->ipLength);
unsigned int HttpDataLen = IpLength - ipHeaderLen - TcpHeadLen;sHttpData = HttpData;
IP层得到的包不一定是顺序的
所以要根据那些序列号把包组合成一串TCP包