<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="udp-socket-connect">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>udp-socket-connect</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>udp-socket-connect</refname>
<refpurpose>connect a socket to a UDP server and chain</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>udp-socket-connect</command>
<arg choice='opt'>--verbose</arg>
<arg choice='opt'>--local-name <replaceable>name</replaceable></arg>
<arg choice='opt'>--local-address <replaceable>address</replaceable></arg>
<arg choice='opt'>--local-port <replaceable>port</replaceable></arg>
<arg choice='opt'>--numeric-host</arg>
<arg choice='opt'>--numeric-service</arg>
<arg choice='opt'>--check-interfaces</arg>
<arg choice='opt'>--no-kill-IP-options</arg>
<arg choice='req'><replaceable>host</replaceable></arg>
<arg choice='req'><replaceable>service</replaceable></arg>
<arg choice='req'><replaceable>next-prog</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>udp-socket-connect</command> is a chain-loading utility that opens a UDP socket, connects it to <replaceable>host</replaceable> and <replaceable>service</replaceable> with <citerefentry><refentrytitle>connect</refentrytitle><manvolnum>3</manvolnum></citerefentry>, and then chain loads to <replaceable>next-prog</replaceable> with the <citerefentry><refentrytitle>execvp</refentrytitle><manvolnum>3</manvolnum></citerefentry> function, having set up I/O and environment variables per the UCSPI conventions.
</para>

<para>
<replaceable>next-prog</replaceable> may contain its own command line options, which <command>udp-socket-connect</command> will ignore.
</para>

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

<para>
The <arg choice='plain'>--check-interfaces</arg> 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.
This isn't particularly useful on a dynamically configured system where network interface IP addresses can come and go.
</para>

<para>
If the <arg choice='plain'>--verbose</arg> option is used, <command>udp-socket-connect</command> logs information about connections made.
</para>

<para>
The <arg choice='plain'>--no-kill-IP-options</arg> command line option sets options on the connected socket.
It permits IP options (which are removed by default) so that clients can set source routes.
</para>

<refsection><title>UCSPI (specifically UCSPI-UDP) conventions</title>

<para>
<replaceable>next-prog</replaceable> is expected to follow the UCSPI conventions: standard input, output, and error are the same as whatever <command>udp-socket-connect</command> 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 <command>tcp-socket-connect</command> itself inherited as file descriptors 6 and 7 is closed.
</para>

<para>
<command>udp-socket-connect</command> obtains information about the local socket connection using the <citerefentry><refentrytitle><code>getpeername</code></refentrytitle><manvolnum>2</manvolnum></citerefentry> and <citerefentry><refentrytitle><code>getsockname</code></refentrytitle><manvolnum>2</manvolnum></citerefentry> library functions, and sets up the UCSPI-UDP conventional environment variables as follows:
</para>

<variablelist>

<varlistentry><term>
<envar>PROTO</envar>
</term><listitem>
<para>
This always has the value <code>UDP</code>, indicating the prefix to the names of the remaining environment variables.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPLOCALIP</envar>
</term><listitem>
<para>
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 <arg choice='plain'>--local-address</arg> command-line option, where <replaceable>address</replaceable> is a numeric IP address that is available and matches the protocol of the remote end.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPLOCALPORT</envar>
</term><listitem>
<para>
The local (client) port number of the connecting socket.
Normally, the operating system assigns this; but an explicit assignment can be requested with the <arg choice='plain'>--local-port</arg> command-line option, where <replaceable>port</replaceable> is a numeric port number.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPLOCALHOST</envar>
</term><listitem>
<para>
The value of <replaceable>name</replaceable> set by the <arg choice='plain'>--local-name</arg> option; guaranteed unset if that option is not used.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPREMOTEIP</envar>
</term><listitem>
<para>
The remote (server) IP address of the connected socket, in human-readable form.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPREMOTEPORT</envar>
</term><listitem>
<para>
The remote (server) port number of the connected socket.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPREMOTEINFO</envar>
</term><listitem>
<para>
Guaranteed unset.
</para>
</listitem>
</varlistentry>

<varlistentry><term>
<envar>UDPREMOTEHOST</envar>
</term><listitem>
<para>
Guaranteed unset.
</para>
</listitem>
</varlistentry>

</variablelist>

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

</refsection>

</refsection><refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
