I'm trying to develop a remote shell using unix (debian sarge) and C
I'm stuck at the point when I have to return the output of a command
from the server to the client, I'm trying to redirect the stdout and
stderr to a temporary txt file (freopen + popen), then read from it and
send the results to the socket but I can't make it work...
I would post my code but it's so messy than I'd rather ask if any of you
have a code sample of this process (executing a command on the server
and send back the results to the client)
thanks a lot
G
> I'm trying to develop a remote shell using unix (debian sarge) and C
Then I strongly suggest diving into the sources of rsh (ie the
rsh-client and rsh-server debian packages)
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile(at)starynkevitch(dot)net
8, rue de la Faïencerie, 92340 Bourg La Reine, France
thanks, I'll try to dive then ;)
There already exists implementations of what you are trying to do
(but if this is just intended as an exercise to get to know the
system, doing it again may still be relevant). Examples doing
what you are trying to do include rsh, rlogin, telnet, and finally
ssh which is a more secure replacement for all of them.
The part about redirecting i/o is typically done through a pseudo
tty, which you can read a bit about here:
http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#ptmx
Only few programs need stdio to be attached to a tty. If you don't
need a tty, it may be simpler to use pipes or just attach the program
directly to the socket.
freopen and popen are completely irrelevant for what you are trying
to do. Instead you should look into dup2 and close. You may also find
a need for fork and exec*.
--
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.
> freopen and popen are completely irrelevant for what you are trying
> to do. Instead you should look into dup2 and close. You may also find
> a need for fork and exec*.
I tried with fork and exec but I didn't manage to redirect the output to
the socket or the temp file cause when I call the exec it starts its own
stdout and stderr
--
remove numbers from email address if willing to send private message
Most likely you are doing something wrong
when trying to redirect the output.