Click here to Skip to main content
16,019,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
TRK3 23-Jun-11 14:47pm    
It would help if you posted your code. It's not clear what you mean by packet, and it's impossible to tell what you are doing wrong. From my understanding of the problem it sounds pretty simple for someone with some C++ skill and shouldn't really require much VS experience (especially if you got past creating a project, compiling and running it).
missu613 23-Jun-11 23:56pm    
Maybe u are right!
I still need to continue to learn!

There are three methods.
First is to use winpcap.
Next is to use raw socket.
Last is to use TDI and NDIS hook driver.
 
Share this answer
 
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)
 
Share this answer
 
Thanks you guys helped quite a bit.
 
Share this answer
 
Just use memcpy() function.
 
Share this answer
 
v2
Comments
Richard MacCutchan 24-Jun-11 10:26am    
Removed the advertisement from your answer. If you wish to advertise on this site then please do it properly and pay for it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900