Questions tagged [socat]

socat is a relay for bidirectional data transfer between two independent data channels.

socat is a relay for bidirectional data transfer between two independent data channels. Each of these data channels may be a file, pipe, device (serial line etc. or a pseudo terminal), a socket (UNIX, IP4, IP6 - raw, UDP, TCP), an SSL socket, proxy CONNECT connection, a file descriptor (stdin etc.), the GNU line editor (readline), a program, or a combination of two of these. These modes include generation of "listening" sockets, named pipes, and pseudo terminals.

socat can be used, e.g., as TCP port forwarder (one-shot or daemon), as an external socksifier, for attacking weak firewalls, as a shell interface to UNIX sockets, IP6 relay, for redirecting TCP oriented programs to a serial line, to logically connect serial lines on different computers, or to establish a relatively secure environment (su and chroot) for running client or server shell scripts with network connections.

Many options are available to refine socats behaviour: terminal parameters, open() options, file permissions, file and process owners, basic socket options like bind address, advanced socket options like IP source routing, linger, TTL, TOS (type of service), or TCP performance tuning.

More capabilities, like daemon mode with forking, client address check, "tail -f" mode, some stream data processing (line terminator conversion), choosing sockets, pipes, or ptys for interprocess communication, debug and trace options, logging to syslog, stderr or file, and last but not least precise error messages make it a versatile tool for many different purposes.

In fact, many of these features already exist in specialized tools; but until now, there does not seem to exists another tool that provides such a generic, flexible, simple and almost comprehensive (UNIX) byte stream connector.

282 questions
5
votes
3 answers

socat:get sender's IP address

I use following code to receive a connection: socat TCP-LISTEN:4000,fork EXEC:"./myscrpit" I need to have a sender's IP address in my script but SOCAT_PEERADDR is not set, what is the problem?
Shahryar
  • 1,454
  • 2
  • 15
  • 32
5
votes
1 answer

Socat exclusive lock to PTY

I would like only one process to open the PTY device created by socat. I used the following to create my_ser device, but it can be read / written by multiple processes. socat -t 0 INTERFACE:my_nw,type=2 PTY,mode=0777,rawer,link=/dev/my_ser I tried…
Raj
  • 3,300
  • 8
  • 39
  • 67
5
votes
1 answer

Serial communication between QEMU host and guest

I'm trying to set up a pair of serial ports between my QEMU host (Debian Jessie x86_64) and guest (also Debian Jessie, but on ARM). Everything except the serial port part works. I'm really new to QEMU so there might be a better way but I've tested…
walle
  • 121
  • 1
  • 3
  • 8
5
votes
2 answers

USB Serial Port on Mac using socat

I have a piece of hardware that is connected over a Prolific Serial to USB cable and I need to use socat to send/receive traffic to/from this and a TCP port. So far it's installed and works fine with minicom using: minicom -D /dev/tty.usbserial -b…
chris
  • 131
  • 1
  • 2
  • 11
4
votes
3 answers

How to make two-directional unix domain sockets with SOCK_DGRAM?

I am trying to write a simple Unix datagram server/client, and am having some problems. What I want is a server that listens on a datagram socket and sends a reply to every message received, to the original sender. I decided to try first using socat…
fyhuang
  • 2,147
  • 5
  • 21
  • 24
4
votes
1 answer

Kubectl port-forwarding not working for IPv6 binding with socat

I'm trying to understand why this particular socat command isn't working in my case where I run it in a IPv6 only Kubernetes cluster. Cluster is build on top of AWS with Calico CNI & containerd. Provisioned using kubeadm and Kubernetes 1.21. I have…
nixgadget
  • 6,983
  • 16
  • 70
  • 103
4
votes
1 answer

socat openssl-listen - ensuring TLSv1.3 is in use

I have a working client/server scenario using socat with the following commands: Server socat openssl-listen:5000,reuseaddr,cert=server.pem,cafile=server.crt,verify=0 STDIO Client socat stdio…
robertlayton
  • 612
  • 1
  • 7
  • 20
4
votes
2 answers

Socat serial port sniffing

I'm currently trying to access data on both directions of a serial port connected to an an app. What i'm trying to do is: ttymxc0 <-----> socat sniff <------> ttyV0 <------> Application ttymxc0 is the real port and ttyV0 is the virtual one. I…
Adraub
  • 41
  • 1
  • 3
4
votes
1 answer

Socat not closing tcp connection

I use socat 1.7.3.1-r0 and run following command on an alpine 3.3 linux server: socat -d -d -d PTY,link=/dev/ttyFOOBAR,echo=0,raw,unlink-close=0 TCP-LISTEN:7000,forever,reuseaddr Socat will listen for clients and create a bidirectional…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
4
votes
1 answer

Pipe One Serial Port to Another in Linux

I am looking for a means to pipe one serial ports data (regardless of data type) to another serial port. In my case I am trying to take in data from one serial port and output it through a radio connected to another serial port in real time. I…
Ludefice
  • 45
  • 1
  • 6
4
votes
0 answers

Running remote commands, with local arguments, through socat?

I would like to set up a socat socket on Computer A, which will receive a string from a socket on Computer B. This string should be interpreted as arguments to a command that will be executed on Computer A, e.g.: Computer A: socat TCP4-L:3334,fork…
FenTheta
  • 141
  • 2
4
votes
1 answer

Multicasting with `socat` in Vagrant & VirtualBox Env

The problem: Each machine in the same network should be able to broadcast to all the members, including itself. This is an attempt to get working multicast with socat with VMs created in Vagrant & VirtualBox Envrionment. It seems things are working…
Askar
  • 5,784
  • 10
  • 53
  • 96
4
votes
1 answer

socat: log conversation with serial port

After some time, I finally got socat to behave in the same way as putty, using: stty -F /dev/ttyS2 115200 cs8 ixoff socat $(tty),raw,echo=0,escape=0x03,nonblock /dev/ttyS2 stty sane I would also like to log the conversation to a log file. EDIT: I…
Ulrik
  • 1,131
  • 4
  • 19
  • 37
4
votes
1 answer

Socat and systemd

I need to run a script, which among many things running socat. Running the script from the command line works fine, now what I want is that this script is run as a service. This is the script I have: #!/usr/bin/env sh set…
Gaspacho
  • 53
  • 1
  • 5
4
votes
2 answers

socat with a virtual tty link and fork removes my pty link

I require to be able to multiplex tcp connections to a single virtual tty for testing software that communicates over a serial port. I have been using the following command to create a server that listens on a tcp port, and then forwards data to the…
srclosson
  • 191
  • 1
  • 1
  • 7
1 2
3
18 19