Copyright (C) 2000-2012 |
Manpages TCPSection: Linux Programmer's Manual (7)Updated: 1999-04-25 Index Return to Main Contents NAMEtcp - TCP protocol.SYNOPSIS#include <sys/socket.h>#include <netinet/in.h> tcp_socket = socket(PF_INET, SOCK_STREAM, 0); DESCRIPTIONThis 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 FORMATSTCP 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.SYSCTLSThese 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).
SOCKET OPTIONSTo 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).
IOCTLSThese ioctls can be accessed using ioctl(2). The correct syntax is:
ERROR HANDLINGWhen 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. NOTESWhen 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
Any errors defined for ip(7) or the generic socket layer may also be returned for TCP.
BUGSNot all errors are documented.IPv6 is not described. Transparent proxy options are not described. VERSIONSThe 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 ALSOsocket(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.
Index
This document was created by man2html, using the manual pages. Time: 21:56:18 GMT, December 09, 2024 |