Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
tcp(7)
Edit
PageHistory
Diff
Info
LikePages
TCP !!!TCP NAME SYNOPSIS DESCRIPTION ADDRESS FORMATS SYSCTLS SOCKET OPTIONS IOCTLS ERROR HANDLING NOTES ERRORS BUGS VERSIONS SEE ALSO ---- !!NAME tcp - TCP protocol. !!SYNOPSIS __#include __ #include __ tcp_socket = socket(PF_INET, SOCK_STREAM, 0);__ !!DESCRIPTION This is an implementation of the TCP protocol defined in RFC793, RFC1122 and RFC2001 with the !NewReno and SACK extensions. It provides a reliable, stream oriented, full duplex connection between two sockets on top of ip(7). TCP guarantees that the data arrives in order and retransmits lost packets. It generates and checks a per packet checksum to catch transmission errors. TCP does not preserve record boundaries. A fresh TCP socket has no remote or local address and is not fully specified. To create an outgoing TCP connection use connect(2) to establish a connection to another TCP socket. To receive new incoming connections bind(2) the socket first to a local address and port and then call listen(2) to put the socket into listening state. After that a new socket for each incoming connection can be accepted using accept(2). A socket which has had __accept__ or __connect__ successfully called on it is fully specified and may transmit data. Data cannot be transmitted on listening or not yet connected sockets. Linux 2.2 supports the RFC1323 TCP high performance extensions. This includes large TCP windows to support links with high latency or bandwidth. In order to make use of them, the send and receive buffer sizes must be increased. They can be be set globally with the __net.core.wmem_default__ and __net.core.rmem_default__ sysctls, or on individual sockets by using the __SO_SNDBUF__ and __SO_RCVBUF__ socket options. The maximum sizes for socket buffers are limited by the global __net.core.rmem_max__ and __net.core.wmem_max__ sysctls. See socket(7) for more information. TCP supports urgent data. Urgent data is used to signal the receiver that some important message is part of the data stream and that it should be processed as soon as possible. To send urgent data specify the __MSG_OOB__ option to send(2). When urgent data is received, the kernel sends a __SIGURG__ signal to the reading process or the process or process group that has been set for the socket using the __FIOCSPGRP__ or __FIOCSETOWN__ ioctls. When the __SO_OOBINLINE__ socket option is enabled, urgent data is put into the normal data stream (and can be tested for by the __SIOCATMARK__ ioctl), otherwise it can be only received when the __MSG_OOB__ flag is set for sendmsg(2). !!ADDRESS FORMATS TCP is built on top of IP (see ip(7)). The address formats defined by ip(7) apply to TCP. TCP only supports point-to-point communication; broadcasting and multicasting are not supported. !!SYSCTLS These sysctls can be accessed by the __/proc/sys/net/ipv4/*__ files or with the sysctl(2) interface. In addition, most IP sysctls also apply to TCP; see ip(7). __tcp_window_scaling__ Enable RFC1323 TCP window scaling. __tcp_sack__ Enable RFC2018 TCP Selective Acknowledgements. __tcp_timestamps__ Enable RFC1323 TCP timestamps. __tcp_fin_timeout__ How many seconds to wait for a final FIN packet before the socket is forcibly closed. This is strictly a violation of the TCP specification, but required to prevent denial-of-service attacks. __tcp_keepalive_probes__ Maximum TCP keep-alive probes to send before giving up. Keep-alives are only sent when the __SO_KEEPALIVE__ socket option is enabled. __tcp_keepalive_time__ The number of seconds after no data has been transmitted before a keep-alive will be sent on a connection. The default is 10800 seconds (3 hours). __tcp_max_ka_probes__ How many keep-alive probes are sent per slow timer run. To prevent bursts, this value should not be set too high. __tcp_stdurg__ Enable the strict RFC793 interpretation of the TCP urgent-pointer field. The default is to use the BSD-compatible interpretation of the urgent-pointer, pointing to the first byte after the urgent data. The RFC793 interpretation is to have it point to the last byte of urgent data. Enabling this option may lead to interoperatibility problems. __tcp_syncookies__ Enable TCP syncookies. The kernel must be compiled with __CONFIG_SYN_COOKIES__. Syncookies protects a socket from overload when too many connection attempts arrive. Client machines may not be able to detect an overloaded machine with a short timeout anymore when syncookies are enabled. __tcp_max_syn_backlog__ Length of the per-socket backlog queue. As of Linux 2.2, the backlog specified in listen(2) only specifies the length of the backlog queue of already established sockets. The maximum queue of sockets not yet established (in __SYN_RECV__ state) per listen socket is set by this sysctl. When more connection requests arrive, Linux starts to drop packets. When syncookies are enabled the packets are still answered and this value is effectively ignored. __tcp_retries1__ Defines how many times an answer to a TCP connection request is retransmitted before giving up. __tcp_retries2__ Defines how many times a TCP packet is retransmitted in established state before giving up. __tcp_syn_retries__ Defines how many times to try to send an initial SYN packet to a remote host before giving up and returns an error. Must be below 255. This is only the timeout for outgoing connections; for incoming connections the number of retransmits is defined by __tcp_retries1__. __tcp_retrans_collapse__ Try to send full-sized packets during retransmit. This is used to work around TCP bugs in some stacks. !!SOCKET OPTIONS To set or get a TCP socket option, call getsockopt(2) to read or setsockopt(2) to write the option with the socket family argument set to __SOL_TCP__. In addition, most __SOL_IP__ socket options are valid on TCP sockets. For more information see ip(7). __TCP_NODELAY__ Turn the Nagle algorithm off. This means that packets are always sent as soon as possible and no unnecessary delays are introduced, at the cost of more packets in the network. Expects an integer boolean flag. __TCP_MAXSEG__ Set or receive the maximum segment size for outgoing TCP packets. If this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the interface MTU are ignored and have no effect. __TCP_CORK__ If enabled don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. This option cannot be combined with __TCP_NODELAY__. !!IOCTLS These ioctls can be accessed using ioctl(2). The correct syntax is: __int__ ''value''__; __''error'' __= ioctl(__''tcp_socket''__,__ ''ioctl_type''__, __''value''__); __ __FIONREAD__ or __TIOCINQ__ Returns the amount of queued unread data in the receive buffer. Argument is a pointer to an integer. __SIOCATMARK__ Returns true when the all urgent data has been already received by the user program. This is used together with __SO_OOBINLINE__. Argument is an pointer to an integer for the test result. __TIOCOUTQ__ Returns the amount of unsent data in the socket send queue in the passed integer value pointer. Unfortunately, the implementation of this ioctl is buggy in all known versions of Linux and instead returns the free space (effectively buffer size minus bytes used including metadata) in the send queue. This will be fixed in future Linux versions. If you use __TIOCOUTQ__, please include a runtime test for both behaviors for correct function on future releases and other Unixes. !!ERROR HANDLING When a network error occurs, TCP tries to resend the packet. If it doesn't succeed after some time, either __ETIMEDOUT__ or the last received error on this connection is reported. Some applications require a quicker error notification. This can be enabled with the __SOL_IP__ level __IP_RECVERR__ socket option. When this option is enabled, all incoming errors are immediately passed to the user program. Use this option with care - it makes TCP less tolerant to routing changes and other normal network conditions. !!NOTES When an error occurs doing a connection setup occuring in a socket write __SIGPIPE__ is only raised when the __SO_KEEPALIVE__ socket option is set. TCP has no real out-of-band data; it has urgent data. In Linux this means if the other end sends newer out-of-band data the older urgent data is inserted as normal data into the stream (even when __SO_OOBINLINE__ is not set). This differs from BSD based stacks. Linux uses the BSD compatible interpretation of the urgent pointer field by default. This violates RFC1122, but is required for interoperability with other stacks. It can be changed by the __tcp_stdurg__ sysctl. !!ERRORS __EPIPE__ The other end closed the socket unexpectedly or a read is executed on a shut down socket. __ETIMEDOUT__ The other end didn't acknowledge retransmitted data after some time. __EAFNOTSUPPORT__ Passed socket address type in ''sin_family'' was not __AF_INET__. Any errors defined for ip(7) or the generic socket layer may also be returned for TCP. !!BUGS Not all errors are documented. IPv6 is not described. Transparent proxy options are not described. !!VERSIONS The sysctls are new in Linux 2.2. __IP_RECVERR__ is a new feature in Linux 2.2. __TCP_CORK__ is new in 2.2. !!SEE ALSO socket(7), socket(2), ip(7), sendmsg(2), recvmsg(2) RFC793 for the TCP specification. RFC1122 for the TCP requirements and a description of the Nagle algorithm. RFC2581 for some TCP algorithms. ----
13 pages link to
tcp(7)
:
udp(7)
Man7t
services(5)
sendto(2)
getsockopt(2)
sendfile(2)
sendmsg(2)
listen(2)
NetworkProgrammingOld
setsockopt(2)
ip(7)
AdvancedUserTips
send(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.