tcp(7) —
NAME
tcp − Internet Transmission Control Protocol
SYNOPSIS
#include <sys/socket.h>
#include <netinet/in.h>
s = socket(AF_INET, SOCK_STREAM, 0);
or
#include <sys/tiuser.h>
#include <sys/tcp.h>
#include <netinet/in.h>
t = t_open("/dev/tcp", O_RDWR);
DESCRIPTION
The tcp protocol provides reliable, flow-controlled, two-way transmission of data. It is a byte-stream protocol used to support the SOCK_STREAM abstraction in the socket environment and the T_COT type of transport in the TLI environment. tcp uses the standard Internet address format and provides a per-host collection of “port addresses”. Thus, each address is composed of an Internet address specifying the host and network, with a specific tcp port on the host identifying the peer entity.
Transport endpoints utilizing the tcp protocol are either “active” or “passive”. Active endpoints initiate connections to passive endpoints. By default, tcp endpoints are created active; to create a passive socket in the socket emulation, the listen(3I) call must be used after binding the socket with the bind(3I) call; to create a passive endpoint with TLI, the qlen field in the t_bind structure of a t_bind(3N) call must be set to a nonzero value. Only passive endpoints may use the accept(3I) call of the socket emulation or the t_accept(3N) call of TLI to accept incoming connections. Only active sockets may use the connect(3I) call of the socket emulation to initiate connections. In the TLI interface, both passive and active STREAMS may initiate a connection with the t_connect(3N) call.
Passive endpoints may “underspecify” their location to match incoming connection requests from multiple networks. This technique, termed “wildcard addressing”, allows a single server to provide service to clients on multiple networks. To create an endpoint which listens on all networks, the Internet address INADDR_ANY must be bound. The TCP port may still be specified at this time; if the port is not specified the system will assign one. Once a connection has been established, the endpoint’s address is fixed by the peer entity’s location. The address assigned the endpoint is the address associated with the network interface through which packets are being transmitted and received. Normally this address corresponds to the peer entity’s network.
tcp supports several options which are set with setsockopt (see getsockopt(3I)) in the socket emulation and t_optmgmt(3N) or t_connect(3N) in the option field for TLI, and tested with getsockopt(3I) for the socket emulation and t_optmgmt(3N) for TLI.
Under most circumstances, tcp sends data when it is presented. When outstanding data has not yet been acknowledged, it gathers small amounts of output to be sent in a single packet once an acknowledgment is received. The option level for the setsockopt call is the protocol number for tcp, available from getprotobyname (see getprotoent(3I)). The same values are used with the TLI option management, but the options are specified as a sequence of options in the format specified in struct inetopts in:
#include <netinet/in.h>
The TLI options also support a number of the socket level options.
The socket-level options that apply to tcp are: SO_SNDBUF, SO_RCVBUF, SO_SNDLOWAT, SO_RCVLOWAT, SO_DEBUG, SO_REUSEADDR, SO_KEEPALIVE, SO_BROADCAST, and SO_OOBINLINE, which are described in getsockopt(3I).
For a small number of clients, such as window systems that send a stream of mouse events which receive no replies, this packetization may cause significant delays. Therefore, tcp provides a boolean option, TCP_NODELAY (from <netinet/tcp.h>), to defeat this algorithm.
tcp also has the option TCP_OOBMODE, which provides a mechanism for changing the interpretation of tcp urgent data. The parameter to TCP_OOBMODE is an integer bit mask. The bits determine the exact mode. Options are defined in netinet/tcp_var.h.
TCPOOB_RFCFORM urgent pointer is last octet of urgent data rather than first octet of non-urgent data.
TCPOOB_SEGMENT return all urgent data rather than last octet. The urgent segment is all data from the beginning of the tcp segment to the end of urgent data.
Options at the ip transport level may be used with tcp; see ip(7). Incoming connection requests that are source-routed are noted, and the reverse source route is used in responding.
DIAGNOSTICS
A socket operation may fail with one of the following errors returned:
[EISCONN] when trying to establish a connection on a socket which already has one.
[ENOBUFS] when the system runs out of memory for an internal data structure.
[ETIMEDOUT] when a connection was dropped due to excessive retransmissions.
[ECONNRESET] when the remote peer forces the connection to be closed.
[ECONNREFUSED] when the remote peer actively refuses to establish a connection (usually because no process is listening to the port).
[EADDRINUSE] when an attempt is made to create a socket with a port that has already been allocated.
[EADDRNOTAVAIL] when an attempt is made to create a socket with a network address for which no network interface exists.
A TLI operation may fail with one of the following errors returned:
[TOUTSTATE] when a function was used in the wrong sequence on the STREAM descriptor or the STREAM was not in the idle state.
[TACCES] when the use did not have the proper permissions for the operation.
[TBADOPT] when an incorrectly formatted option or an unimplemented option is specified.
[TBADDATA] when the amount of data was not within the bounds of the transport provider.
[TBADSEQ] when an invalid connection sequence number was specified.
[TLOOK] when an asynchronous event occurred on the STREAM descriptor.
[TNOTSUPPORT] when the underlying transport provider does not support a requested operation.
[TSYSERR] when a system error occurs during operation.
[TNOADDR] when the transport provider cannot assign the requested address.
[TBADADDR] when the user attempts to use an illegal address or formats the address information incorrectly.
[TNODATA] when O_NDELAY is set and an operation would normally have blocked.
[TBADFLAG] when an invalid flag was provided in a t_optmgmt request.
SEE ALSO
getprotoent(3I), getsockopt(3I), socket(3I), intro(7N), inet(7), ip(7), socket(7). Network Programmer’s Guide.
\*U — Version 1.0