开发者

How to save the packages received by a network interface or some port in a file and resend the packages received when needed?

开发者 https://www.devze.com 2023-03-31 19:54 出处:网络
I am doing my work on a server service program on Linux that processes the packages sent to the socket it listens.There is already a old such service listening on the port doing its job,and

I am doing my work on a server service program on Linux that processes the packages sent to the socket it listens.There is already a old such service listening on the port doing its job,and I can't stop 开发者_运维问答the old server service, and I need to get the packages sent to the old server and send them to my new server service to make sure it works well .How can I get the package and resent them to my new service? Is there such a tool or is there some functionality that tools such as tcpdump already provides? Thanks:)


For connection-less protocols like UDP you can record data with tcpdump and resend it with netcat.

For connection-oriented protocols like TCP, I think it's not that easy, because TCP expects your packets to have proper values in confirmed acknowledgment numbers, which will differ between your recorded packets and freshly established TCP connection. In that case, you'll need to establish connection manually (i.e., have custom app for that purpose) and re-send payload only. Maybe, there's some readily available app for that purpose (extract payload from tcpdump format and send it to the remote), I can't tell. But it's pretty easy to write such application.

By the way, same thing applies even to UDP, if your server maintains some sort of sequencing by his own -- resent packets can have sequence numbers your server does not expect to receive.

0

精彩评论

暂无评论...
验证码 换一张
取 消