xref: /csrg-svn/share/man/man4/tcp.4 (revision 47675)
1*47675Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California.
236752Sbostic.\" All rights reserved.
320744Smckusick.\"
443581Strent.\" %sccs.include.redist.man%
520744Smckusick.\"
6*47675Scael.\"     @(#)tcp.4	6.5 (Berkeley) 03/28/91
736752Sbostic.\"
8*47675Scael.Dd
9*47675Scael.Dt TCP 4
10*47675Scael.Os BSD 4.2
11*47675Scael.Sh NAME
12*47675Scael.Nm tcp
13*47675Scael.Nd Internet Transmission Control Protocol
14*47675Scael.Sh SYNOPSIS
15*47675Scael.Fd #include <sys/socket.h>
16*47675Scael.Fd #include <netinet/in.h>
17*47675Scael.Ft int
18*47675Scael.Fn socket AF_INET SOCK_STREAM 0
19*47675Scael.Sh DESCRIPTION
20*47675ScaelThe
21*47675Scael.Tn TCP
22*47675Scaelprotocol provides reliable, flow-controlled, two-way
2320744Smckusicktransmission of data.  It is a byte-stream protocol used to
24*47675Scaelsupport the
25*47675Scael.Dv SOCK_STREAM
26*47675Scaelabstraction.  TCP uses the standard
2720744SmckusickInternet address format and, in addition, provides a per-host
28*47675Scaelcollection of
29*47675Scael.Dq port addresses .
30*47675ScaelThus, each address is composed
3120744Smckusickof an Internet address specifying the host and network, with
32*47675Scaela specific
33*47675Scael.Tn TCP
34*47675Scaelport on the host identifying the peer entity.
35*47675Scael.Pp
36*47675ScaelSockets utilizing the tcp protocol are either
37*47675Scael.Dq active
38*47675Scaelor
39*47675Scael.Dq passive .
40*47675ScaelActive sockets initiate connections to passive
41*47675Scaelsockets.  By default
42*47675Scael.Tn TCP
43*47675Scaelsockets are created active; to create a
4420744Smckusickpassive socket the
45*47675Scael.Xr listen 2
4620744Smckusicksystem call must be used
4720744Smckusickafter binding the socket with the
48*47675Scael.Xr bind 2
4920744Smckusicksystem call.  Only
5020744Smckusickpassive sockets may use the
51*47675Scael.Xr accept 2
5220744Smckusickcall to accept incoming connections.  Only active sockets may
5320744Smckusickuse the
54*47675Scael.Xr connect 2
5520744Smckusickcall to initiate connections.
56*47675Scael.Pp
57*47675ScaelPassive sockets may
58*47675Scael.Dq underspecify
59*47675Scaeltheir location to match
6020744Smckusickincoming connection requests from multiple networks.  This
61*47675Scaeltechnique, termed
62*47675Scael.Dq wildcard addressing ,
63*47675Scaelallows a single
6420744Smckusickserver to provide service to clients on multiple networks.
6520744SmckusickTo create a socket which listens on all networks, the Internet
66*47675Scaeladdress
67*47675Scael.Dv INADDR_ANY
68*47675Scaelmust be bound.  The
69*47675Scael.Tn TCP
70*47675Scaelport may still be specified
7120744Smckusickat this time; if the port is not specified the system will assign one.
7220744SmckusickOnce a connection has been established the socket's address is
7320744Smckusickfixed by the peer entity's location.   The address assigned the
7420744Smckusicksocket is the address associated with the network interface
7520744Smckusickthrough which packets are being transmitted and received.  Normally
7620744Smckusickthis address corresponds to the peer entity's network.
77*47675Scael.Pp
78*47675Scael.Tn TCP
79*47675Scaelsupports one socket option which is set with
80*47675Scael.Xr setsockopt 2
8128252Skarelsand tested with
82*47675Scael.Xr getsockopt 2 .
83*47675ScaelUnder most circumstances,
84*47675Scael.Tn TCP
85*47675Scaelsends data when it is presented;
8628252Skarelswhen outstanding data has not yet been acknowledged, it gathers
8728252Skarelssmall amounts of output to be sent in a single packet once
8828252Skarelsan acknowledgement is received.
8928252SkarelsFor a small number of clients, such as window systems
9028252Skarelsthat send a stream of mouse events which receive no replies,
9128252Skarelsthis packetization may cause significant delays.
92*47675ScaelTherefore,
93*47675Scael.Tn TCP
94*47675Scaelprovides a boolean option,
95*47675Scael.Dv TCP_NODELAY
96*47675Scael(from
97*47675Scael.Aq Pa netinet/tcp.h ,
9828252Skarelsto defeat this algorithm.
9928252SkarelsThe option level for the
100*47675Scael.Xr setsockopt
101*47675Scaelcall is the protocol number for
102*47675Scael.Tn TCP ,
10328252Skarelsavailable from
104*47675Scael.Xr getprotobyname 3 .
105*47675Scael.Pp
106*47675ScaelOptions at the
107*47675Scael.Tn IP
108*47675Scaeltransport level may be used with
109*47675Scael.Tn TCP ;
110*47675Scaelsee
111*47675Scael.Xr ip 4 .
11228252SkarelsIncoming connection requests that are source-routed are noted,
11328252Skarelsand the reverse source route is used in responding.
114*47675Scael.Sh DIAGNOSTICS
11520744SmckusickA socket operation may fail with one of the following errors returned:
116*47675Scael.Bl -tag -width [EADDRNOTAVAIL]
117*47675Scael.It Bq Er EISCONN
11820744Smckusickwhen trying to establish a connection on a socket which
11920744Smckusickalready has one;
120*47675Scael.It Bq Er ENOBUFS
12120744Smckusickwhen the system runs out of memory for
12220744Smckusickan internal data structure;
123*47675Scael.It Bq Er ETIMEDOUT
12420744Smckusickwhen a connection was dropped
12520744Smckusickdue to excessive retransmissions;
126*47675Scael.It Bq Er ECONNRESET
12720744Smckusickwhen the remote peer
12820744Smckusickforces the connection to be closed;
129*47675Scael.It Bq Er ECONNREFUSED
13020744Smckusickwhen the remote
13120744Smckusickpeer actively refuses connection establishment (usually because
13220744Smckusickno process is listening to the port);
133*47675Scael.It Bq Er EADDRINUSE
13420744Smckusickwhen an attempt
13520744Smckusickis made to create a socket with a port which has already been
13620744Smckusickallocated;
137*47675Scael.It Bq Er EADDRNOTAVAIL
13820744Smckusickwhen an attempt is made to create a
13920744Smckusicksocket with a network address for which no network interface
14020744Smckusickexists.
141*47675Scael.El
142*47675Scael.Sh SEE ALSO
143*47675Scael.Xr getsockopt 2 ,
144*47675Scael.Xr socket 2 ,
145*47675Scael.Xr intro 4 ,
146*47675Scael.Xr inet 4 ,
147*47675Scael.Xr ip 4
148*47675Scael.Sh HISTORY
149*47675ScaelThe
150*47675Scael.Nm
151*47675Scaelprotocol stack appeared in
152*47675Scael.Bx 4.2 .
153