这篇文章继续介绍一下socat的工作原理和选项说明。
工作原理
socat主要的工作原理如下所示:
工作原理说明:在初始化阶段解析命令行和初始化操作,然后顺次打开需要进行数据转发的两个连接,连接打开之后按照需要进行数据的转发,转发完毕关闭连接。
命令介绍
socat命令执行非常简单,格式如下所示:
命令格式:socat [options]
<address> <address>
options选项
选项 | 详细说明 |
---|---|
-V | print version and feature information to stdout, and exit |
-h | -? |
-hh | like -h, plus a list of all common address option names |
-hhh | like -hh, plus a list of all available address option names |
-d[ddd] | increase verbosity (use up to 4 times; 2 are recommended) |
-D | analyze file descriptors before loop |
-ly[facility] | log to syslog, using facility (default is daemon) |
-lf<logfile> |
log to file |
-ls | log to stderr (default if no other log) |
-lm[facility] | mixed log mode (stderr during initialization, then syslog) |
-lp<progname> |
set the program name used for logging |
-lu | use microseconds for logging timestamps |
-lh | add hostname to log messages |
-v | verbose data traffic, text |
-x | verbose data traffic, hexadecimal |
-b<size_t> |
set data buffer size (8192) |
-s | sloppy (continue on error) |
-t<timeout> |
wait seconds before closing second channel |
-T<timeout> |
total inactivity timeout in seconds |
-u | unidirectional mode (left to right) |
-U | unidirectional mode (right to left) |
-g | do not check option groups |
-L<lockfile> |
try to obtain lock, or fail |
-W <lockfile> |
try to obtain lock, or wait |
-4 | prefer IPv4 if version is not explicitly specified |
-6 | prefer IPv6 if version is not explicitly specified |
address说明
socat核心功能用于实现socket的转换,在命令行格式中的address所支持的主要类型包括:
- STDIN STDOUT :标准输入输出
- 文件类型:可以指定文件作为数据流参数
- TCP类型:支持TCP类型
- UDP类型:支持UDP类型
- TCP-LISTEN:支持建立TCP监听端口
- UDP-LISTEN:支持建立UDP监听端口
- EXEC:支持程序的执行