tcp-socket-connect 1 user commands nosh
tcp-socket-connect connect a socket to a TCP server and chain
`tcp-socket-connect` --verbose --local-name name --local-address address --local-port port --numeric-host --numeric-service --check-interfaces --no-keepalives --no-kill-IP-options --no-delay host service next-prog

## Description

`tcp-socket-connect` is a chain-loading utility that opens a TCP socket, connects it to host and service with connect 3, and then chain loads to next-prog with the execvp 3 function, having set up I/O and environment variables per the UCSPI conventions.

next-prog may contain its own command line options, which `tcp-socket-connect` will ignore.

If the --numeric-host command line option is used, then no name lookup is done on host and it must be (a human readable form of) an IP address. If the --numeric-service command line option is used, then no name lookup is done on service and it must be a port number. Otherwise, host is looked up using the system name resolution facility and port can be an alphanumeric service name.

The --check-interfaces option prevents the use of any IPv4 addresses if there are no IPv4 addresses on any network interface, and the use of any IPv6 addresses if there are no IPv6 addresses.

If the --verbose option is used, `tcp-socket-connect` logs information about connections made.

The --no-keepalives, --no-kill-IP-options, and --no-delay command line options set options on the connected socket. The first disables the use of TCP keepalive probes (which are used by default to ensure that dead connections are noticed and eliminated); the second permits IP options (which are removed by default) so that clients can set source routes; and the third disables the "Nagle" delay algorithm used for slow clients.

### UCSPI (specifically UCSPI-TCP) conventions

next-prog is expected to follow the UCSPI conventions: standard input, output, and error are the same as whatever `tcp-socket-connect` inherited; file descriptors 6 and 7 are (respectively) reading from and writing to the connected socket, which it should treat as generic I/O streams and not expect to be a socket; and information about the local and remote ends of the connected socket is in environment variables. Whatever `tcp-socket-connect` itself inherited as file descriptors 6 and 7 is closed.

`tcp-socket-connect` obtains information about the local socket connection using the `getpeername` 2 and `getsockname` 2 library functions, and sets up the UCSPI-TCP conventional environment variables as follows:

`PROTO`

  This always has the value `TCP`, indicating the prefix to the names of the remaining environment variables.

`TCPLOCALIP`

  The local (client) IP address of the connecting socket, in human-readable form. Normally, the operating system assigns this; but an explicit assignment can be requested with the --local-address command-line option, where address is a numeric IP address that is available and matches the protocol of the remote end.

`TCPLOCALPORT`

  The local (client) port number of the connecting socket. Normally, the operating system assigns this; but an explicit assignment can be requested with the --local-port command-line option, where port is a numeric port number.

`TCPLOCALHOST`

  The value of name set by the --local-name option; guaranteed unset if that option is not used.

`TCPREMOTEIP`

  The remote (server) IP address of the connected socket, in human-readable form.

`TCPREMOTEPORT`

  The remote (server) port number of the connected socket.

`TCPREMOTEINFO`

  Guaranteed unset.

`TCPREMOTEHOST`

  Guaranteed unset.

In the 21st century Internet, remote user account information and even host name information are attacker-supplied data and must not be expected by a UCSPI-TCP client, let alone relied upon. Even attempting to find out such information can involve contacting potentially malicious servers. `tcp-socket-connect` performs no lookups for such information.

## Author

Jonathan de Boyne Pollard