xref: /netbsd-src/share/man/man4/tcp.4 (revision d20841bb642898112fe68f0ad3f7b26dddf56f07)
1.\"	$NetBSD: tcp.4,v 1.14 2003/11/23 07:25:11 jhawk Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)tcp.4	8.1 (Berkeley) 6/5/93
31.\"
32.Dd November 23, 2003
33.Dt TCP 4
34.Os
35.Sh NAME
36.Nm tcp
37.Nd Internet Transmission Control Protocol
38.Sh SYNOPSIS
39.In sys/socket.h
40.In netinet/in.h
41.Ft int
42.Fn socket AF_INET SOCK_STREAM 0
43.Ft int
44.Fn socket AF_INET6 SOCK_STREAM 0
45.Sh DESCRIPTION
46The
47.Tn TCP
48provides reliable, flow-controlled, two-way transmission of data.
49It is a byte-stream protocol used to support the
50.Dv SOCK_STREAM
51abstraction.
52.Tn TCP
53uses the standard Internet address format and, in addition, provides
54a per-host collection of
55.Dq port addresses .
56Thus, each address is composed of an Internet address specifying
57the host and network, with a specific
58.Tn TCP
59port on the host identifying the peer entity.
60.Pp
61Sockets using
62.Tn TCP
63are either
64.Dq active
65or
66.Dq passive .
67Active sockets initiate connections to passive
68sockets.
69By default
70.Tn TCP
71sockets are created active; to create a passive socket the
72.Xr listen 2
73system call must be used
74after binding the socket with the
75.Xr bind 2
76system call.
77Only passive sockets may use the
78.Xr accept 2
79call to accept incoming connections.
80Only active sockets may use the
81.Xr connect 2
82call to initiate connections.
83.Pp
84Passive sockets may
85.Dq underspecify
86their location to match incoming connection requests from multiple networks.
87This technique, termed
88.Dq wildcard addressing ,
89allows a single
90server to provide service to clients on multiple networks.
91To create a socket which listens on all networks, the Internet
92address
93.Dv INADDR_ANY
94must be bound.
95The
96.Tn TCP
97port may still be specified at this time; if the port is not
98specified the system will assign one.
99Once a connection has been established the socket's address is
100fixed by the peer entity's location.
101The address assigned the socket is the address associated with the
102network interface through which packets are being transmitted and received.
103Normally this address corresponds to the peer entity's network.
104.Pp
105.Tn TCP
106supports one socket option which is set with
107.Xr setsockopt 2
108and tested with
109.Xr getsockopt 2 .
110Under most circumstances,
111.Tn TCP
112sends data when it is presented;
113when outstanding data has not yet been acknowledged, it gathers
114small amounts of output to be sent in a single packet once
115an acknowledgement is received.
116For a small number of clients, such as window systems
117that send a stream of mouse events which receive no replies,
118this packetization may cause significant delays.
119Therefore,
120.Tn TCP
121provides a boolean option,
122.Dv TCP_NODELAY
123(from
124.Aq Pa netinet/tcp.h ,
125to defeat this algorithm.
126The option level for the
127.Xr setsockopt 2
128call is the protocol number for
129.Tn TCP ,
130available from
131.Xr getprotobyname 3 .
132In the historical
133.Bx
134.Tn TCP
135implementation, if the
136.Dv TCP_NODELAY
137option was set on a passive socket, the sockets returned by
138.Xr accept 2
139erroneously did not have the
140.Dv TCP_NODELAY
141option set; the behavior was corrected to inherit
142.Dv TCP_NODELAY
143in
144.Nx 1.6 .
145.Pp
146Options at the
147.Tn IP
148network level may be used with
149.Tn TCP ;
150see
151.Xr ip 4
152or
153.Xr ip6 4 .
154Incoming connection requests that are source-routed are noted,
155and the reverse source route is used in responding.
156.Pp
157There are many adjustable parameters that control various aspects
158of the
159.Nx
160TCP behavior; these parameters are documented in
161.Xr sysctl 3 ,
162and they include:
163.Bl -bullet -compact
164.It
165RFC 1323 extensions for high performance
166.It
167Send/receive buffer sizes
168.It
169Default maximum segment size (MSS)
170.It
171SYN cache parameters
172.It
173Initial window size
174.It
175Hughes/Touch/Heidemann Congestion Window Monitoring algorithm
176.It
177Keepalive parameters
178.It
179newReno algorithm for congestion control
180.It
181Logging of connection refusals
182.It
183RST packet rate limits
184.El
185.Sh DIAGNOSTICS
186A socket operation may fail with one of the following errors returned:
187.Bl -tag -width [EADDRNOTAVAIL]
188.It Bq Er EISCONN
189when trying to establish a connection on a socket which
190already has one;
191.It Bq Er ENOBUFS
192when the system runs out of memory for
193an internal data structure;
194.It Bq Er ETIMEDOUT
195when a connection was dropped
196due to excessive retransmissions;
197.It Bq Er ECONNRESET
198when the remote peer
199forces the connection to be closed;
200.It Bq Er ECONNREFUSED
201when the remote
202peer actively refuses connection establishment (usually because
203no process is listening to the port);
204.It Bq Er EADDRINUSE
205when an attempt
206is made to create a socket with a port which has already been
207allocated;
208.It Bq Er EADDRNOTAVAIL
209when an attempt is made to create a
210socket with a network address for which no network interface
211exists.
212.El
213.Sh SEE ALSO
214.Xr getsockopt 2 ,
215.Xr socket 2 ,
216.Xr sysctl 3 ,
217.Xr inet 4 ,
218.Xr inet6 4 ,
219.Xr intro 4 ,
220.Xr ip 4 ,
221.Xr ip6 4
222.Rs
223.%R RFC
224.%N 793
225.%D September 1981
226.%T "Transmission Control Protocol"
227.Re
228.Rs
229.%R RFC
230.%N 1122
231.%D October 1989
232.%T "Requirements for Internet Hosts -- Communication Layers"
233.Re
234.Sh HISTORY
235The
236.Nm
237protocol stack appeared in
238.Bx 4.2 .
239