1 .\" $NetBSD: tcp.4,v 1.3 1994/11/30 16:22:35 jtc Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
34 .\" @(#)tcp.4 8.1 (Berkeley) 6/5/93
41 .Nd Internet Transmission Control Protocol
47 .Fn socket AF_INET SOCK_STREAM 0
51 protocol provides reliable, flow-controlled, two-way
53 It is a byte-stream protocol used to
59 Internet address format and, in addition, provides a per-host
61 .Dq "port addresses" .
62 Thus, each address is composed
63 of an Internet address specifying the host and network,
66 port on the host identifying the peer entity.
74 Active sockets initiate connections to passive
78 sockets are created active; to create a
81 system call must be used
82 after binding the socket with the
85 Only passive sockets may use the
87 call to accept incoming connections.
88 Only active sockets may use the
92 call to initiate connections.
96 their location to match
97 incoming connection requests from multiple networks.
98 This technique, termed
99 .Dq "wildcard addressing" ,
101 server to provide service to clients on multiple networks.
102 To create a socket which listens on all networks, the Internet
108 port may still be specified
109 at this time; if the port is not specified, the system will assign one.
110 Once a connection has been established, the socket's address is
111 fixed by the peer entity's location.
112 The address assigned to the
113 socket is the address associated with the network interface
114 through which packets are being transmitted and received.
115 Normally, this address corresponds to the peer entity's network.
118 supports a number of socket options which can be set with
122 .Bl -tag -width ".Dv TCP_CONNECTIONTIMEOUT"
124 Under most circumstances,
126 sends data when it is presented;
127 when outstanding data has not yet been acknowledged, it gathers
128 small amounts of output to be sent in a single packet once
129 an acknowledgement is received.
130 For a small number of clients, such as window systems
131 that send a stream of mouse events which receive no replies,
132 this packetization may cause significant delays.
135 defeats this algorithm.
137 By default, a sender- and
138 .No receiver- Ns Tn TCP
139 will negotiate among themselves to determine the maximum segment size
140 to be used for each connection.
143 option allows the user to determine the result of this negotiation,
144 and to reduce it if desired.
147 usually sends a number of options in each packet, corresponding to
150 extensions which are provided in this implementation.
153 is provided to disable
155 option use on a per-connection basis.
158 .No sender- Ns Tn TCP
161 bit, and begin transmission immediately (if permitted) at the end of
166 When this option is set to a non-zero value,
168 will delay sending any data at all until either the socket is closed,
169 or the internal send buffer is filled.
173 options enable to specify the amount of time, in seconds, that the
174 connection must be idle before keepalive probes (if enabled) are sent.
175 The default value is specified by the
178 .Va net.inet.tcp.keepidle .
179 .It Dv TCP_CONNECTIONTIMEOUT
181 .Dv TCP_CONNECTIONTIMEOUT
182 option allows to specify the timeout, in seconds, for new, non established
184 connections. This option can be useful for both active and passive
186 connections. The default value is specified by the
189 .Va net.inet.tcp.keepinit .
191 When keepalive probes are enabled, this option will set the amount of time in seconds between successive keepalives sent to probe an unresponsive peer.
193 .Tn When keepalive probes are enabled, this option will set the number of times a keepalive probe should be repeated if the peer is not responding. After this many probes, the connection will be closed.
194 .It Dv TCP_SENDMOREACKS
197 data packets are received, OS X uses an algorithm to reduce the number of acknowlegements by generating a
199 acknowlegement for 8 data packets instead of acknowledging every other data packet. When this socket option is enabled, the connection will always send a
201 acknowledgement for every other data packet.
202 .It Dv TCP_ENABLE_ECN
203 Using Explicit Congestion Notification (ECN) on
205 allows bi-directional end-to-end notification of congestion without dropping packets. Conventionally TCP/IP networks signal congestion by dropping packets. When ECN is successfully negotiated, an ECN-aware router may set a mark in the IP header instead of dropping a packet in order to signal impending congestion. The
207 receiver of the packet echoes congestion indication to the
209 sender, which reduces it's transmission rate as if it detected a dropped packet. This will avoid unnecessary retransmissions and will improve latency by saving the time required for recovering a lost packet.
210 .It Dv TCP_NOTSENT_LOWAT
211 The send socket buffer of a
212 .Tn TCP sender has unsent and unacknowledged data. This option allows a
213 .Tn TCP sender to control the amount of unsent data kept in the send socket buffer. The value of the option should be the maximum amount of unsent data in bytes. Kevent, poll and select will generate a write notification when the unsent data falls below the amount given by this option. This will allow an application to generate just-in-time fresh updates for real-time communication.
215 The TCP listener can set this option to use TCP Fast Open feature. After
216 setting this option, an
218 may return a socket that is in SYN_RECEIVED state but is readable and writable.
219 .It Dv TCP_CONNECTION_INFO
220 This socket option can be used to obtain TCP connection level statistics. The
221 "struct tcp_connection_info" defined in <netinet/tcp_var.h> is copied to the
225 The option level for the
227 call is the protocol number for
230 .Xr getprotobyname 3 ,
233 All options are declared in
238 transport level may be used with
242 Incoming connection requests that are source-routed are noted,
243 and the reverse source route is used in responding.
244 .Ss "Non-blocking connect"
248 socket is set non-blocking, and the connection cannot be established immediately,
252 returns with the error
254 and the connection is established asynchronously.
256 When the asynchronous connection completes successfully,
262 will indicate the file descriptor is ready for writing.
263 If the connection encounters an error, the file descriptor
264 is marked ready for both reading and writing, and the pending error
265 can be retrieved via the socket option
268 Note that even if the socket is non-blocking, it is possible for the connection
269 to be established immediately. In that case
276 A socket operation may fail with one of the following errors returned:
279 when trying to establish a connection on a socket which
282 when the system runs out of memory for
283 an internal data structure;
285 when a connection was dropped
286 due to excessive retransmissions;
289 forces the connection to be closed;
290 .It Bq Er ECONNREFUSED
292 peer actively refuses connection establishment (usually because
293 no process is listening to the port);
296 is made to create a socket with a port which has already been
298 .It Bq Er EADDRNOTAVAIL
299 when an attempt is made to create a
300 socket with a network address for which no network interface
302 .It Bq Er EAFNOSUPPORT
303 when an attempt is made to bind or connect a socket to a multicast
305 .It Bq Er EINPROGRESS
310 when the socket is set nonblocking, and the connection cannot be
311 immediately established;
317 when connection request is already in progress for the specified socket.
323 in case a connection is experiencing a data-stall (probably due to a middlebox issue).
324 It is advised that the current connection gets closed by the application and a
325 new attempt is being made.
350 .Dv TCP_CONNECTIONTIMEOUT
351 first appeared in Mac OS X 10.6.