当然,我只是想了解原理,如果有源码就更好了,请发到117712#sina*com,立马给分,如果没有讲讲原理也行,我先说说我现在的进展,我需要获取到tcp发送端口和接收端口,目前从网上下出来一个tcp_header的结构体,总是不正确(获取到的发送端口和接收端口不正确),这里我给出代码给各位高手看看,struct ip_header //IP协议数据结构
{
u_int8_t ip_hlen :4, //首部长度
ip_version:4; //IP版本
u_int8_t ip_tos; //服务类型
u_int16_t ip_length; //总长
u_int16_t ip_id; //标识
u_int16_t ip_offset:13,ip_flag:3; //片偏移|标志
u_int8_t ip_ttl; //生存时间
u_int8_t ip_protocol; //协议
u_int16_t ip_sum; //首部校检和
u_int8_t ip_src_address[4]; //来源地址
u_int8_t ip_dst_address[4]; //目的地址
u_int32_t ip_op_pad; // 选项与填充(Option + Padding)
};//------------------------------------------------------------------
struct tcp_header //TCP协议数据结构
{
u_int16_t tcp_src_port; //源端口
u_int16_t tcp_dst_port; //目的端口
u_int32_t tcp_sn; //序列号
u_int32_t tcp_ack; //确认号
u_int8_t tcp_reserved4:4, //保留字段低4bit
tcp_hlen:4; //tcp头部长度
u_int8_t tcp_ctrl_fin:1, //终止连接位
tcp_ctrl_syn:1, //同步序列位
tcp_ctrl_rst:1, //复位连接位
tcp_ctrl_psh:1, //PUSH请求位
tcp_ctrl_ack:1, //确认字段有效位
tcp_ctrl_urg:1, //紧急指针有效位
tcp_reserved2:2; //保留字段高2bit
u_int16_t tcp_wnd_size; //窗口大小
u_int16_t tcp_sum; //校检和
u_int16_t tcp_urgent_ptr; //紧急指针
u_int32_t tcp_op_pad; //填充
};// 上面是定义 // 取得IP头
m_ip = (struct ip_header *)(data+14); // 取得Tcp头
tcp_header *tcpHeader = (struct tcp_header*)(data+14+20);
CString aabb;
aabb.Format("Come: %d To: %d", tcpHeader->tcp_src_port, tcpHeader->tcp_dst_port);
AfxMessageBox(aabb);// 输出的端口和sniffer上显示的始终对不上,请各位大牛帮忙研究一下,谢谢,能给出能运行的代码最好了,分不是问题!
{
u_int8_t ip_hlen :4, //首部长度
ip_version:4; //IP版本
u_int8_t ip_tos; //服务类型
u_int16_t ip_length; //总长
u_int16_t ip_id; //标识
u_int16_t ip_offset:13,ip_flag:3; //片偏移|标志
u_int8_t ip_ttl; //生存时间
u_int8_t ip_protocol; //协议
u_int16_t ip_sum; //首部校检和
u_int8_t ip_src_address[4]; //来源地址
u_int8_t ip_dst_address[4]; //目的地址
u_int32_t ip_op_pad; // 选项与填充(Option + Padding)
};//------------------------------------------------------------------
struct tcp_header //TCP协议数据结构
{
u_int16_t tcp_src_port; //源端口
u_int16_t tcp_dst_port; //目的端口
u_int32_t tcp_sn; //序列号
u_int32_t tcp_ack; //确认号
u_int8_t tcp_reserved4:4, //保留字段低4bit
tcp_hlen:4; //tcp头部长度
u_int8_t tcp_ctrl_fin:1, //终止连接位
tcp_ctrl_syn:1, //同步序列位
tcp_ctrl_rst:1, //复位连接位
tcp_ctrl_psh:1, //PUSH请求位
tcp_ctrl_ack:1, //确认字段有效位
tcp_ctrl_urg:1, //紧急指针有效位
tcp_reserved2:2; //保留字段高2bit
u_int16_t tcp_wnd_size; //窗口大小
u_int16_t tcp_sum; //校检和
u_int16_t tcp_urgent_ptr; //紧急指针
u_int32_t tcp_op_pad; //填充
};// 上面是定义 // 取得IP头
m_ip = (struct ip_header *)(data+14); // 取得Tcp头
tcp_header *tcpHeader = (struct tcp_header*)(data+14+20);
CString aabb;
aabb.Format("Come: %d To: %d", tcpHeader->tcp_src_port, tcpHeader->tcp_dst_port);
AfxMessageBox(aabb);// 输出的端口和sniffer上显示的始终对不上,请各位大牛帮忙研究一下,谢谢,能给出能运行的代码最好了,分不是问题!
解决方案 »
- 如何探测socket是否保持SO_KEEPALIVE??
- 新手弹出对话框的问题,帮帮我。
- 如果在SDI中实现dialogbar的位置设置?
- 怎么取一个字符串的其中某些位,用vc老长时间了,但总是写一些固定的东西,故依然要问很弱问题
- 请问:OnDraw()为什么执行不了
- 555,带参数的应用程序怎么写???
- 我编译msdn里的activex的sample的时候,怎么总是说mfc42u.lib没找到(我用的是vc++6.0)
- 在VC中调用atl com,还没调用,只是include文件就出错,这是为什么???
- 右键单击任务栏上的应用程序弹出菜单的消息怎么截获,是什么消息呢?
- 请问:怎样在磁盘上建立二进制文件?并且怎样将字符串拆成二进制写入此文件中?
- vc6 从SQL里通过时间字段选取数据
- 有没有VC关于自绘方面的书籍啊?
改成
aabb.Format("Come: %d To: %d", htons(tcpHeader->tcp_src_port), htons(tcpHeader->tcp_dst_port));htons使用前需要
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
谢谢,你是我的救命草!再次感谢!