• C

Running Telnet from C

I'm writing an application where I need to execute telnet to connect to an IP address on a specific port.  Once connected, I can transmit some strings through telnet and store the responses.  I was curious how to handle this.  I might not even need to use telnet, I might just be able to open a socket, but I've been unable to find details on how to do this.  I'm writing in C though I'm naturally a PHP programmer, so this is a bit new to me.  Any detailed help would be greatly appreciated.  Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes, to write a telnet client you basically need to open a socket to the server, on port 21. However, you must be able to handle the specific responses that you receive from the server.

Here some examples on how to write a simple client server program:

However, writing the actual telnet client is much more difficult, you need to know a little bit about the telnet protocol in order to correctly login to the server. Have a look at this:


But there are alot of telnet clients already written for various platforms, and some of them are open source. You could learn quite a bit by looking at their code. PuTtY is one of the more well known ones:


Hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This is a lot harder than you might think.      The Telnet protocol requires some initial handshaking.  Unfortunately the handshaking protocol is really really really broken.  The intial design was full of bad things like race conditions and undefined conditions.   Some of the updates in the later RFC's try to point this out, but they don't provide solutions.    Many people have spent months debugging this initial handshaking business.

IMHO It's best to go with some already debugged code, tested on many Telnet servers.  

You can use libcurl library. This library is very easy to use. I have used it couple of times to implement different clients (not telnet though!!).

   You can download it from http://sourceforge.net/projects/curl/

Are points going to be distributed for this question??
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.