用C ++复制数据包 [英] Copying a Packet in C++

查看:98
本文介绍了用C ++复制数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C ++ Visual Studio读取数据包并将该数据包复制到另一个文件中.我有一些C ++技能,但很少有Visual Studio经验.有人可以帮帮我吗.当我尝试复制数据包时,输出仅显示随机字符.

解决方案

共有三种方法.
首先是使用winpcap.
接下来是使用原始套接字.
最后是使用TDI和NDIS挂钩驱动程序.
1)从您自己的应用程序中打印数据包
2)打印其他应用程序的数据包:
a)使用外部资源进行嗅探->原始套接字,嗅探驱动程序等.
b)从过程内部嗅探-> ws2_32.recv ws2_32.send

在所有情况下,我建议您将数据包打印为十六进制数字.只要数据不只是文本.

for(int i = 0; i < nSizeOfPacket; i++)
{
   printf_s("%02X ", byPacketBuffer[i]);
}


其中byPacketBuffer是无符号char *指向数据包数据的指针.



STL

for(int i = 0; i < nSizeOfPacket; i++)
{
   std::cout << std::hex << (int)byPacketBuffer[i] << " ";
}


您可以使用iomanip标头设置输出的宽度和填充. (a b ba c ca-> 0A 0B BA 0C CA)


谢谢大家的帮助.


I am trying to read in a packet and duplicate the packet in another file using C++ Visual Studio. I have some C++ skills but very little Visual Studio experience. Can someone please help me. When I try to copy the packet, the output only displays random characters.

解决方案

There are three methods.
First is to use winpcap.
Next is to use raw socket.
Last is to use TDI and NDIS hook driver.


Not sure what you are trying to achieve, but it depends on where did you get the packet.

1) Printing the packet from your own application
2) Printing the packet of other application:
a) Sniffing using external resources -> Raw Sockets, sniffing drivers etc.
b) Sniffing from inside of the process -> ws2_32.recv ws2_32.send

In all cases I recommend you to print the packet as hexdecimal numbers. As-long the data isn''t text only.

for(int i = 0; i < nSizeOfPacket; i++)
{
   printf_s("%02X ", byPacketBuffer[i]);
}


Where byPacketBuffer is unsigned char * pointer to the packet data.

OR

STL

for(int i = 0; i < nSizeOfPacket; i++)
{
   std::cout << std::hex << (int)byPacketBuffer[i] << " ";
}


You can use iomanip header to set width and fill of the output. ( a b ba c ca -> 0A 0B BA 0C CA)


Thanks you guys helped quite a bit.


这篇关于用C ++复制数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