Telnet Server

2019-02-17 23:17发布

I would like to implement a telnet server in C. How would I proceed with this? Which RFCs should I look at? This is important to me, and I would appreciate any help.

标签: c telnet
6条回答
\"骚年 ilove
2楼-- · 2019-02-17 23:28

Note that real telnet is not just a simple interface that handles the stdin and stdout of the user's login shell.

There's lots of additional functionality that is carried separately in 'options', which handle such things as setting the $TERM environment variable, setting the rows/columns (and resetting them if the user resizes their terminal).

If you are looking to do real telnet, and not just a simple TCP server, then indeed RFC 854 is your starting point. However there's stacks more relevant RFCs which describe those options mentioned above which are listed at http://en.wikipedia.org/wiki/Telnet

查看更多
姐就是有狂的资本
3楼-- · 2019-02-17 23:29

For very basic telnet (just telnet to a port and echo bytes), there's not much to do. Read from a socket, process it (in an echo server, do nothing), spit back a result. You could implement a simple MUD-style server without knowing anything in any RFCs.

But if you're really concerned about RFCs, RFC 854 might be a starting point.

http://www.faqs.org/rfcs/rfc854.html

查看更多
欢心
4楼-- · 2019-02-17 23:31

If you are serious about network programming I would highly recommend Richard W. Stevens' "UNIX Network Programming Vol 1" - it's much better reading than RFCs with great examples.

It is very expensive book but there are cheap paperback edition available on eBay. Even if you get expensive hard-cover edition it worth every penny you paid.

查看更多
The star\"
5楼-- · 2019-02-17 23:38

Knowing how the socket API works internally is very useful, because it is often exported with very minor changes by higher level languages.

That said, you might want to use the event loop support provided by GLib and use the related networking library GNet.

Here's how to use GNet to open a socket on port 4000, then close every connection made to it. There is a little bit of magic here as the server registers itself with the default main context as part of its creation.

#include <glib.h>
#include <gnet.h>

void client_connect(GServer G_GNUC_UNUSED *server, GConn *conn, gpointer G_GNUC_UNUSED user_data){
  g_print("Connection from %s\n", conn->hostname);
  gnet_conn_disconnect(conn);
  gnet_conn_unref(conn); conn = NULL;
}

int main(void){
  GMainLoop *loop = g_main_loop_new(NULL, FALSE);
  GServer *server;
  gnet_init();
  server = gnet_server_new(NULL, 4000, client_connect, NULL);
  g_main_loop_run(loop);
  g_main_loop_unref(loop); loop = NULL;
  return 0;
}
查看更多
做个烂人
6楼-- · 2019-02-17 23:45

If you need help with socket programming etc.

checkout beej's guide: http://beej.us/guide/bgnet/

查看更多
我只想做你的唯一
7楼-- · 2019-02-17 23:48

I recommend installing Wireshark to watch the Telnet traffic using an existing Telnet server. Then looking at the log, you can gain a better understanding of how the server communicates with the client. Then, use the RFC as a reference if you don't understand any of the commands going across the wire.

查看更多
登录 后发表回答