bash の /dev/tcp/host/port

これが気になっちゃったので。

linux.die.net

    /dev/tcp/host/port 

If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open a TCP connection to the corresponding socket.

    /dev/udp/host/port 

If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open a UDP connection to the corresponding socket. 

GitHub に bash のミラーリポジトリがあったので参考にした。

実際に仕事してるところ

getaddrinfoIPv6 に対応してるかどうかで呼び分けている。

socket で作成したソケットを connect して得られた file descriptor を返すようになっている。

誰が close するんだろう。

netopen の呼び出し元

redir_openfile descriptor の後始末をしてるようだ。