title: linux c/c++ programming telnet connection io redirection
body: <p>I have a computer (say computer A) whenever computer A gets a connection over a particular telnet port, it launches a program.</p>
  
  <p>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. </p>
  
  <p><code><pre>/usr/local/bin/gkermit -e 8000 -w -a /location/x/ -ir</pre></code></p>
  
  <p>I have a second program on computer B. This 2nd program will connect to computer A</p>
  
  <p><code><pre>mPid = forkpty(&amp;mPort, buffer, &amp;mCurrTermattr, NULL);
  ...
  if child
  {
      execl("/usr/bin/telnet", "telnet", mComPort.name.c_str(), NULL);
  }</pre></code></p>
  
  <p>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)</p>
  
  <p>The problem is that when computer B launches gKermit to send a file, It cannot communicate with computer A gKermit.
  <code><pre>system(gkermit -d gkermit.txt -X -e 8000 -i -s testfile.txt)</pre></code></p>
  
  <p>One would think if we are talking using mPort we could redirect the computer B system call stdio to use that mPort by doing:</p>
  
  <p><code><pre>dup2(mPort, STDIN_FILENO)</pre></code></p>
  
  <p>however this does not do the trick. Any help would be appreciated.</p>