I'm trying to debug a service to which clients connect using TCP (in Linux). I cannot change either program (don't have source), and I cannot make use of mechanisms which snoop on the network layer (like tcpdump, pcap, wireshark, etc).
I can configure each of service and client programs to listen or connect on whatever port or address binding I need.
I know it is possible to use the SOCAT program to forward arbitrary connections, using a command like SOCAT -d -d TCP-LISTEN:2001,bind=127.0.0.1,fork TCP:localhost:2002
. But I don't see that standard versions of socat have any mechanism for logging the data as it goes back and forth.
What I need is a way of forwarding a TCP connection in this fashion, but logging the data in both directions to a file (well, a pair of files). Ideally this strategy would only use stock Linux packages, such as socat or tee.
I realize it's likely possible to write a program which does this, using Perl or Python or similar, but for the purposes of this question, I want a way of doing with using just glue (bash, etc) and stock programs.