7

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.

1 Answer 1

7

Add the -v option to print out the data being transferred:

SOCAT -v -d -d TCP-LISTEN:2001,bind=127.0.0.1,fork TCP:localhost:2002

In order to write it to a file add (Windows):

 1> log.log 2>&1
1
  • 1
    For my socat version (version 1.7.4.1), checkout man socat, there some helpful options like -v, -x, -r <file> and -R <file> .
    – immerzl
    Oct 18, 2022 at 3:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .