Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

read(2)

write(2)

getmsg(2)

putmsg(2)

socket(2)

bind(2)

connect(2)

send(2)

sendto(2)

recv(2)

recvfrom(2)

getsockopt(2)

setsockopt(2)

listen(2)

accept(2)

shutdown(2)

getsockname(2)

getpeername(2)

streamio(7)

clone(7)

raw(7)

udp(7)

ip(7)

TCP(7)  —  

NAME

tcp − internet transmission control protocol (TCP) multiplexor

DESCRIPTION

tcp is a (N by 1) STREAMS multiplexor.  The upstream side (N) is clonable (see clone(7)).  The downstream side is the ip(7) multiplexor.  tcp implements the TCP protocol which provides reliable, flow-controlled, byte-stream, connection-based, two-way transmission of data.  tcp uses the standard Internet address format and, in addition, provides a per-host collection of “port addresses”.  Thus, a tcp endpoint is identified by the <internet-addr, port> pair.  A circuit can then uniquely be specified by two endpoints.  a tcp endpoint can be either “active” or “passive”.  The active side initiates connections to the passive side. 

tcp supports two abstractions: the socket abstraction as in the BSD systems and the Transport Level Interface (TLI) abstraction as in System V Release 3.  A connection example, for the socket abstraction, follows.  A user server program:

− creates (via open(2)) a passive tcp channel,

− sets it to the socket abstraction (via SOCK_ON ioctl),

− binds (via SOCK_BIND ioctl) to a “listening” address, which can be “wildcard” (INADDR_ANY) as defined in <netinet/in.h>,

− listens (via SOCK_LISTEN ioctl) to the network,

− accepts (via SOCK_ACCEPT ioctl) incoming connection requests. 

Only active TCP endpoints can initiate connection (via SOCK_CONNECT).  Once the connection is established, read(2) and write(2) system calls are used to transfer data.  That is, at the tcp upper multiplexor level, data is encoded in the M_DATA STREAMS messages. 

In the TLI abstraction, tcp implements the kernel level transport provider interface (TPI).  This abstraction is used in conjunction with the user level TLI library.  Connection setup and takedown procedure is similar, in principle, to that for the socket abstraction, but differs syntactically.  For example, a connection request is not presented as an ioctl command; TPI expects an M_PROTO message which contains “T_conn_req” information.  Each transfer contains an M_PROTO block and one or more M_DATA blocks.  The M_PROTO has the type T_DATA_REQ for output and T_DATA_IND for input.  There is no address information in the M_PROTO block, only “MORE_flag” to indicate the continuation of the transport service data unit. 

COMMAND FUNCTIONS

tcp recognizes the following ioctl commands. 

I_LINK Link another stream (ip) under tcp.  I_LINK can only happen at channel 0 (the tcp control channel).  Error codes are:

[EPERM] The user does not have the “root” privilege. 

[EINVAL] The tcp multiplexor has been linked. 

I_UNLINK Unlink the ip stream.  I_UNLINK can only happen at channel 0 (the tcp control channel).  Error codes are:

[EPERM] The user does not have the “root” privilege. 

[EINVAL] The tcp multiplexor is not linked. 

SOCK_ON Set to “socket” mode. 

SOCK_OFF Set to “TLI” mode.  This is the default mode. 

The following are applicable to the TLI abstraction only. 

TF_RDWR Set to “tirdwr” mode such that when data arrives, only M_DATA blocks will be sent up (instead of with the leading M_PROTO block). 

The following are applicable to the socket abstraction only.  Most of the commands take an argument which is either an integer or a pointer to an address in the form of struct sockaddr_in as defined in <netinet/in.h>.  Other definitions and data structures can be found in <sys/socklib.h>. 

SOCK_BIND Bind the specified address to the local endpoint.  Error codes are:

[EISCONN] This channel was bound before. 

[EAFNOSUPPORT] The specified address family is not supported.  Currently only the Internet family is supported. 

