xref: /freebsd/share/man/man4/tcp.4 (revision e627b39baccd1ec9129690167cf5e6d860509655)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     From: @(#)tcp.4	8.1 (Berkeley) 6/5/93
33.\"	$Id: tcp.4,v 1.4 1995/02/15 22:07:27 wollman Exp $
34.\"
35.Dd February 14, 1995
36.Dt TCP 4
37.Os BSD 4.2
38.Sh NAME
39.Nm tcp
40.Nd Internet Transmission Control Protocol
41.Sh SYNOPSIS
42.Fd #include <sys/socket.h>
43.Fd #include <netinet/in.h>
44.Ft int
45.Fn socket AF_INET SOCK_STREAM 0
46.Sh DESCRIPTION
47The
48.Tn TCP
49protocol provides reliable, flow-controlled, two-way
50transmission of data.  It is a byte-stream protocol used to
51support the
52.Dv SOCK_STREAM
53abstraction.  TCP uses the standard
54Internet address format and, in addition, provides a per-host
55collection of
56.Dq port addresses .
57Thus, each address is composed
58of an Internet address specifying the host and network, with
59a specific
60.Tn TCP
61port on the host identifying the peer entity.
62.Pp
63Sockets utilizing the tcp protocol are either
64.Dq active
65or
66.Dq passive .
67Active sockets initiate connections to passive
68sockets.  By default
69.Tn TCP
70sockets are created active; to create a
71passive socket the
72.Xr listen 2
73system call must be used
74after binding the socket with the
75.Xr bind 2
76system call.  Only
77passive sockets may use the
78.Xr accept 2
79call to accept incoming connections.  Only active sockets may
80use the
81.Xr connect 2
82call to initiate connections.
83.Tn TCP
84also supports a more datagram-like mode, called Transaction
85.Tn TCP ,
86which is described in
87.Xr ttcp 4 .
88.Pp
89Passive sockets may
90.Dq underspecify
91their location to match
92incoming connection requests from multiple networks.  This
93technique, termed
94.Dq wildcard addressing ,
95allows a single
96server to provide service to clients on multiple networks.
97To create a socket which listens on all networks, the Internet
98address
99.Dv INADDR_ANY
100must be bound.  The
101.Tn TCP
102port may still be specified
103at this time; if the port is not specified the system will assign one.
104Once a connection has been established the socket's address is
105fixed by the peer entity's location.   The address assigned the
106socket is the address associated with the network interface
107through which packets are being transmitted and received.  Normally
108this address corresponds to the peer entity's network.
109.Pp
110.Tn TCP
111supports a number of socket options which can be set with
112.Xr setsockopt 2
113and tested with
114.Xr getsockopt 2 :
115.Bl -tag -width TCP_NODELAYx
116.It Dv TCP_NODELAY
117Under most circumstances,
118.Tn TCP
119sends data when it is presented;
120when outstanding data has not yet been acknowledged, it gathers
121small amounts of output to be sent in a single packet once
122an acknowledgement is received.
123For a small number of clients, such as window systems
124that send a stream of mouse events which receive no replies,
125this packetization may cause significant delays.
126The boolean option
127.Dv TCP_NODELAY
128defeats this algorithm.
129.It Dv TCP_MAXSEG
130By default, a sender\- and receiver-TCP
131will negotiate among themselves to determine the maximum segment size
132to be used for each connection.  The
133.Dv TCP_MAXSEG
134option allows the user to determine the result of this negotiation,
135and to reduce it if desired.
136.It Dv TCP_NOOPT
137.Tn TCP
138usually sends a number of options in each packet, corresponding to
139various
140.Tn TCP
141extensions which are provided in this implementation.  The boolean
142option
143.Dv TCP_NOOPT
144is provided to disable
145.Tn TCP
146option use on a per-connection basis.
147.It Dv TCP_NOPUSH
148By convention, the sender-TCP
149will set the
150.Dq push
151bit and begin transmission immediately (if permitted) at the end of
152every user call to
153.Xr write 2
154or
155.Xr writev 2 .
156The
157.Dv TCP_NOPUSH
158option is provided to allow servers to easily make use of Transaction
159TCP (see
160.Xr ttcp 4 ).
161When the option is set to a non-zero value,
162.Tn TCP
163will delay sending any data at all until either the socket is closed,
164or the internal send buffer is filled.
165.El
166.Pp
167The option level for the
168.Xr setsockopt 2
169call is the protocol number for
170.Tn TCP ,
171available from
172.Xr getprotobyname 3 ,
173or
174.Dv IPPROTO_TCP .
175All options are declared in
176.Aq Pa netinet/tcp.h .
177.Pp
178Options at the
179.Tn IP
180transport level may be used with
181.Tn TCP ;
182see
183.Xr ip 4 .
184Incoming connection requests that are source-routed are noted,
185and the reverse source route is used in responding.
186.Sh MIB VARIABLES
187The
188.Nm
189protocol implements three variables in the
190.Li net.inet
191branch of the
192.Xr sysctl 3
193MIB.
194.Bl -tag -width TCPCTL_DO_RFC1644
195.It Dv TCPCTL_DO_RFC1323
196.Pq tcp.rfc1323
197Implement the window scaling and timestamp options of RFC 1323
198(default true).
199.It Dv TCPCTL_DO_RFC1644
200.Pq tcp.rfc1644
201Implement Transaction
202.Tn TCP ,
203as described in RFC 1644.
204.It Dv TCPCTL_MSSDFLT
205.Pq tcp.mssdflt
206The default value used for the maximum segment size
207.Pq Dq MSS
208when no advice to the contrary is received from MSS negotiation.
209.El
210.Sh DIAGNOSTICS
211A socket operation may fail with one of the following errors returned:
212.Bl -tag -width [EADDRNOTAVAIL]
213.It Bq Er EISCONN
214when trying to establish a connection on a socket which
215already has one;
216.It Bq Er ENOBUFS
217when the system runs out of memory for
218an internal data structure;
219.It Bq Er ETIMEDOUT
220when a connection was dropped
221due to excessive retransmissions;
222.It Bq Er ECONNRESET
223when the remote peer
224forces the connection to be closed;
225.It Bq Er ECONNREFUSED
226when the remote
227peer actively refuses connection establishment (usually because
228no process is listening to the port);
229.It Bq Er EADDRINUSE
230when an attempt
231is made to create a socket with a port which has already been
232allocated;
233.It Bq Er EADDRNOTAVAIL
234when an attempt is made to create a
235socket with a network address for which no network interface
236exists.
237.It Bq Er EAFNOSUPPORT
238when an attempt is made to bind or connect a socket to a multicast
239address.
240.El
241.Sh SEE ALSO
242.Xr getsockopt 2 ,
243.Xr socket 2 ,
244.Xr sysctl 3 ,
245.Xr intro 4 ,
246.Xr inet 4 ,
247.Xr ip 4 ,
248.Xr ttcp 4
249.Rs
250.%A V. Jacobson, R. Braden, and D. Borman
251.%T "TCP Extensions for High Performance"
252.%O RFC 1323
253.Re
254.Rs
255.%A R. Braden
256.%T "T/TCP \- TCP Extensions for Transactions"
257.%O RFC 1644
258.Re
259.Sh HISTORY
260The
261.Nm
262protocol appeared in
263.Bx 4.2 .
264The RFC 1323 extensions for window scaling and timestamps were added
265in
266.Bx 4.4 .
267