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