tags:

views:

780

answers:

6
+3  Q: 

Telnet Server

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.

+9  A: 

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

Mitch Haile
Just echoing the bytes is very very far from what a telnet server does...
bortzmeyer
The question sounds like homework. He got an answer that is suitable for homework. What did you want to add?
Mitch Haile
+2  A: 

If you need help with socket programming etc.

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

argonide
+2  A: 

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.

qrdl
A: 

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;
}
+2  A: 

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

Alnitak
A: 

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.

ShaChris23