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