[EADDRINUSE] Try to bind to a reserved port which was used by another channel and the user does not have the root privilege. 

[EADDRNOTAVAIL] All available ports are currently used. 

SOCK_LISTEN Indicate the willingness to accept connection and set the limit for simultaneous pending connections.  Error codes are:

[EISCONN] The channel is already listening. 

[EINVAL] The argument (limit) is not an integer. 

[EINVAL] The listening channel is not bound yet. 

[EBUSY] Another channel is already listening in the same address. 

SOCK_REJECT (The listener) refuse the connection request.  There are potential many pending requests.  The socket abstraction always refuses the first request, the one in the front of the queue.  The TLI abstraction has the option to refuse any request.  Error codes are:

[EINVAL] There is no pending connection request. 

SOCK_ACCEPT Accept a connection. 
This interface resembles the I_FDINSERT STREAMS ioctl.  An accepting scenario is as follow.  When the connection request comes in to the listening channel, The following structure encoded in the M_PROTO is sent upstream to indicate a connection request just arrives. 

typedef struct {
ulongoperation;/∗ SOCK_CONNIND here ∗/
ulongfildes;/∗ fd is accepted on ∗/
ulongseq;/∗ sequence number ∗/
intfamily;/∗ address family ∗/
union a { /∗ foreign address ∗/
struct sockaddr_in in;
struct sockaddr_un un;
} rem_addr;
} socketop_t;

Once the server decides to accept the connection, it first opens a new tcp channel and puts the file descriptor in fildes. Then the server issues this ioctl (SOCK_ACCEPT), again using the argument socketop_t. The pending connection request is then associated with the new channel. A circuit is now considered established.
If the SOCK_ACCEPT is done before any connection request, the ioctl is held and not acknowledged.  This effectively puts the caller to sleep (until the connection comes). 
Error codes are:

[EINVAL] The argument does not point to a correct socketop_t structure. 

[EINVAL] fildes is not a valid stream file descriptor or not associated with any tcp(7) channel. 

[EINVAL] The accepting channel is not in the listening state. 

SOCK_CONNECT Connect to another tcp endpoint whose address is specified in the argument.  Error codes are:

[EINVAL] Address format is wrong. 

[EADDRNOTAVAIL] If the local endpoint was not bound previously, now attempt to bind first.  Return this error if no free port is available. 

[EISCONN] This channel is already in the “connect” state. 

[EAFNOSUPPORT] The specified address family is not supported.  Currently only the Internet family is supported. 

[ENOBUFS] Can not allocate internal resources used for the connection. 

SOCK_SHUTDOWN Shutdown either the receiving side (argument is 0), or the sending side (argument is 1), or both sides (argument is 2). 

SOCK_GETNAME Return the address of our own endpoint. 

SOCK_GETPEER Return the address of the peer endpoint which is connected to us. 

SOCK_SETOPT Set socket options.  For options that are recognized, see either <sys/socket.h> or setsockopt(2) manual page. 

SOCK_GETOPT Get socket options.  For options that are recognized, see either <sys/socket.h> or getsockopt(2) manual page. 

SOCK_SENDOOB There may be one or more M_DATA blocks following the M_IOCTL.  These data blocks are sent to peer as the out-of-band data.  Normally only one byte of OOB data is present. 

SOCK_RECVOOB Retrieve the out-of-band data (only one byte).  If there is no OOB data pending, the ioctl returns error code EWOULDBLOCK. 

FILES

/dev/tcp tcp clone device

/dev/tcp0 tcp control channel

SEE ALSO

read(2), write(2), getmsg(2), putmsg(2), socket(2), bind(2), connect(2), send(2), sendto(2), recv(2), recvfrom(2), getsockopt(2), setsockopt(2), listen(2), accept(2), shutdown(2), getsockname(2), getpeername(2) streamio(7), clone(7), raw(7), udp(7), ip(7)

September 02, 1992

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