static char sccsid
[] = "@(#)rcmd.c 4.2 82/10/07";
char *index(), *sprintf();
rcmd(ahost
, rport
, locuser
, remuser
, cmd
, fd2p
)
char *locuser
, *remuser
, *cmd
;
struct sockaddr_in sin
, sin2
, from
;
hp
= gethostbyname(*ahost
);
fprintf(stderr
, "%s: unknown host\n", *ahost
);
s
= rresvport(rcmdoptions
|SO_KEEPALIVE
);
sin
.sin_family
= hp
->h_addrtype
;
bcopy(hp
->h_addr
, &sin
.sin_addr
, hp
->h_length
);
sin
.sin_port
= htons(rport
);
if (connect(s
, &sin
) < 0) {
if (errno
== ECONNREFUSED
&& timo
<= 16) {
int s2
= rresvport(rcmdoptions
|SO_ACCEPTCONN
);
port
= htons((u_short
)sin2
.sin_port
);
(void) sprintf(num
, "%d", port
);
(void) write(s
, num
, strlen(num
)+1);
if (accept(s2
, &from
) < 0) {
from
.sin_port
= ntohs(from
.sin_port
);
if (from
.sin_family
!= AF_INET
||
from
.sin_port
>= IPPORT_RESERVED
) {
"socket: protocol failure in circuit setup.\n");
(void) write(s
, locuser
, strlen(locuser
)+1);
(void) write(s
, remuser
, strlen(remuser
)+1);
(void) write(s
, cmd
, strlen(cmd
)+1);
if (read(s
, &c
, 1) != 1) {
while (read(s
, &c
, 1) == 1) {
short lport
= IPPORT_RESERVED
- 1;
sin
.sin_family
= AF_INET
;
sin
.sin_port
= htons(lport
);
s
= socket(SOCK_STREAM
, 0, &sin
, options
);
if (errno
!= EADDRINUSE
&& errno
!= EADDRNOTAVAIL
) {
if (lport
== IPPORT_RESERVED
/2) {
fprintf(stderr
, "socket: All ports in use\n");
ruserok(rhost
, ruser
, luser
)
char *rhost
, *ruser
, *luser
;
hostf
= fopen("/etc/hosts.equiv", "r");
while (fgets(ahost
, sizeof (ahost
), hostf
)) {
user
= index(ahost
, ' ');
if (!strcmp(rhost
, ahost
) &&
!strcmp(ruser
, user
? user
: luser
))
hostf
= fopen(".rhosts", "r");