Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getsockopt(2)

socket(2)

inet(4f)

intro(4n)

ip(4p)

tcp(4p)

Name

tcp − Internet Transmission Control Protocol

Syntax

#include <sys/socket.h>
#include <netinet/in.h>

s = socket(AF_INET, SOCK_STREAM, 0);

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.  TCP uses the standard Internet address format and, in addition, 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. 

Sockets utilizing the TCP protocol are either “active” or “passive”.  Active sockets initiate connections to passive sockets.  By default TCP sockets are created active; to create a passive socket the listen() system call must be used after binding the socket with the bind() system call.  Only passive sockets can use the accept() call to accept incoming connections.  Only active sockets can use the connect() call to initiate connections.

Passive sockets can “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 a socket that listens on all networks, the Internet address INADDR_ANY must be bound.  The TCP port can still be specified at this time.  If the port is not specified,  the system will assign one.  Once a connection has been established,  the socket’s address is fixed by the peer entity’s location.   The address assigned the socket 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 one socket option that is set with setsockopt() and tested with getsockopt(.). 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 acknowledgement is received. For a small number of clients, such as window systems that send a stream of mouse events that 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. The option level for the setsockopt call is the protocol number for TCP, available from getprotobyname(.).

Diagnostics

A socket operation may fail with one of the following errors returned:

[EISCONN] Try to establish a connection on a socket which already has one. 

[ENOBUFS] The system runs out of memory for an internal data structure. 

[ETIMEDOUT] A connection was dropped due to excessive retransmissions. 

[ECONNRESET] The remote peer forces the connection to be closed. 

[ECONNREFUSED] The remote peer actively refuses connection establishment (usually because no process is listening to the port). 

[EADDRINUSE] An attempt is made to create a socket with a port that has already been allocated. 

[EADDRNOTAVAIL] An attempt is made to create a socket with a network address for which no network interface exists. 

See Also

getsockopt(2), socket(2), inet(4f), intro(4n), ip(4p)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026