socat [options] <address> <address>
socat -V
socat -h[h[h]] | -?[?[?]]
filan
procan
Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of different types of data sinks and sources (see address types), and because lots of address options may be applied to the streams, socat can be used for many different purposes.
Filan is a utility that prints information about its active file descriptors to stdout. It has been written for debugging socat, but might be useful for other purposes too. Use the -h option to find more infos.
Procan is a utility that prints information about process parameters to stdout. It has been written to better understand some UNIX process properties and for debugging socat, but might be useful for other purposes too.
The life cycle of a socat instance typically consists of four phases.
In the init phase, the command line options are parsed and logging is initialized.
During the open phase, socat opens the first address and afterwards the second address. These steps are usually blocking; thus, especially for complex address types like socks, connection requests or authentication dialogs must be completed before the next step is started.
In the transfer phase, socat watches both streams' read and write file descriptors via select() , and, when data is available on one side and can be written to the other side, socat reads it, performs newline character conversions if required, and writes the data to the write file descriptor of the other stream, then continues waiting for more data in both directions.
select()
When one of the streams effectively reaches EOF, the closing phase begins. Socat transfers the EOF condition to the other stream, i.e. tries to shutdown only its write stream, giving it a chance to terminate gracefully. For a defined time socat continues to transfer data in the other direction, but then closes all remaining channels and terminates.
Socat provides some command line options that modify the behaviour of the program. They have nothing to do with so called address options that are used as parts of address specifications.
-V
-h | -?
-hh | -??
-hhh | -???
-d
-d0
-d -d | -dd | -d2
-d -d -d | -ddd | -d3
-d -d -d -d | -dddd | -d4
-D
--experimental
-ly[<facility>]
-lf
<logfile>
-ls
-lp
<progname>
-lu
-lm[<facility>]
-lh
uname()
-v
-x
-r <file>
$$
$PROGNAME
$TIMESTAMP
MICROS
-R <file>
-b
<size>
-s
-S
<signals-bitmap>
-t
<timeout>
-T
-u
-U
-g
-L
<lockfile>
-W
-4
-6
--statistics
With the address command line arguments, the user gives socat instructions and the necessary information for establishing the byte streams.
An address specification usually consists of an address type keyword, zero or more required address parameters separated by ':' from the keyword and from each other, and zero or more address options separated by ','.
The keyword specifies the address type (e.g., TCP4, OPEN, EXEC). For some keywords there exist synonyms ('-' for STDIO, TCP for TCP4). Keywords are case insensitive. For a few special address types, the keyword may be omitted: Address specifications starting with a number are assumed to be FD (raw file descriptor) addresses; if a '/' is found before the first ':' or ',', GOPEN (generic file open) is assumed.
The required number and type of address parameters depend on the address type. E.g., TCP4 requires a server specification (name or address), and a port specification (number or service name).
Zero or more address options may be given with each address. They influence the address in some ways. Options consist of an option keyword or an option keyword and a value, separated by '='. Option keywords are case insensitive. For filtering the options that are useful with an address type, each option is member of one option group. For each address type there is a set of option groups allowed. Only options belonging to one of these address groups may be used (except with option -g).
Address specifications following the above schema are also called single address specifications. Two single addresses can be combined with "!!" to form a dual type address for one channel. Here, the first address is used by socat for reading data, and the second address for writing data. There is no way to specify an option only once for being applied to both single addresses.
Usually, addresses are opened in read/write mode. When an address is part of a dual address specification, or when option -u or -U is used, an address might be used only for reading or for writing. Considering this is important with some address types.
With socat version 1.5.0 and higher, the lexical analysis tries to handle quotes and parenthesis meaningfully and allows escaping of special characters. If one of the characters ( { [ ' is found, the corresponding closing character - ) } ] ' - is looked for; they may also be nested. Within these constructs, socats special characters and strings : , !! are not handled specially. All those characters and strings can be escaped with \ or within ""
This section describes the available address types with their keywords, parameters, and semantics.
CREATE:<filename>
creat()
creat
DCCP-CONNECT:<host>:<port>
DCCP:<host>:<port>
DCCP4-CONNECT:<host>:<port>
DCCP4:<host>:<port>
DCCP6-CONNECT:<host>:<port>
DCCP6:<host>:<port>
DCCP-LISTEN:<port>
DCCP-L:<port>
DCCP4-LISTEN:<port>
DCCP4-L:<port>
DCCP6-LISTEN:<port>
DCCP6-L:<port>
EXEC:<command-line>
execvp()
$PATH
socketpair()
FD:<fdnum>
GOPEN:<filename>
sendto()
O_APPEND
O_CREAT
IP-SENDTO:<host>:<protocol>
INTERFACE:<interface>
IP4-SENDTO:<host>:<protocol>
IP6-SENDTO:<host>:<protocol>
IP-DATAGRAM:<address>:<protocol>
IP4-DATAGRAM:<host>:<protocol>
IP6-DATAGRAM:<host>:<protocol>
IP-RECVFROM:<protocol>
IP4-RECVFROM:<protocol>
IP6-RECVFROM:<protocol>
IP-RECV:<protocol>
IP4-RECV:<protocol>
IP6-RECV:<protocol>
OPEN:<filename>
open()
OPENSSL:<host>:<port>
OPENSSL-LISTEN:<port>
OPENSSL-DTLS-CLIENT:<host>:<port>
OPENSSL-DTLS-SERVER:<port>
PIPE:<filename>
-b 2048
PIPE
SOCKETPAIR
POSIXMQ-READ:/<mqueue>
POSIXMQ-RECEIVE:/<mqueue>
POSIXMQ-RECV:/<mqueue>
POSIXMQ-SEND:/<mqueue>
POSIXMQ-BIDIRECTIONAL:/mqueue
PROXY:<proxy>:<hostname>:<port>
PTY
READLINE
SCTP-CONNECT:<host>:<port>
SCTP4-CONNECT:<host>:<port>
SCTP6-CONNECT:<host>:<port>
SCTP-LISTEN:<port>
SCTP4-LISTEN:<port>
SCTP6-LISTEN:<port>
SOCKET-CONNECT:<domain>:<protocol>:<remote-address>
SOCK_STREAM
SOCKET-DATAGRAM:<domain>:<type>:<protocol>:<remote-address>
SOCKET-LISTEN:<domain>:<protocol>:<local-address>
SOCKET-RECV:<domain>:<type>:<protocol>:<local-address>
SOCKET-RECVFROM:<domain>:<type>:<protocol>:<local-address>
SOCKET-SENDTO:<domain>:<type>:<protocol>:<remote-address>
ACCEPT-FD:<fdnum>
SOCKS4:<socks-server>:<host>:<port>
SOCKS4A:<socks-server>:<host>:<port>
SOCKS5-CONNECT:<socks-server>:<socks-port>:<target-host>:<target-port>
SOCKS5-LISTEN:<socks-server>:<socks-port>:<listen-host>:<listen-port>
STDERR
STDIN
STDIO
STDOUT
SHELL:<shell-command>
SYSTEM:<shell-command>
system()
TCP:<host>:<port>
TCP4:<host>:<port>
TCP6:<host>:<port>
TCP-LISTEN:<port>
TCP4-LISTEN:<port>
TCP6-LISTEN:<port>
TUN[:<if-addr>/<bits>]
/dev/net/tun
ioctl()s
UDP:<host>:<port>
UDP4:<host>:<port>
UDP6:<host>:<port>
UDP-DATAGRAM:<address>:<port>
UDP4-DATAGRAM:<address>:<port>
UDP6-DATAGRAM:<address>:<port>
UDP-LISTEN:<port>
UDP4-LISTEN:<port>
UDP6-LISTEN:<port>
UDP-SENDTO:<host>:<port>
UDP4-SENDTO:<host>:<port>
UDP6-SENDTO:<host>:<port>
UDP-RECVFROM:<port>
UDP4-RECVFROM:<port>
UDP6-RECVFROM:<port>
UDP-RECV:<port>
UDP4-RECV:<port>
UDP6-RECV:<port>
UDPLITE-CONNECT:<host>:<port>
UDPLITE4-CONNECT:<host>:<port>
UDPLITE6-CONNECT:<host>:<port>
UDPLITE-DATAGRAM:<address>:<port>
UDPLITE4-DATAGRAM:<address>:<port>
UDPLITE6-DATAGRAM:<address>:<port>
UDPLITE-LISTEN:<port>
UDPLITE4-LISTEN:<port>
UDPLITE6-LISTEN:<port>
UDPLITE-SENDTO:<host>:<port>
UDPLITE4-SENDTO:<host>:<port>
UDPLITE6-SENDTO:<host>:<port>
UDPLITE-RECVFROM:<port>
UDPLITE4-RECVFROM:<port>
UDPLITE6-RECVFROM:<port>
UDPLITE-RECV:<port>
UDPLITE4-RECV:<port>
UDPLITE6-RECV:<port>
UNIX-CONNECT:<filename>
UNIX-LISTEN:<filename>
UNIX-SENDTO:<filename>
/tmp/sock1
UNIX-RECVFROM:<filename>
UNIX-RECV:<filename>
UNIX-CLIENT:<filename>
VSOCK-CONNECT:<cid>:<port>
VSOCK-LISTEN:<port>
ABSTRACT-CONNECT:<string>
ABSTRACT-LISTEN:<string>
ABSTRACT-SENDTO:<string>
ABSTRACT-RECVFROM:<string>
ABSTRACT-RECV:<string>
ABSTRACT-CLIENT:<string>
Address options can be applied to address specifications to influence the process of opening the addresses and the properties of the resulting data channels.
For technical reasons not every option can be applied to every address type; e.g., applying a socket option to a regular file will fail. To catch most useless combinations as early as in the open phase, the concept of option groups was introduced. Each option belongs to one or more option groups. Options can be used only with address types that support at least one of their option groups (but see option -g).
Address options have data types that their values must conform to. Every address option consists of just a keyword or a keyword followed by "=value", where value must conform to the options type. Some address options manipulate parameters of system calls; e.g., option sync sets the O_SYNC flag with the open() call. Other options cause a system or library call; e.g., with option `ttl=value' the setsockopt(fd, SOL_IP, IP_TTL, value, sizeof(int)) call is applied. Other options set internal socat variables that are used during data transfer; e.g., `crnl' causes explicit character conversions. A few options have more complex implementations; e.g., su-d (substuser-delayed) inquires some user and group infos, stores them, and applies them later after a possible chroot() call.
O_SYNC
setsockopt(fd, SOL_IP, IP_TTL, value, sizeof(int))
chroot()
If multiple options are given to an address, their sequence in the address specification has (almost) no effect on the sequence of their execution/application. Instead, socat has built in an option phase model that tries to bring the options in a useful order. Some options exist in different forms (e.g., unlink, unlink-early, unlink-late) to control the time of their execution.
If the same option is specified more than once within one address specification, with equal or different values, the effect depends on the kind of option. Options resulting in function calls like setsockopt() cause multiple invocations. With options that set parameters for a required call like open() or set internal flags, the value of the last option occurrence is effective.
setsockopt()
The existence or semantics of many options are system dependent. Socat usually does NOT try to emulate missing libc or kernel features, it just provides an interface to the underlying system. So, if an operating system lacks a feature, the related option is simply not available on this platform.
The following paragraphs introduce just the more common address options. For a more comprehensive reference and to find information about canonical option names, alias names, option phases, and platforms see file xio.help.
FD option group
This option group contains options that are applied to a UN*X style file descriptor, no matter how it was generated. Because all current socat address types are file descriptor based, these options may be applied to any address. Note: Some of these options are also member of another option group, that provides another, non-fd based mechanism. For these options, it depends on the actual address type and its option groups which mechanism is used. The second, non-fd based mechanism is prioritized.
cloexec[=<bool>]
FD_CLOEXEC
fcntl()
exec()
setlk[=<bool>]
fcntl(fd, F_SETLK, ...)
setlkw[=<bool>]
fcntl(fd, F_SETLKW, ...)
setlk-rd[=<bool>]
setlkw-rd[=<bool>]
flock-ex[=<bool>]
flock(fd, LOCK_EX)
flock-ex-nb[=<bool>]
flock(fd, LOCK_EX|LOCK_NB)
flock-sh[=<bool>]
flock(fd, LOCK_SH)
flock-sh-nb[=<bool>]
flock(fd, LOCK_SH|LOCK_NB)
lock[=<bool>]
user=<user>
chown()
fchown()
user-late=<user>
group=<group>
group-late=<group>
mode=<mode>
chmod()
fchmod()
perm-late=<mode>
append[=<bool>]
fcntl(fd, F_SETFL, O_APPEND)
nonblock[=<bool>]
connect()
O_NONBLOCK
fcntl(fd, F_SETFL, O_NONBLOCK)
binary[=<bool>]
text[=<bool>]
noinherit[=<bool>]
cool-write[=<bool>]
end-close[=<bool>]
shutdown(2)
close(2)
shut-none[=<bool>]
shut-down[=<bool>]
shut-close[=<bool>]
shut-null[=<bool>]
null-eof[=<bool>]
ioctl-void=<request>
ioctl()
ioctl-int=<request>:<value>
ioctl-intp=<request>:<value>
ioctl-bin=<request>:<value>
ioctl-string=<request>:<value>
NAMED option group
These options work on file system entries. Please note that, with UNIX domain client addresses, this means the bind entry, not the target/peer entry. See also options user, group, and mode.
user-early=<user>
group-early=<group>
perm-early=<mode>
unlink-early[=<bool>]
unlink[=<bool>]
unlink-late[=<bool>]
unlink-close[=<bool>]
OPEN option group
The OPEN group options allow setting flags with the open() system call. E.g., option `creat' sets the O_CREAT flag. When the used address does not use open() (e.g.STDIO), the fcntl(..., F_SETFL, ...) call is used instead. See also options append and nonblock.
fcntl(..., F_SETFL, ...)
creat[=<bool>]
dsync[=<bool>]
write()
excl[=<bool>]
largefile[=<bool>]
noatime[=<bool>]
noctty[=<bool>]
nofollow[=<bool>]
nshare[=<bool>]
rshare[=<bool>]
rsync[=<bool>]
sync[=<bool>]
rdonly[=<bool>]
wronly[=<bool>]
trunc[=<bool>]
REG and BLK option group
These options are usually applied to a UN*X file descriptor, but their semantics make sense only on a file supporting random access.
seek=<offset>
lseek(fd, <offset>, SEEK_SET)
lseek64
seek-cur=<offset>
lseek(fd, <offset>, SEEK_CUR)
seek-end=<offset>
lseek(fd, <offset>, SEEK_END)
ftruncate=<offset>
ftruncate(fd, <offset>)
ftruncate64
secrm[=<bool>]
unrm[=<bool>]
compr[=<bool>]
fs-sync[=<bool>]
immutable[=<bool>]
fs-append[=<bool>]
nodump[=<bool>]
fs-noatime[=<bool>]
journal-data[=<bool>]
notail[=<bool>]
dirsync[=<bool>]
PIPE options
These options may be applied to pipes (fifos).
f-setpipe-sz=<int>
setpipe=<int>
General address options
These options may be applied to all address types. They change some process properties that are restored after opening the address.
chdir=<filename>
cd=<filename>
umask=<mode>
umask
PROCESS option group
Options of this group change the process properties instead of just affecting one data channel. For EXEC and SYSTEM addresses and for LISTEN and CONNECT type addresses with option fork, these options apply to the child processes instead of the main socat process.
chroot=<directory>
chroot-early=<directory>
setgid=<group>
setgid-early=<group>
setuid=<user>
setuid-early=<user>
su=<user>
su-d=<user>
substuser-delayed
setpgid=<pid_t>
setsid
netns=<net-namespace-name>
READLINE option group
These options apply to the readline address type.
history=<filename>
noprompt
noecho=<pattern>
prompt=<string>
APPLICATION option group
This group contains options that work at data level. Note that these options only apply to the "raw" data transferred by socat, but not to protocol data used by addresses like PROXY.
cr
crnl
ignoreeof
readbytes=<bytes>
lockfile=<filename>
waitlock=<filename>
escape=<int>
SOCKET option group
These options are intended for all kinds of sockets, e.g. IP or UNIX domain. Most are applied with a setsockopt() call.
bind=<sockname>
bind()
connect-timeout=<seconds>
so-bindtodevice=<interface>
broadcast
debug
dontroute
keepalive
linger=<seconds>
shutdown()
close()
oobinline
priority=<priority>
rcvbuf=<bytes>
socket()
rcvbuf-late=<bytes>
so-rcvtimeo=<time>, rcvtimeo=<time>
recv()
read()
so-sndtimeo=<time>, sndtimeo=<time>
send
rcvlowat=<bytes>
reuseaddr[=[0|1]]
setsockopt(...SO_REUSEADDR...)
reuseaddr=
sndbuf=<bytes>
sndbuf-late=<bytes>
sndlowat=<bytes>
pf=<string>
socktype=<type>
protocol
reuseport
SO_REUSEPORT
so-timestamp
setsockopt=<level>:<optname>:<optval>
level
optname
value
setsockopt-int=<level>:<optname>:<optval>
setsockopt
setsockopt-listen=<level>:<optname>:<optval>
setsockopt-string=<level>:<optname>:<optval>
UNIX option group
These options apply to UNIX domain based addresses.
bind-tempname[=/tmp/pre-XXXXXX], unix-bind-tempname[=/tmp/pre-XXXXXX]
SENDTO
CLIENT
X
/tmp/fileXXXXXX
unix-tightsocklen[=(0|1)]
struct sockaddr_un
IP4 and IP6 option groups
These options can be used with IPv4 and IPv6 based sockets.
tos=<tos>
ttl=<ttl>
ip-options=<data>
ip-options=x8307040a000001
mtudiscover=<0|1|2>
ip-pktinfo
ip-recverr
ip-recvopts
ip-recvtos
ip-recvttl
ip-recvdstaddr
ip-recvif
ip-add-membership=<multicast-address:interface-address>
ip-add-membership=<multicast-address:interface-name>
ip-add-membership=<multicast-address:interface-index>
ip-add-membership=<multicast-address:interface-address:interface-name>
ip-add-membership=<multicast-address:interface-address:interface-index>
struct mreqn
ip-add-source-membership=<multicast-address:interface-address:source-address>
ipv6-join-group=<multicast-address:interface-name>
ipv6-join-group=<multicast-address:interface-index>
ipv6-join-source-group=<multicast-address:interface-name:source-address>
ipv6-join-source-group=<multicast-address:interface-index:source-address>
ip-multicast-if=<hostname>
ip-multicast-loop[=<bool>]
ip-multicast-ttl=<byte>
ip-transparent
Resolver options
These options temporarily change the behaviour of hostname resolution. The options of form ai-* affect behaviour of the getaddrinfo() function that includes /etc/hosts and NIS based lookups.
ai-*
getaddrinfo()
/etc/hosts
The addresses of form res-* only affect DNS lookups, and only when the result is not cached in nscd . These options might not work on all operating systems or libc implementations.
res-*
nscd
ai-addrconfig[=0|1]
addrconfig[=0|1]
ai-passive[=0|1]
passive[=0|1]
ai-v4mapped[=0|1]
v4mapped[=0|1]
res-debug
res-aaonly
res-usevc
res-primary
res-igntc
res-recurse
res-defnames
res-stayopen
res-dnsrch
res-retrans=<int>
res-retry=<int>
res-nsaddr=<ipaddr>[:<port>]
_res:nsaddr_list[0]
IP6 option group
These options can only be used on IPv6 based sockets. See IP options for options that can be applied to both IPv4 and IPv6 sockets.
ipv6only[=<bool>]
ipv6-recvdstopts
ipv6-recvhoplimit
ipv6-recvhopopts
ipv6-recvpktinfo
ipv6-unicast-hops=link(TYPE_INT)(<int>)
ipv6-recvrthdr
ipv6-tclass
ipv6-recvtclass
TCP option group
These options may be applied to TCP sockets. They work by invoking setsockopt() with the appropriate parameters.
cork
defer-accept
keepcnt=<count>
keepidle=<seconds>
keepintvl=<seconds>
linger2=<seconds>
mss=<bytes>
mss-late=<bytes>
nodelay
rfc1323
stdurg
syncnt=<count>
md5sig
noopt
nopush
sack-disable
signature-enable
abort-threshold=<milliseconds>
conn-abort-threshold=<milliseconds>
keepinit
paws
sackena
tsoptena
UDP option group
This option may be applied to UDP datagram sockets.
udp-ignore-peerport>
UDPLITE option group
These options may be applied to UDPLITE addresses:
udplite-send-cscov
udplite-recv-cscov
SCTP option group
These options may be applied to SCTP stream sockets.
sctp-nodelay
sctp-maxseg=<bytes>
DCCP option group
These options may be applied to DCCP sockets.
dccp-set-ccid=<int>
ccid=<int>
UDP, TCP, SCTP, DCCP, and UDPLITE option group
Here we find options that are related to the network port mechanism and thus can be used with UDP, TCP, SCTP, DCCP, and UDP-Lite client and server addresses.
sourceport=<port>
lowport
SOCKS option group
When using SOCKS type addresses, some socks specific options can be set.
socksport=<tcp service>
socksuser=<user>
HTTP option group
Options that can be provided with HTTP type addresses. The only HTTP address currently implemented is proxy-connect.
http-version=<string>
proxyport=<TCP service>
ignorecr
proxy-authorization=<username>:<password>
proxy-authorization-file=<filename>
resolve
RANGE option group
These options check if a connecting client should be granted access. They can be applied to listening and receiving network sockets. tcp-wrappers options fall into this group.
range=<address-range>
tcpwrap[=<name>]
allow-table=<filename>
deny-table=<filename>
tcpwrap-etc=<directoryname>
LISTEN option group
Options specific to listening sockets.
backlog=<count>
listen()
accept-timeout=<seconds>
CHILD option group
Addresses of LISTEN and CONNECT type take the fork option to handle multiple connections via child processes.
fork
max-children=<count>
children-shutup[=1|2|..]
EXEC option group
Options for addresses that invoke a program.
path=<string>
login
argv[0]
FORK option group
EXEC or SYSTEM addresses invoke a program using a child process and transfer data between socat and the program. The interprocess communication mechanism can be influenced with the following options. Per default, a socketpair() is created and assigned to stdin and stdout of the child process, while stderr is inherited from the socat process, and the child process uses file descriptors 0 and 1 for communicating with the main socat process.
nofork
pipes
openpty
openpty()
ptmx
pty
ctty
stderr
dup()
fdin=<fdnum>
fdout=<fdnum>
sighup
sigint
sigquit
Options for address SHELL
shell=<filename>
/bin/dash
SHELL
TERMIOS option group
For addresses that work on a tty (e.g., stdio, file:/dev/tty, exec:...,pty), the terminal parameters defined in the UN*X termios mechanism are made available as address option parameters. Please note that changes of the parameters of your interactive terminal remain effective after socat's termination, so you might have to enter "reset" or "stty sane" in your shell afterwards. For EXEC and SYSTEM addresses with option PTY, these options apply to the pty by the child processes.
b0
b19200
socat -hh |grep ' b[1-9]'
echo[=<bool>]
icanon[=<bool>]
raw
rawer
cfmakeraw
cfmakeraw()
ignbrk[=<bool>]
brkint[=<bool>]
bs0
bs1
bsdly=<0|1>
clocal[=<bool>]
cr0 cr1 cr2 cr3
crdly=<0|1|2|3>
cread[=<bool>]
crtscts[=<bool>]
cs5 cs6 cs7 cs8
csize=<0|1|2|3>
cstopb[=<bool>]
dsusp=<byte>
echoctl[=<bool>]
echoe[=<bool>]
echok[=<bool>]
echoke[=<bool>]
echonl[=<bool>]
echoprt[=<bool>]
eof=<byte>
eol=<byte>
eol2=<byte>
erase=<byte>
discard=<byte>
ff0
ff1
ffdly[=<bool>]
flusho[=<bool>]
hupcl[=<bool>]
icrnl[=<bool>]
iexten[=<bool>]
igncr[=<bool>]
ignpar[=<bool>]
imaxbel[=<bool>]
inlcr[=<bool>]
inpck[=<bool>]
intr=<byte>
isig[=<bool>]
ispeed=<unsigned-int>
istrip[=<bool>]
iuclc[=<bool>]
ixany[=<bool>]
ixoff[=<bool>]
ixon[=<bool>]
kill=<byte>
lnext=<byte>
min=<byte>
nl0
nl1
nldly[=<bool>]
noflsh[=<bool>]
ocrnl[=<bool>]
ofdel[=<bool>]
ofill[=<bool>]
olcuc[=<bool>]
onlcr[=<bool>]
onlret[=<bool>]
onocr[=<bool>]
opost[=<bool>]
ospeed=<unsigned-int>
parenb[=<bool>]
parmrk[=<bool>]
parodd[=<bool>]
pendin[=<bool>]
quit=<byte>
reprint=<byte>
sane
start=<byte>
stop=<byte>
susp=<byte>
swtc=<byte>
tab0
tab1
tab2
tab3
tabdly=<unsigned-int>
time=<byte>
tostop[=<bool>]
vt0
vt1
vtdly[=<bool>]
werase=<byte>
xcase[=<bool>]
xtabs
i-pop-all
i-push=<string>
i-pop-all,i-push=ptem,i-push=ldterm,i-push=ttcompat
PTY option group
These options are intended for use with the pty address type.
link=<filename>
wait-slave
poll()
pty-interval=<seconds>
sitout-eio=<timeval>
OPENSSL option group
These options apply to the openssl and openssl-listen address types.
cipher=<cipherlist>
ciphers
method=<ssl-method>
--with-openssl-method
SSL2
SSL3
SSL23
TLS1
TLS1.1
TLS1.2
min-proto-version
TLS1.0
TLS1.3
openssl-max-proto-version
verify[=<bool>]
cert=<filename>
key=<filename>
dhparams=<filename>
cafile=<filename>
capath=<dirname>
egd=<filename>
openssl-maxfraglen=<int>, maxfraglen=<int>
openssl-maxsendfrag=<int>, maxsendfrag=<int>
pseudo
compress
commonname=<string>
no-sni[=<bool>]
snihost=<string>
fips
RETRY option group
Options that control retry of some system calls, especially connection attempts.
retry=<num>
interval=<timespec>
forever
INTERFACE option group
These options may be applied to addresses INTERFACE and TUN. These address types and options are currently only implemented on Linux operating system.
Note regarding VLANs: On incoming packets the Linux kernel strips off the VLAN tag before passing the data to the user space program on raw sockets. Special measures are required to get the VLAN information, see packet(7) PACKET_AUXDATA, and to optionally insert the tag into the packet again, use option retrieve-vlan when you need this.
retrieve-vlan
iff-up
iff-broadcast
iff-debug
iff-loopback
iff-pointopoint
iff-notrailers
iff-running
iff-noarp
iff-promisc
iff-allmulti
iff-master
iff-slave
iff-multicast
iff-portsel
iff-automedia
iff-dynamic
TUN option group
Options that control Linux TUN/TAP interface device addresses.
tun-device=<device-file>
tun-name=<if-name>
tun-type=[tun|tap]
iff-no-pi
POSIX-MQ option group
Options that may be applied to POSIX-MQ addresses.
posixmq-priority (mq-prio)
This section explains the different data types that address parameters and address options can take.
strtoul()
UCHAR_MAX
strtol()
strtoll()
strtoul
getservbyname()
transfers data between STDIO (-) and a TCP4 connection to port 80 of host www.domain.org. This example results in an interactive connection similar to telnet or netcat. The stdin terminal parameters are not changed, so you may close the relay with ^D or abort it with ^C.
this is similar to the previous example, but you can edit the current line in a bash like manner (READLINE) and use the history file .http_history; socat prints messages about progress (-d -d). The port is specified by service name (www), and correct network line termination characters (crnl) instead of NL are used.
installs a simple TCP port forwarder. With TCP4-LISTEN it listens on local port "www" until a connection comes in, accepts it, then connects to the remote host (TCP4) and starts data transfer. It will not accept a second connection.
TCP port forwarder, each side bound to another local IP address (bind). This example handles an almost arbitrary number of parallel or consecutive connections by fork'ing a new process after each accept() . It provides a little security by su'ing to user nobody after forking; it only permits connections from the private 10 network (range); due to reuseaddr, it allows immediate restart after master process's termination, even if some child sockets are not completely shut down. With -lmlocal2, socat logs to stderr until successfully reaching the accept loop. Further logging is directed to syslog with facility local2.
accept()
a simple server that accepts connections (TCP4-LISTEN) and fork's a new child process for each connection; every child acts as single relay. The client must match the rules for daemon process name "script" in /etc/hosts.allow and /etc/hosts.deny, otherwise it is refused access (see "man 5 hosts_access"). For EXEC'uting the program, the child process chroot's to /home/sandbox, su's to user sandbox, and then starts the program /home/sandbox/bin/myscript. Socat and myscript communicate via a pseudo tty (pty); myscript's stderr is redirected to stdout, so its error messages are transferred via socat to the connected client.
mail.sh is a shell script, distributed with socat, that implements a simple SMTP client. It is programmed to "speak" SMTP on its FDs 3 (in) and 4 (out). The fdin and fdout options tell socat to use these FDs for communication with the program. Because mail.sh inherits stdin and stdout while socat does not use them, the script can read a mail body from stdin. Socat makes alias1 your local source address (bind), cares for correct network line termination (crnl) and sends at most 512 data bytes per packet (mss).
opens an interactive connection via the serial line, e.g. for talking with a modem. rawer sets the console's and ttyS0's terminal parameters to practicable values, crnl converts to correct newline characters. escape allows terminating the socat process with character control-O. Consider using READLINE instead of the first address.
with UNIX-LISTEN, socat opens a listening UNIX domain socket /tmp/.X11-unix/X1. This path corresponds to local XWindow display :1 on your machine, so XWindow client connections to DISPLAY=:1 are accepted. Socat then speaks with the SOCKS4 server host.victim.org that might permit sourceport 20 based connections due to an FTP related weakness in its static IP filters. Socat pretends to be invoked by socksuser nobody, and requests to be connected to loopback port 6000 (only weak sockd configurations will allow this). So we get a connection to the victims XWindow server and, if it does not require MIT cookies or Kerberos authentication, we can start work. Please note that there can only be one connection at a time, because TCP can establish only one session with a given set of addresses and ports.
this is an example for unidirectional data transfer (-u). Socat transfers data from file /tmp/readdata (implicit address GOPEN), starting at its current end (seek-end=0 lets socat start reading at current end of file; use seek=0 or no seek option to first read the existing data) in a "tail -f" like mode (ignoreeof). The "file" might also be a listening UNIX domain socket (do not use a seek option then).
EXEC'utes an ssh session to server. Uses a pty for communication between socat and ssh, makes it ssh's controlling tty (ctty), and makes this pty the owner of a new process group (setsid), so ssh accepts the password from socat.
implements a simple network based message collector. For each client connecting to port 3334, a new child process is generated (option fork). All data sent by the clients are append'ed to the file /tmp/in.log. If the file does not exist, socat creat's it. Option reuseaddr allows immediate restart of the server process.
wraps a command line history (READLINE) around the EXEC'uted ftp client utility. This allows editing and reuse of FTP commands for relatively comfortable browsing through the ftp directory hierarchy. The password is echoed! pty is required to have ftp issue a prompt. Nevertheless, there may occur some confusion with the password and FTP prompts.
generates a pseudo terminal device (PTY) on the client that can be reached under the symbolic link $HOME/dev/vmodem0. An application that expects a serial line or modem can be configured to use $HOME/dev/vmodem0; its traffic will be directed to a modemserver via ssh where another socat instance links it to /dev/ttyS0.
creates a listener in the given network namespace that accepts TCP connections on port 8000 and forwards them to server2.
creates two virtual network interfaces, one in default namespace, the other one in namespace2, and forwards packets between them, acting as a virtual network connection.
starts a forwarder that accepts connections on port 2022, and directs them through the proxy daemon listening on port 3128 (proxyport) on host proxy.local, using the CONNECT method, where they are authenticated as "username" with "s3cr3t" (proxyauth). proxy.local should establish connections to host www.domain.org on port 22 then.
is an OpenSSL client that tries to establish a secure connection to an SSL server. Option cafile specifies a file that contains trust certificates: we trust the server only when it presents one of these certificates and proofs that it owns the related private key. Otherwise the connection is terminated. With cert a file containing the client certificate and the associated private key is specified. This is required in case the server wishes a client authentication; many Internet servers do not. The first address ('-') can be replaced by almost any other socat address.
is an OpenSSL server that accepts TCP connections, presents the certificate from the file server.pem and forces the client to present a certificate that is verified against cafile.crt. The second address ('PIPE') can be replaced by almost any other socat address. For instructions on generating and distributing OpenSSL keys and certificates see the additional socat docu socat-openssl.txt.
socat-openssl.txt
creates a 100GB+1B sparse file; this requires a file system type that supports this (ext2, ext3, ext4, reiserfs, xfs; not minix, vfat). The operation of writing 1 byte might take long (reiserfs: some minutes; ext2: "no" time), and the resulting file can consume some disk space with just its inodes (reiserfs: 2MB; ext2: 16KB).
listens for incoming TCP connections on port 7777. For each accepted connection, invokes a shell. This shell has its stdin and stdout directly connected to the TCP socket (nofork). The shell starts filan and lets it print the socket addresses to stderr (your terminal window).
functions as primitive binary editor: it writes the 4 bytes 000 014 000 000 to the executable /usr/bin/squid.exe at offset 0x00074420 (this was a real world patch to make the squid executable from Cygwin run under Windows, in 2004).
connects to an unknown service and prevents being flooded.
merges data arriving from different TCP streams on port 8888 to just one stream to target:9999. The end-close option prevents the child processes forked off by the second address from terminating the shared connection to 9999 (close(2) just unlinks the inode which stays active as long as the parent process lives; shutdown(2) would actively terminate the connection).
is a simple DCCP echo server. DCCP is now directly provisioned in socat, however this example shows how use socats TCP procedures and change the socket type to SOCK_DCCP=6 (on Linux) and the IP protocol to IPPROTO_DCCP=33.
is a simple DCCP client. DCCP is now directly provisioned in socat, however this example shows how use socats TCP procedures, but changes the socket type to SOCK_DCCP=6 (on Linux) and the IP protocol to IPPROTO_DCCP=33.
sends a broadcast to the network 192.168.1.0/24 and receives the replies of the timeservers there. Ignores NTP packets from hosts outside this network.
is semantically equivalent to the previous example, but all parameters are specified in generic form. the value 6 of setsockopt-int is the Linux value for SO_BROADCAST.
SO_BROADCAST
sends a broadcast to the local network(s) using protocol 44. Accepts replies from the private address range only.
transfers data from stdin to the specified multicast address using UDP. Both local and remote ports are 6666. Tells the interface eth0 to also accept multicast packets of the given group. Multiple hosts on the local network can run this command, so all data sent by any of the hosts will be received by all the other ones. Note that there are many possible reasons for failure, including IP-filters, routing issues, wrong interface selection by the operating system, bridges, or a badly configured switch.
establishes one side of a virtual (but not private!) network with host2 where a similar process might run, with UDP-L and tun address 192.168.255.2. They can reach each other using the addresses 192.168.255.1 and 192.168.255.2. Note that streaming eg.via TCP or SSL does not guarantee to retain packet boundaries and might thus cause packet loss.
establishes a VSOCK connection with the host (host is always reachable with the well-know CID=2) on 1234 port.
listens for a VSOCK connection on 1234 port.
establishes a VSOCK connection with the guest that have CID=31 on 1234 port, binding the local socket to the 5555 port.
starts a forwarder that accepts VSOCK connections on port 3333, and directs them to the guest with CID=42 on the same port.
forwards VSOCK connections from 22 port to the local SSH server. Running this in a VM allows you to connect via SSH from the host using VSOCK, as in the example below.
forwards TCP connections from 22222 port to the guest with CID=33 listening on VSOCK port 22. Running this in the host, allows you to connect via SSH running "ssh -p 22222 user@localhost", if the guest runs the example above.
circumvents the problem that pppd requires a serial device and thus might not be able to work on a synchronous line that is represented by a network device. socat creates a PTY to make pppd happy, binds to the network interface hdlc0, and can transfer data between both devices. Use pppd on device /var/run/ppp then.
hdlc0
/var/run/ppp
Writes packets read from stdio (i.e., lines of input when run interactively) into POSIX message queue, with priority 10.
Receives messages (packets) from POSIX message queue and, for each messages, forks a sub process that reads and processes the message. At most 3 sub processes are allowed at the same time.
creates a very primitive HTTP echo server: each HTTP client that connects gets a valid HTTP reply that contains information about the client address and port as it is seen by the server host, the host address (which might vary on multihomed servers), and the original client request.
waits for an incoming UDP packet on port 9999 and prints the environment variables provided by socat. On BSD based systems you have to replace ip-pktinfo with ip-recvdstaddr,ip-recvif. Especially of interest is SOCAT_IP_DSTADDR: it contains the target address of the packet which may be a unicast, multicast, or broadcast address.
sends an SSDP (Simple Service Discovery Protocol) query to the local network and collects and outputs the answers received.
systemd-socket-activate is a program for testing systemd socket activation of daemons. With --inetd it waits for a connection on the specified port. It does not accept the connection but passes the listening file descriptor as FDs 0 and 1. Socat accepts the waiting connection and starts data transfer.
systemd-socket-activate
systemd
--inetd
Socat uses a logging mechanism that allows filtering messages by severity. The severities provided are more or less compatible to the appropriate syslog priority. With one or up to four occurrences of the -d command line option, the lowest priority of messages that are issued can be selected. Each message contains a single uppercase character specifying the messages severity (one of F, E, W, N, I, or D)
Log messages can be written to stderr, to a file, or to syslog.
On exit, socat gives status 0 if it terminated due to EOF or inactivity timeout, with a positive value on error, and with a negative value on fatal error.
/usr/bin/socat /usr/bin/filan /usr/bin/procan
Input variables carry information from the environment to socat, output variables are set by socat for use in executed scripts and programs.
In the output variables beginning with "SOCAT" this prefix is actually replaced by the upper case name of the executable or the value of option -lp.
"1.7.0.0"
"1.6.0.1+envvar"
The work of the following groups and organizations was invaluable for this project:
The FSF (GNU, http://www.fsf.org/) project with their free and portable development software and lots of other useful tools and libraries.
The Linux developers community (http://www.linux.org/) for providing a free, open source operating system.
The Open Group (http://www.unix-systems.org/) for making their standard specifications available on the Internet for free.
This man page describes version 1.8.0 of socat.
Addresses cannot be nested, so a single socat process cannot, e.g., drive ssl over socks.
Address option ftruncate without value uses default 1 instead of 0.
Verbose modes (-x and/or -v) display line termination characters inconsistently when address options cr or crnl are used: They show the data after conversion in either direction.
The data transfer blocksize setting (-b) is ignored with address readline.
Send bug reports to <socat@dest-unreach.org>
nc(1), rinetd(8), openssl(1), stunnel(8), rlwrap(1), setsid(1)
Socat home page http://www.dest-unreach.org/socat/
Gerhard Rieger <rieger@dest-unreach.org> and contributors