s6-networking: the s6-tcpserver-socketbinder program
Keywords: s6-networking s6-tcpserver-socketbinder tcpserver ucspi inet ipv4 ipv6 socket bind listen TCP/IP

s6-networking
Software
skarnet.org

# The `s6-tcpserver-socketbinder` program

`s6-tcpserver-socketbinder` binds an INET domain socket to an IPv4 or IPv6 address and port, then executes a program.

## Interface

         s6-tcpserver-socketbinder [ -d | -D ] [ -b backlog ] [ -M | -m ] [ -B ] ip port prog...

- s6-tcpserver-socketbinder creates a TCP socket and binds it to IP address ip, port port. It prepares the socket to accept connections by calling listen().
- It then execs into prog... with the open socket as its standard input.

## Options

- `-d` : allow instant rebinding to the same IP and port even if it has been used not long ago - this is the SO_REUSEADDR flag to setsockopt() and is generally used with server programs. This is the default.
- `-D` : disallow instant rebinding to the same path.
- `-b backlog` : set a maximum of backlog backlog connections on the socket - extra connection attempts will rejected by the kernel. The default is the maximum number allowed by the system. If backlog is 0, then the socket will be created, but it will not be listening.
- `-M` : create a TCP socket. This is the default.
- `-m` : create a UDP socket. Note that by default UDP sockets are not connection-mode, and `listen()` will fail - so you should always give the `-b0` option to s6-tcpserver-socketbinder along with `-m`.
- `-B` : create a blocking socket. Default is non-blocking.

## Notes

- The socket is provided non-blocking by default.
- s6-tcpserver-socketbinder is part of a set of basic blocks used to build a flexible TCP/IP super-server. It normally should be given a command line crafted to make it execute into s6-tcpserverd to accept connections from clients, or into a program such as s6-applyuidgid to drop privileges before doing so.
- The s6-tcpserver program does exactly this. It implements a full TCP/IP super-server by building a command line starting with s6-tcpserver-socketbinder and ending with s6-tcpserverd followed by the application program, and executing into it.
- For s6-tcpserver-socketbinder, `::` means "all IPv6 addresses", and `0.0.0.0` means "all IPv4 addresses". It does not provide a way to bind a socket to all addresses regardless of protocol; instead, you should use two sockets, one for IPv4 and one for IPv6.