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