\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#162: IPv6 Sockets for Tcl}
\date{October 23, 2003}
\author{Rafael Martínez Torres, Donal K. Fellows, Reinhard Max}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#162}&\textbf{IPv6 Sockets for Tcl}\\\hline
Author&

Rafael Martínez Torres \tipmail{rafael.martinez}{novagnet.com}
\par
Donal K. Fellows \tipmail{donal.k.fellows}{manchester.ac.uk}
\par
Reinhard Max \tipmail{max}{tclers.tk}
\\
Created&Thursday, \(\text{23}^{\text{rd}}\) October 2003\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.16 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP is about allowing Tcl to use IPv6 sockets in virtually the same way that you would use the current (IPv4) sockets.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

IPv6 is the next generation of the IP protocol that underlies Internet sockets. IPv6 advantages include a wider address space (128 bits instead current 32 bits), improved mobility, mandatory security at IP layer (IPsec...), etc. Tcl should allow the programmers try both protocols at their networking programs without too much effort (dependant on underlying operating system support, of course), just accepting the literal address (192.0.2.42, 2001:DB8::baad:f00d) or the DNS names (www.example.com).

\section{Proposed Change}

The interpreter should understand:
\begingroup\small\begin{verbatim}
socket 192.0.2.42 http
socket 2001:DB8::baad:f00d echo
socket -server accept 9999
socket ipv6.example.com 8080
\end{verbatim}
\endgroup

Where a hostname resolves to multiple addresses in multiple families, the addresses are tried one by one as returned by the the resolver library until a connection can be established. The order depends on the resolver library and its configuration; it is deliberately not touched by Tcl, so that local preferences are automatically respected by Tcl programs.

For sockets that actually use IPv6 the output of \textbf{fconfigure} needs to be changed to reflect the fact:

Client sockets:
\begingroup\small\begin{verbatim}
% fconfigure sock5 -peername
2001:DB8::baad:f00d ipv6.example.com 7
% fconfigure sock5 -sockname
2001:DB8::dead:beef 2001:DB8::dead:beef 49198
\end{verbatim}
\endgroup

Server sockets:
\begingroup\small\begin{verbatim}
% socket -server accept 0
sock3
% fconfigure sock3 -sockname
0.0.0.0 0.0.0.0 49198 :: :: 49198
\end{verbatim}
\endgroup

The \textbf{-sockname} and \textbf{-peername} options are the affected ones; for client sockets they can indicate addresses in the IPv6 or IPv4 namespaces, and for server sockets the \textbf{-sockname} option will list all the addresses bound (2 in the above example), three elements each. To maximize backward compatibility, the IPv4 address (if bound) will always be listed first. (Client sockets will always only list a single address as they will always be connected by a definite protocol.)

\section{Reference Implementation}

A development branch has been opened up; see [\url{http://wiki.tcl.tk/25947}] for details.

An older patch is available for UNIX platforms [\url{http://www.ngn.euro6ix.org/IPv6/tcl}].

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
