Negotiating echo with telnet client

混江龙づ霸主 提交于 2019-12-11 14:20:56

问题


For some reason, I want to create a server for the standard Telnet application as client to connect to. I wrote a basic TCP server in C++, its purpose is to serve an interactive menu, so I have to set ECHO on my side.

When the client connects, I send IAC WILL ECHO to it, and I expected to get IAC DO ECHO. To my surprise, what I get is IAC DO ECHO, IAC WON'T ECHO, IAC DON'T ECHO. Three messages one by one. And the client is still echoing by itself.

What am I doing wrong? What do those three messages mean?

int main() {
    TcpListener tcpListener(10001);  // custom tcp helper library
    auto stream = tcpListener.acceptClient();
    vector<uint8_t> msg = {255, 251, 1}; // send IAC WILL ECHO on start
    stream.writeBytes(msg);
    auto message = stream.readBytes(100);
    while (!message.empty()) {
        for (auto c : message) cout << (int)c << endl; // to see what i'm getting from client
        cout << "length: " << message.size() << "\n";
        stream.writeBytes(message); // echo back
        message = stream.readBytes(100);
    }
    return 0;
}

回答1:


I think my mistake can be now seen in my code, but I worked on some more complicated version of it. The problem is I echoed all messages from client, so when I sent IAC WILL ECHO it responded with IAC DO ECHO. When I echoed it client said it won't do it and then sent IAC DON'T ECHO (to clear the situation I think). So of course to avoid such errors first thing in telnet server is to properly handle negotation.



来源:https://stackoverflow.com/questions/49924382/negotiating-echo-with-telnet-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!