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.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Note that real telnet is not just a simple interface that handles the
stdin
andstdout
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
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
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.
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.
If you need help with socket programming etc.
checkout beej's guide: http://beej.us/guide/bgnet/
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.