A utility similar to the venerable Netcat that works over a number of protocols and through a files, pipes, devices (terminal or modem, etc.), sockets (Unix, IP4, IP6 – raw, UDP, TCP), a client for SOCKS4, proxy CONNECT, or SSL, etc.
It provides forking, logging, and dumping, different modes for interprocess communication, and many more options. It can be used, for example, as a TCP relay (one-shot or daemon), as a daemon-based socksifier, as a shell interface to Unix sockets, as an IP6 relay, for redirecting TCP-oriented programs to a serial line, or to establish a relatively secure environment (su and chroot) for running client or server shell scripts with network connections.
Socat provides some command line options that modify the behaviour of the program.
- Print version and available feature information to stdout, and exit.
-h | -?
- Print a help text to stdout describing command line options and available address types, and exit.
-hh | -??
- Like -h, plus a list of the short names of all available address options. Some options are platform dependend, so this output is helpful for checking the particular implementation.
-hhh | -???
- Like -hh, plus a list of all available address option names.
- Without this option, only fatal and error messages are generated; applying this option also prints warning messages. See DIAGNOSTICS for more information.
- Prints fatal, error, warning, and notice messages.
-d -d -d
- Prints fatal, error, warning, notice, and info messages.
-d -d -d -d
- Prints fatal, error, warning, notice, info, and debug messages.
- Logs information about file descriptors before starting the transfer phase.
- Writes messages to syslog instead of stderr; severity as defined with -d option. With optional <facility>, the syslog type can be selected, default is “daemon”. Third party libraries might not obey this option.
- Writes messages to <logfile> [filename] instead of stderr. Some third party libraries, in particular libwrap, might not obey this option.
- Writes messages to stderr (this is the default). Some third party libraries might not obey this option, in particular libwrap appears to only log to syslog.
- Overrides the program name printed in error messages and used for constructing environment variable names.
- Extends the timestamp of error messages to microsecond resolution. Does not work when logging to syslog.
- Mixed log mode. During startup messages are printed to stderr; when socat starts the transfer phase loop or daemon mode (i.e. after opening all streams and before starting data transfer, or, with listening sockets with fork option, before the first accept call), it switches logging to syslog. With optional <facility>, the syslog type can be selected, default is “daemon”.
- Adds hostname to log messages. Uses the value from environment variable HOSTNAME or the value retrieved with
uname()if HOSTNAME is not set.
- Writes the transferred data not only to their target streams, but also to stderr. The output format is text with some conversions for readability, and prefixed with “> ” or “< ” indicating flow directions.
- Writes the transferred data not only to their target streams, but also to stderr. The output format is hexadecimal, prefixed with “> ” or “< ” indicating flow directions. Can be combined with
- Sets the data transfer block <size> [size_t]. At most <size> bytes are transferred per step. Default is 8192 bytes.
- By default, socat terminates when an error occurred to prevent the process from running when some option could not be applied. With this option, socat is sloppy with errors and tries to continue. Even with this option, socat will exit on fatals, and will abort connection attempts when security checks failed.
- When one channel has reached EOF, the write part of the other channel is shut down. Then, socat waits <timeout> [timeval] seconds before terminating. Default is 0.5 seconds. This timeout only applies to addresses where write and read part can be closed independently. When during the timeout interval the read part gives EOF, socat terminates without awaiting the timeout.
- Total inactivity timeout: when socat is already in the transfer loop and nothing has happened for <timeout> [timeval] seconds (no data arrived, no interrupt occurred…) then it terminates. Useful with protocols like UDP that cannot transfer EOF.
- Uses unidirectional mode. The first address is only used for reading, and the second address is only used for writing (example).
- Uses unidirectional mode in reverse direction. The first address is only used for writing, and the second address is only used for reading.
- During address option parsing, don’t check if the option is considered useful in the given address environment. Use it if you want to force, e.g., appliance of a socket option to a serial device.
- If lockfile exists, exits with error. If lockfile does not exist, creates it and continues, unlinks lockfile on exit.
- If lockfile exists, waits until it disappears. When lockfile does not exist, creates it and continues, unlinks lockfile on exit.
- Use IP version 4 in case that the addresses do not implicitly or explicitly specify a version; this is the default.
- Use IP version 6 in case that the addresses do not implicitly or explicitly specify a version.