Manual Page Result
0
Command: tcp | Section: 3 | Source: UNIX v10 | File: tcp.3
TCP(3X) TCP(3X)
NAME
tcp_sock, tcp_connect, tcp_listen, tcp_accept, tcp_rcmd - tcp network-
ing functions
SYNOPSIS
#include <sys/inet/tcp_user.h>
int tcp_sock();
int tcp_connect(fd, tp)
int fd;
struct tcpuser *tp;
int tcp_listen(fd, tp)
int fd;
struct tcpuser *tp;
int tcp_accept(fd, tp)
int fd;
struct tcpuser *tp;
int tcp_rcmd(host, port, locuser, remuser, cmd, fd2p)
char *host, *port, *locuser, *remuser, *cmd;
int *fd2p;
DESCRIPTION
These routines are loaded by the -lin option of ld(1).
TCP is a protocol layered upon IP (internet protocol). It provides
full-duplex byte stream connections between end points called sockets.
The address of a socket is composed of the internet address of its host
and the port number to which the socket is bound.
Tcp_sock returns the file descriptor of an unbound socket. Once
opened, a socket may be bound to a port number within the host and set
up as the active or passive end of a connection.
Addresses and parameters are passed in tcpuser structures:
struct tcpuser {
int code;
tcp_port lport, fport;
in_addr laddr, faddr;
int param;
};
Lport and laddr refer to the port and address numbers of the local end
of a connection. Fport and faddr refer to the port and address numbers
of the foreign end of a connection.
Tcp_connect binds socket fd to port tp->lport and attempts to set up a
connection to the socket bound to port tp->fport on host tp->faddr. If
tp->lport is 0, a local port number is automatically chosen. Tcp_con-
nect returns 0 if the connection is established, -1 otherwise.
Tp->lport and tp->laddr are filled in to reflect the local port and ad-
dress numbers for the connection. Communication proceeds by performing
read(2) and write on fd. If tp->param is non-zero, it specifies op-
tions to set for the connection. The only option supported is
SO_KEEPALIVE which causes empty messages to be sent periodically to de-
tect dead connections.
Tcp_listen binds socket fd to port tp->lport and configures the socket
to listen for connection requests to that port. If tp->faddr and
tp->fport are non-zero, only connections coming from sockets on machine
faddr and bound to port fport are listened for. Tcp_listen returns 0
on success, -1 otherwise. tp->laddr is filled in to reflect the local
address number for the connection. Select(2) can be used with a lis-
tening socket to provide asynchronous polling of connection requests by
selecting for pending input on the socket.
Tcp_accept waits for and accepts a connection request sent to the lis-
tening socket fd. When a connection arrives, tcp_accept returns a new
file descriptor over which communications can proceed. Tp->faddr,
tp->fport, tp->laddr, and tp->lport are filled in to identify the two
ends of the connection. Tp->param is filled in with the minor device
number of the tcp device used for the new connection. Fd is left open
and continues listening for connections.
Tcp_rcmd remotely executes a cmd on host as user remuser. Standard in-
put is attached to cmd's standard input and cmd's standard output is
attached to standard output. If fd2p is non-zero, it is filled with
the file descriptor of a new TCP connection attached to cmd's standard
error. Otherwise, cmd's standard error is attached to its standard
output.
FILES
the socket devices
SEE ALSO
ipc(3), internet(3), udp(3)
DIAGNOSTICS
Tcp_sock returns -1 if no sockets are available.
TCP(3X)