socat使用指南:2:工作原理與選項說明

這篇文章繼續介紹一下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:支持程序的執行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章