linux c/c++ 编程telnet连接io重定向
我有一台计算机(比如计算机 A),每当计算机 A 通过特定的 telnet 端口获得连接时,它就会启动一个程序。
计算机 A 上的该程序处理登录、身份验证等。它可以执行的工作之一是接收文件。 它通过启动 gKermit 来处理此问题。
<代码>
/usr/local/bin/gkermit -e 8000 -w -a /location/x/ -ir
我在计算机 B 上有第二个程序。该第二个程序将连接到计算机 A
mPid = forkpty(&mPort, buffer, &mCurrTermattr, NULL);
...
if child
{
execl("/usr/bin/telnet", "telnet", mComPort.name.c_str(), NULL);
}
现在程序的父进程可以使用文件描述符mPort来发送接收数据。 (即像登录计算机A,并告诉它接收文件)
问题是,当计算机B启动gKermit发送文件时,它无法与计算机A gKermit通信。 <代码>
system(gkermit -d gkermit.txt -X -e 8000 -i -s testfile.txt)
人们可能会认为,如果我们使用 mPort 进行交谈,我们可以通过执行以下操作来重定向计算机 B 系统调用 stdio 以使用该 mPort:
dup2(mPort, STDIN_FILENO)
然而这并不能解决问题。 任何帮助,将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能是错的,但您需要重定向标准输出(如果 kermit 通信是双向的,则可能需要重定向标准输入)。 另外,我有点好奇mPort是什么,管道? 你会读它并写它吗? 通常,您有两个文件描述符,一个用于读取,一个用于写入。
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 的回复,
似乎添加:
现在允许 gKermint 进行双向通信。 这当然有道理。 啊
Thanks for the responses jpalecek,
It seems that adding:
now allows gKermint to communicate in both directions. Which of course makes sense. ugh