Ok then, the best I can do is give some pseudo-code:

- Program starts.
- Create two pipes with pipe() calls.
- fork()
        - Child chooses one pipe and dup2()'s the read end over descriptor 0
(stdin)
        - Child takes other pipe and dup2()'s the write end over descriptor 1
(stdout)
          and maybe descriptor 2 (stderr).
        - Child (to be clean) close all the pipe()'s since they're now
replacing stdin
          and stdout.
        - Parent (to be clean) closes the same ends that were dup2()'ed (since
those
          technically belong to the child only.
        - Child does an execv(), execl(), or your exec of choice of
"telnet". Child
          has now been officially replaced. You may or may not choose to
pass an argument
          that is the host to telnet (you can write "open XXXX" to it
later instead if you
          want.
        - Parent continues.
- Start parsing input and output.
        - Parent read()s from other end of pipe duped to child's descriptor 1
until it
          sees "login:", when it does it write()s the usename to the
other end of the pipe 
          duped to child's descriptor 0.
        - Parent read()s until it sees "password:", when it does it
write()s
          the password. You may want to use regular expressions to do matching
so
          its more portable. You may also want to use select() or poll()
to check
          for read() or write()ability so you don't block (probably not in this
          particular scenario though).
        - Parent read()s until it sees the shell prompt (or output
indicating the shell
          in use is ready for input), then writes any command(s) it
wants to execute.
        - Continue to read() and write() whatever's necessary to control what
you're
          doing.
- When done wait3() for the child to complete (ie: exit).

"telnet" may not be happy with a pipe() as stdin and stdout. In which
case you'll have to use pseudo-terminals (a whole nother ball of wax).
You may have to read character by character and do your own buffering
too. If you're lucky, the above will work.

                        - Matt
begin:vcard 
n:Fahrner;Matt
tel;pager:(603) 639-4142
tel;fax:(603) 443-6190
tel;work:(603) 448-4100 xt 5150
x-mozilla-html:FALSE
url:http://www.gizzy.com/matt
org:Burlington Coat Factory Warehouse;MIS Networking
version:2.1
email;internet:[EMAIL PROTECTED]
title:Manager of Networking
adr;quoted-printable:;;2 South Park St.=0D=0AWillis House;Lebanon;NH;03766;USA
x-mozilla-cpt:;-3648
fn:Matt Fahrner
end:vcard

Reply via email to