subnets, netmask
[unix-history] / usr / src / share / man / man4 / tcp.4
CommitLineData
ded36191
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
7787ae36 5.\" @(#)tcp.4 6.2 (Berkeley) %G%
ded36191 6.\"
9205d69a 7.TH TCP 4P ""
ded36191
KM
8.UC 5
9.SH NAME
10tcp \- Internet Transmission Control Protocol
11.SH SYNOPSIS
12.B #include <sys/socket.h>
13.br
14.B #include <netinet/in.h>
15.PP
16.B s = socket(AF_INET, SOCK_STREAM, 0);
17.SH DESCRIPTION
18The TCP protocol provides reliable, flow-controlled, two-way
19transmission of data. It is a byte-stream protocol used to
20support the SOCK_STREAM abstraction. TCP uses the standard
21Internet address format and, in addition, provides a per-host
22collection of \*(lqport addresses\*(rq. Thus, each address is composed
23of an Internet address specifying the host and network, with
24a specific TCP port on the host identifying the peer entity.
25.PP
26Sockets utilizing the tcp protocol are either \*(lqactive\*(rq or
27\*(lqpassive\*(rq. Active sockets initiate connections to passive
28sockets. By default TCP sockets are created active; to create a
29passive socket the
30.IR listen (2)
31system call must be used
32after binding the socket with the
33.IR bind (2)
34system call. Only
35passive sockets may use the
36.IR accept (2)
37call to accept incoming connections. Only active sockets may
38use the
39.IR connect (2)
40call to initiate connections.
41.PP
42Passive sockets may \*(lqunderspecify\*(rq their location to match
43incoming connection requests from multiple networks. This
44technique, termed \*(lqwildcard addressing\*(rq, allows a single
45server to provide service to clients on multiple networks.
46To create a socket which listens on all networks, the Internet
47address INADDR_ANY
48must be bound. The TCP port may still be specified
49at this time; if the port is not specified the system will assign one.
50Once a connection has been established the socket's address is
51fixed by the peer entity's location. The address assigned the
52socket is the address associated with the network interface
53through which packets are being transmitted and received. Normally
54this address corresponds to the peer entity's network.
7787ae36
MK
55.PP
56TCP supports one socket option which is set with
57.IR setsockopt (2)
58and tested with
59.IR getsockopt (2).
60Under most circumstances, TCP sends data when it is presented;
61when outstanding data has not yet been acknowledged, it gathers
62small amounts of output to be sent in a single packet once
63an acknowledgement is received.
64For a small number of clients, such as window systems
65that send a stream of mouse events which receive no replies,
66this packetization may cause significant delays.
67Therefore, TCP provides a boolean option, TCP_NODELAY (from
68.IR <netinet/tcp.h> ,
69to defeat this algorithm.
70The option level for the
71.I setsockopt
72call is the protocol number for TCP,
73available from
74.IR getprotobyname (3N).
75.PP
76Options at the IP transport level may be used with TCP; see
77.IR ip (4P).
78Incoming connection requests that are source-routed are noted,
79and the reverse source route is used in responding.
ded36191
KM
80.SH DIAGNOSTICS
81A socket operation may fail with one of the following errors returned:
82.TP 20
83[EISCONN]
84when trying to establish a connection on a socket which
85already has one;
86.TP 20
87[ENOBUFS]
88when the system runs out of memory for
89an internal data structure;
90.TP 20
91[ETIMEDOUT]
92when a connection was dropped
93due to excessive retransmissions;
94.TP 20
95[ECONNRESET]
96when the remote peer
97forces the connection to be closed;
98.TP 20
99[ECONNREFUSED]
100when the remote
101peer actively refuses connection establishment (usually because
102no process is listening to the port);
103.TP 20
104[EADDRINUSE]
105when an attempt
106is made to create a socket with a port which has already been
107allocated;
108.TP 20
109[EADDRNOTAVAIL]
110when an attempt is made to create a
111socket with a network address for which no network interface
112exists.
113.SH SEE ALSO
7787ae36 114getsockopt(2), socket(2), intro(4N), inet(4F), ip(4P)