Re: Changing an existing tool to talk over ssh
From: all mail refused (elvis_at_notatla.org.uk)
Date: 03/17/04
- Next message: Darren Tucker: "Re: Port For Control And Transfer"
- Previous message: Rishi Chopra: "Re: Port For Control And Transfer"
- In reply to: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Next in thread: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Reply: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 17 Mar 2004 02:50:06 GMT
In article <pGI5c.10198$HK6.96@newssvr23.news.prodigy.com>, Steve Turner wrote:
>When I speak of "ssh-enabled" tools, I'm talking about tools like rsync
>or scp that call ssh under the covers to perform the connection and
>execute a daemon process on behalf of the client. As near as I can
>figure these tools open a pipe (which yields both a read and a write
>handle) connects the read and write handles to the stdin and stdout of a
>forked ssh process, and the handles magically become the mechanism with
>with the client and server speak to each other. If I am correct (in
>spite of my naive understanding of Unix sockets programming, forked
>processes, and duped file handles), can the program I'm looking at be
>made to use only one of those handles for both reading and writing, or
>should I rework the program to use a socket "pair"? Thanks.
If you do the SSH protocol, calculations and all, in your program you're
free to call connect() once and do whatever you want. If you use SSH
as "ssh -N -L 2000:localhost:3000 foreign" you've got much the same.
If you're calling an external ssh program I think you'll want the pair.
#!/usr/bin/perl -w
pipe(RHDOWN,WHDOWN) or die("pipe");
pipe(RHUP,WHUP) or die("pipe");
$pid=fork();
die("fork") unless defined($pid);
if (!$pid) {
# child
close(RHUP);
close(WHDOWN);
open(STDIN, "<&RHDOWN");
open(STDOUT, ">&WHUP"); # should do STDERR to
exec("/usr/local/bin/ssh",
"SOMEHOST-WITH-PASSWORDLESS-ACCESS", "dc") or die("ssh");
}
# parent
close(RHDOWN);
close(WHUP);
printf(WHDOWN "1\n");
for (1..5) {
printf(WHDOWN "2*p\n");
}
printf(WHDOWN "quit\n");
close(WHDOWN);
while (<RHUP>) {
chomp;
printf("REMOTE DC SAYS :%s:\n", $_);
}
close(RHUP);
waitpid($pid,0);
exit(0);
-- Elvis Notargiacomo master AT barefaced DOT cheek
- Next message: Darren Tucker: "Re: Port For Control And Transfer"
- Previous message: Rishi Chopra: "Re: Port For Control And Transfer"
- In reply to: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Next in thread: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Reply: Steve Turner: "Re: Changing an existing tool to talk over ssh"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|