Redirect stdin and stdout to a TCP connection

Redirect stdin and stdout to a TCP connection

Post by na8530b00-Rive » Wed, 22 Feb 1995 05:45:18



Hello everybody,

How I can redirect the stdin and stdout to a TCP connection?

The reason I asked this question is because I want to use a
regular shell application thru telnet. For example, if somebody
types telnet xxx.xxx.xxx.com 12345 I want my shell/C program
to attend the socket, but at the same time if I am at the
shell prompt I would like to execute the same program using
the standard IO.

Thanks in advance,
Miguel A. Rivera
AT&T Bell Labs.
Naperville, IL. 60563

 
 
 

Redirect stdin and stdout to a TCP connection

Post by Eric Bierm » Wed, 22 Feb 1995 10:57:36




>Hello everybody,

>How I can redirect the stdin and stdout to a TCP connection?

>The reason I asked this question is because I want to use a
>regular shell application thru telnet. For example, if somebody
>types telnet xxx.xxx.xxx.com 12345 I want my shell/C program
>to attend the socket, but at the same time if I am at the
>shell prompt I would like to execute the same program using
>the standard IO.

skd = accept ();

if skd < 0  error

fork();

if child {

   close 0,
   close 1
   dup(skd);   /* to duplicate the socket as std input */
   dup(skd);   /* to duplicate the socket as the std output */

   exec the shell script
 }

/* parent do whatever you want */

Ravikanth Varahagiri

 
 
 

Redirect stdin and stdout to a TCP connection

Post by Jim L » Wed, 22 Feb 1995 16:44:09


I'm not sure if this is appropriate for your needs, but another
way to accomplish this is to have your inetd setup to run
your C program.  When you do this, inetd automatically takes
care of all of the socket stuff, and starts up your C program,
and sets up stdin, stdout, and stderr to the socket.

Jim Lum

 
 
 

Redirect stdin and stdout to a TCP connection

Post by Riku Saikkon » Fri, 24 Feb 1995 04:18:22



>How I can redirect the stdin and stdout to a TCP connection?
>The reason I asked this question is because I want to use a
>regular shell application thru telnet. For example, if somebody
>types telnet xxx.xxx.xxx.com 12345 I want my shell/C program
>to attend the socket, but at the same time if I am at the
>shell prompt I would like to execute the same program using
>the standard IO.

If you have root access, use inetd (see man inetd). Otherwise, see the inetd
source or something... Inetd does just that before executing any daemon.

An example from the /etc/inetd.conf I have (not on spider.compart.fi):

systat  stream  tcp     nowait  guest   /usr/sbin/tcpd  /bin/ps -auwwx
netstat stream  tcp     nowait  guest   /usr/sbin/tcpd  /bin/netstat -tu

And those are the standard ps and netstat... Tcpd is from tcp_wrapper, you
don't need it for this (but it's otherwise a good thing to have).

--

"The world is indeed full of peril, and in it there are many dark places;
but still there is much that is fair, and though in all lands love is now
mingled with grief, it grows perhaps the greater." - J.R.R. Tolkien

 
 
 

Redirect stdin and stdout to a TCP connection

Post by Kari E. Hurt » Tue, 28 Feb 1995 22:53:19


?How I can redirect the stdin and stdout to a TCP connection?

?The reason I asked this question is because I want to use a
?regular shell application thru telnet. For example, if somebody
?types telnet xxx.xxx.xxx.com 12345 I want my shell/C program
?to attend the socket, but at the same time if I am at the
?shell prompt I would like to execute the same program using
?the standard IO.

Redirectoring of stdin and stdout to TCP connection not handle
telnet -options  (telnet commands which is started with byte 255)
correctly -- that way you don't talk telnet -protocol.

This may or may not hurt you. Just warning.
--
- Kari E. Hurtta                             /  El?m? on monimutkaista