Zach Flynn wrote:
Ok, so I'm programming in Unix if that makes any difference. And I'm
doing:
system("telnet somehost.com 25");
But I can't figure out how to send a command to it. Like, for example,
I would like to send the helo command to the smpt port with this telnet
open. Does anyone here know how to? Thanks.
(kinda desired output)
# ./program
Telnetting...
helo
250 welcome.
mail from: wh******@something.org
250 ok.
etc...I think you get the idea that I would like to this inside my C
program.
-Zach
First, wrong newsgroup for this.
Second, you'll want to do roughly the following:
1) Open two pipes. (man 2 pipe)
2) Fork. (man 2 fork)
3) Close the unneeded ends of the pipes in each process. (man 2 close)
4) Use dup2 to set stdin and stdout to your pipes. (man 2 dup2)
5) In your child process, do something like execl("/bin/sh", "/bin/sh",
"-c", "telnet host port"). (man 3 execl)
Then you could read from the program and write to its stdin via your
pipes. Or if you were more comfortable, use fdopen to get FILE*'s to
read/write with instead.