'\"macro stdmacro
.if n .pH g3n.rexec @(#)rexec	40.4 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} rexec 3N "TCP/IP" "\&"
.if \nX=1 .ds x} rexec 3N "TCP/IP"
.if \nX=2 .ds x} rexec 3N "" "\&"
.if \nX=3 .ds x} rexec "" "" "\&"
.TH \*(x}
.SH NAME
\f4rexec\f1 \- return stream to a remote command
.SH SYNOPSIS
.nf
\f4rem = rexec(ahost, inport, user, passwd, cmd, fd2p);\f1
\f4char **ahost;\f1
\f4u_short inport;\f1
\f4char *user, *passwd, *cmd;\f1
\f4int *fd2p;\f1
.fi
.SH DESCRIPTION
.LP
\f4rexec(\|)\f1
looks up the host
.I *ahost
using
\f4gethostbyname\f1
[see
\f4gethostent\f1(3N)],
returning \-1 if the host does not exist.
Otherwise
.I *ahost
is set to the standard name of the host.
If a username and password are both specified, then these
are used to authenticate to the foreign host; otherwise
the environment and then the user's \f4\.netrc\f1
file in his home directory are searched
for appropriate information.  If all this fails,
the user is prompted for the information.
.LP
The port
\f4inport\f1
specifies which well-known
.SM DARPA
Internet port to use for the connection.
The protocol for connection is described in detail in
\f4rexecd\f1(1M).
.LP
If the call succeeds, a socket of type
\f4SOCK_STREAM\f1
is returned to the caller, and given to
the remote command as its standard input and standard output.
If
.I fd2p
is non-zero, then a auxiliary channel to a control
process will be setup, and a descriptor
for it will be placed in
.IR *fd2p .
The control process will return diagnostic
output from the command (unit 2) on this channel,
and will also accept bytes on this channel as
signal numbers, to be forwarded to the process
group of the command.  If
.I fd2p
is 0, then the standard error
(unit 2 of the remote
command) will be made the same as its standard output
and no provision is made for sending arbitrary
signals to the remote process, although you may be
able to get its attention by using out-of-band data.
.SH SEE ALSO
\f4gethostent\f1(3N),
\f4getservent\f1(3N),
\f4rcmd\f1(3N),
\f4rexecd\f1(1M).
.SH NOTES
.LP
There is no way to specify options to the
\f4socket(\|)\f1
call that
\f4rexec(\|)\f1
makes.
