views:

1110

answers:

2

I have a computer (say computer A) whenever computer A gets a connection over a particular telnet port, it launches a program.

this program on computer A handles login, authentication etc. One of the jobs it can do is receive files. It handles this by launching gKermit.

/usr/local/bin/gkermit -e 8000 -w -a /location/x/ -ir

I have a second program on computer B. This 2nd program will connect to computer A

mPid = forkpty(&mPort, buffer, &mCurrTermattr, NULL);
...
if child
{
    execl("/usr/bin/telnet", "telnet", mComPort.name.c_str(), NULL);
}

now the parent process of the program can use the file descriptor mPort to send receive data. (i.e. like logging into computer A, and telling it to receive a file)

The problem is that when computer B launches gKermit to send a file, It cannot communicate with computer A gKermit.

system(gkermit -d gkermit.txt -X -e 8000 -i -s testfile.txt)

One would think if we are talking using mPort we could redirect the computer B system call stdio to use that mPort by doing:

dup2(mPort, STDIN_FILENO)

however this does not do the trick. Any help would be appreciated.

A: 

I may be wrong, but you need to redirect stdout (and maybe stdin if kermit communication is bidirectional). Also, I'm a little curious what is the mPort, a pipe? Do you read and write to it? Usually, you have two file descriptors, one fo reading, one for writing.

jpalecek
mPort is the file descriptor returned from forkpty() [link text][1]data is sent/received over telnet connection from computer B to computer A using mPort as the file descriptor in read()/write() [1]: http://linux.die.net/man/3/forkpty
Tree77
Would your program work without allocating the terminal (eg. with normal pipes?) I would try it, since the correspondence between data passed to the terminal is not equivalent to the data read in the child. And definitely, redirect both fds.
jpalecek
A: 

Thanks for the responses jpalecek,

It seems that adding:

dup2(mPort, STDOUT_FILENO)

now allows gKermint to communicate in both directions. Which of course makes sense. ugh

Tree77