2

I am implementing a netcat clone and currently need a way to run command-line programs over the network.

My solution so far is to execute a process and use pipes for STDIN and STDOUT, then forward the data back and forth over TCP.

The problem is, I feel like this is a round-about way of doing things. When I run bash, the prompt doesn't show up, and I am unable to use ncurses programs, like Vi.

Is there an easier way to control the input and see the output of a program in C, or are pipes my best bet?

Here a portion of my code (click on it, it's very intuitive):

http://pastebin.com/MjyxFkdu

I am using C with GNU/Linux.

Irresponsible Newb
  • 603
  • 2
  • 7
  • 15
  • 2
    What will your solution offer that `ssh` doesn't? – Brian Cain Nov 27 '11 at 03:53
  • Could you clarify your question? You want to want send the commands from your netcat clone, but you want it to return inmedialy so you can use the console again? – RedComet Nov 27 '11 at 03:56
  • duskwuff was correct, I should have used telnetd as an example. It looks like a pty is what I am looking for. It seems like I can only create one using syscalls. – Irresponsible Newb Nov 27 '11 at 04:10
  • Regarding your comment Brian Cain, I am doing this as a way of forcing myself to learn, not because I am displeased with SSH. Actually, I am very pleased with SSH. :3 – Irresponsible Newb Nov 27 '11 at 04:12

1 Answers1

2

Correct terminal behavior can't be obtained using pipes -- you will need to use a PTY (pseudoterminal) to get the right results.

Note that what you're trying to write here is essentially telnetd...