xref: /netbsd-src/share/man/man4/tcp.4 (revision d9158b13b5dfe46201430699a3f7a235ecf28df3)
1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
2.\" 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	6.5 (Berkeley) 3/28/91
33.\"	$Id: tcp.4,v 1.2 1993/08/01 07:55:49 mycroft Exp $
34.\"
35.Dd March 28, 1991
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.Pp
84Passive sockets may
85.Dq underspecify
86their location to match
87incoming connection requests from multiple networks.  This
88technique, termed
89.Dq wildcard addressing ,
90allows a single
91server to provide service to clients on multiple networks.
92To create a socket which listens on all networks, the Internet
93address
94.Dv INADDR_ANY
95must be bound.  The
96.Tn TCP
97port may still be specified
98at this time; if the port is not specified the system will assign one.
99Once a connection has been established the socket's address is
100fixed by the peer entity's location.   The address assigned the
101socket is the address associated with the network interface
102through which packets are being transmitted and received.  Normally
103this 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
128call is the protocol number for
129.Tn TCP ,
130available from
131.Xr getprotobyname 3 .
132.Pp
133Options at the
134.Tn IP
135transport level may be used with
136.Tn TCP ;
137see
138.Xr ip 4 .
139Incoming connection requests that are source-routed are noted,
140and the reverse source route is used in responding.
141.Sh DIAGNOSTICS
142A socket operation may fail with one of the following errors returned:
143.Bl -tag -width [EADDRNOTAVAIL]
144.It Bq Er EISCONN
145when trying to establish a connection on a socket which
146already has one;
147.It Bq Er ENOBUFS
148when the system runs out of memory for
149an internal data structure;
150.It Bq Er ETIMEDOUT
151when a connection was dropped
152due to excessive retransmissions;
153.It Bq Er ECONNRESET
154when the remote peer
155forces the connection to be closed;
156.It Bq Er ECONNREFUSED
157when the remote
158peer actively refuses connection establishment (usually because
159no process is listening to the port);
160.It Bq Er EADDRINUSE
161when an attempt
162is made to create a socket with a port which has already been
163allocated;
164.It Bq Er EADDRNOTAVAIL
165when an attempt is made to create a
166socket with a network address for which no network interface
167exists.
168.El
169.Sh SEE ALSO
170.Xr getsockopt 2 ,
171.Xr socket 2 ,
172.Xr intro 4 ,
173.Xr inet 4 ,
174.Xr ip 4
175.Sh HISTORY
176The
177.Nm
178protocol stack appeared in
179.Bx 4.2 .
180