简体   繁体   中英

Changing tcp/ip packets c++ or java

Here is the situation. There are server and client in network. They communicate like this:

  1. Client sends request for some function.
  2. Server sends to client function parameters.
  3. Client trying to perform function and sends answer to server.
  4. Server sends to client data which it should show.

But sometimes client can't perform function and sends error. I want to catch all packets from step 2, analyze them (I've already have tools for that), prevent some of them to reach client, process them with my program and form packet like in step 3. This must be done on client side. I have no access neither to server nor to client.

So, the question is: Is there libraries for changing, injecting and removing tcp/ip packet in c++ or java? The solution should be working in both Win and Linux systems. Also, may be you have better ideas to expand client functionality?

Thanks for any help! I tried to google how to change packets, but all I got were unanswered questions and sniffers=(

Edit: Actually, I don't really need injecting and removing packets, I can manage it with only changing packet data. Also, there is no multiple requests in the same packet, and a single request across multiple packets is not a problem.

You have to build a Proxy for your server. The client connects to the proxy, and the proxy itself connects to the server. It just routes all the packages between client and server.

BUT it is now able to intercept specific messages and to modify them. Imagine a filtering HTTP proxy, it works the same way.

I have personal experience with libpcap on linux and freeBSD, a kind of lowlevel library that helps to catch or inject packets. I did use it in an IPV6 network bridge project... But i know there is a windows port for it. http://sourceforge.net/projects/libpcap/ You can let the library to:

  1. catch packets using a filter
  2. extract data from packet
  3. you can process the data (modify them)
  4. reinject it again using the same library

But you would have to work with internal data in a quite raw matter. Best documentation for this library are comments inside its header file, that is the most up to date info. Maybe there are some more comfortable highlevel libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM