Commit | Line | Data |
---|---|---|
15637ed4 RG |
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 | .\" @(#)tcp.4 6.5 (Berkeley) 3/28/91 | |
33 | .\" | |
34 | .Dd March 28, 1991 | |
35 | .Dt TCP 4 | |
36 | .Os BSD 4.2 | |
37 | .Sh NAME | |
38 | .Nm tcp | |
39 | .Nd Internet Transmission Control Protocol | |
40 | .Sh SYNOPSIS | |
41 | .Fd #include <sys/socket.h> | |
42 | .Fd #include <netinet/in.h> | |
43 | .Ft int | |
44 | .Fn socket AF_INET SOCK_STREAM 0 | |
45 | .Sh DESCRIPTION | |
46 | The | |
47 | .Tn TCP | |
48 | protocol provides reliable, flow-controlled, two-way | |
49 | transmission of data. It is a byte-stream protocol used to | |
50 | support the | |
51 | .Dv SOCK_STREAM | |
52 | abstraction. TCP uses the standard | |
53 | Internet address format and, in addition, provides a per-host | |
54 | collection of | |
55 | .Dq port addresses . | |
56 | Thus, each address is composed | |
57 | of an Internet address specifying the host and network, with | |
58 | a specific | |
59 | .Tn TCP | |
60 | port on the host identifying the peer entity. | |
61 | .Pp | |
62 | Sockets utilizing the tcp protocol are either | |
63 | .Dq active | |
64 | or | |
65 | .Dq passive . | |
66 | Active sockets initiate connections to passive | |
67 | sockets. By default | |
68 | .Tn TCP | |
69 | sockets are created active; to create a | |
70 | passive socket the | |
71 | .Xr listen 2 | |
72 | system call must be used | |
73 | after binding the socket with the | |
74 | .Xr bind 2 | |
75 | system call. Only | |
76 | passive sockets may use the | |
77 | .Xr accept 2 | |
78 | call to accept incoming connections. Only active sockets may | |
79 | use the | |
80 | .Xr connect 2 | |
81 | call to initiate connections. | |
82 | .Pp | |
83 | Passive sockets may | |
84 | .Dq underspecify | |
85 | their location to match | |
86 | incoming connection requests from multiple networks. This | |
87 | technique, termed | |
88 | .Dq wildcard addressing , | |
89 | allows a single | |
90 | server to provide service to clients on multiple networks. | |
91 | To create a socket which listens on all networks, the Internet | |
92 | address | |
93 | .Dv INADDR_ANY | |
94 | must be bound. The | |
95 | .Tn TCP | |
96 | port may still be specified | |
97 | at this time; if the port is not specified the system will assign one. | |
98 | Once a connection has been established the socket's address is | |
99 | fixed by the peer entity's location. The address assigned the | |
100 | socket is the address associated with the network interface | |
101 | through which packets are being transmitted and received. Normally | |
102 | this address corresponds to the peer entity's network. | |
103 | .Pp | |
104 | .Tn TCP | |
105 | supports one socket option which is set with | |
106 | .Xr setsockopt 2 | |
107 | and tested with | |
108 | .Xr getsockopt 2 . | |
109 | Under most circumstances, | |
110 | .Tn TCP | |
111 | sends data when it is presented; | |
112 | when outstanding data has not yet been acknowledged, it gathers | |
113 | small amounts of output to be sent in a single packet once | |
114 | an acknowledgement is received. | |
115 | For a small number of clients, such as window systems | |
116 | that send a stream of mouse events which receive no replies, | |
117 | this packetization may cause significant delays. | |
118 | Therefore, | |
119 | .Tn TCP | |
120 | provides a boolean option, | |
121 | .Dv TCP_NODELAY | |
122 | (from | |
123 | .Aq Pa netinet/tcp.h , | |
124 | to defeat this algorithm. | |
125 | The option level for the | |
126 | .Xr setsockopt | |
127 | call is the protocol number for | |
128 | .Tn TCP , | |
129 | available from | |
130 | .Xr getprotobyname 3 . | |
131 | .Pp | |
132 | Options at the | |
133 | .Tn IP | |
134 | transport level may be used with | |
135 | .Tn TCP ; | |
136 | see | |
137 | .Xr ip 4 . | |
138 | Incoming connection requests that are source-routed are noted, | |
139 | and the reverse source route is used in responding. | |
140 | .Sh DIAGNOSTICS | |
141 | A socket operation may fail with one of the following errors returned: | |
142 | .Bl -tag -width [EADDRNOTAVAIL] | |
143 | .It Bq Er EISCONN | |
144 | when trying to establish a connection on a socket which | |
145 | already has one; | |
146 | .It Bq Er ENOBUFS | |
147 | when the system runs out of memory for | |
148 | an internal data structure; | |
149 | .It Bq Er ETIMEDOUT | |
150 | when a connection was dropped | |
151 | due to excessive retransmissions; | |
152 | .It Bq Er ECONNRESET | |
153 | when the remote peer | |
154 | forces the connection to be closed; | |
155 | .It Bq Er ECONNREFUSED | |
156 | when the remote | |
157 | peer actively refuses connection establishment (usually because | |
158 | no process is listening to the port); | |
159 | .It Bq Er EADDRINUSE | |
160 | when an attempt | |
161 | is made to create a socket with a port which has already been | |
162 | allocated; | |
163 | .It Bq Er EADDRNOTAVAIL | |
164 | when an attempt is made to create a | |
165 | socket with a network address for which no network interface | |
166 | exists. | |
167 | .El | |
168 | .Sh SEE ALSO | |
169 | .Xr getsockopt 2 , | |
170 | .Xr socket 2 , | |
171 | .Xr intro 4 , | |
172 | .Xr inet 4 , | |
173 | .Xr ip 4 | |
174 | .Sh HISTORY | |
175 | The | |
176 | .Nm | |
177 | protocol stack appeared in | |
178 | .Bx 4.2 . |