Reconstruct a file from a TCP stream
Posted
by
Abhishek Chanda
on Programmers
See other posts from Programmers
or by Abhishek Chanda
Published on 2012-10-01T07:38:25Z
Indexed on
2012/10/01
9:49 UTC
Read the original article
Hit count: 270
c++
|networking
I have a client and a server and a third box which sees all packets from the server to the client (but not the other way around). Now when the client requests a file from the server (over HTTP), the third box sees the response. I am trying to reconstruct the file there. I am using libpcap
to capture TCP datagrams and trying to reconstruct the file there. Here is what I did
- Listen for packets on an interface
- Group all packets which have the same ACK number
- Sort the group based on SEQ number
- Extract data from each packet and combine them and write to the disk
The problem is, the file thus generated is not exactly the same as the original file. Does everything sound correct here?
Some more details:
- I am using C++
- The packet data is being stored as
std::vector<char>
- I did change the byte order while reading the ack number and seq number from the packet using
ntohl
- I am not sure if I need to change the byte order for the data as well. I tried to reverse the data from each packet before combining them, even that did not work.
Is there something I am missing?
© Programmers or respective owner