I'm new to C/C++ and i'm looking for some good examples on interactive telnet code. Can somebody point me in the right direction to good real-world examples.
I'm coming from a Perl/Expect background way of doing things, however I want to write something in C/C++ so I can interact through telnet to a Cisco router and perform a series of commands etc.
Some advise too if you don't mind. From my Googling I've seemed to notice C/C++ programmers tend to like re-creating the wheel so to speak when coming to such types of programs, so they tend to build raw sockets etc to do this. Am I right in being lead to believe this? Isn't their an easier way like with Perl to include a module like NET::TELNET and just pass arguments through to the module that has been pre-written. I'm sure there must be something but I think for the most part I may not being searching for the right terms to pull good results.
I guess in a nutshell I'm probably being lazy and I'm looking for some sort of good practical code example. Some of the C books I'm reading are good to get into the language however I don't seem to see many books on the networking side. Now before you mention D. Comer and Stevens books etc which I do know of I'm talking about books that deal with network applications through examples, not the setting up a basic tcp/upd server daemon type. There seem to be plenty of other books on various other topics except when it comes to networking.
Anyway may be a bit short-sighted at the moment into this but I'm yearning for some direction and answers. I hope someone can help.
Is this code supposed to do something that your standard run-of-the-mill telnet client can't do? If you're not out to learn exactly how this works (i.e. re-inventing the wheel) then I don't understand why you don't just use a telnet client that already exists.
Ok I don't think I came across clearly.
I don't want to write a telnet client. I want to write a program that can use telnet to connect to a router. Then once it has connected to the router performing an expect-like sequence to login, then send various commands to be performed by the router.
This is so I can automate certain tasks on the router.
In Perl one can use the NET::TELNET module which saves you from writing all the necessary telnet code, and then you can use expect to perform the automated command sending. Now i'd like to do the same in C/C++ but just need some examples on this or a point in the right direction.
Hope this is a bit clearer.
First you will need to understand socket programming to make the connection to the telnet server. Then read the telnet rfc (http://www.faqs.org/rfcs/rfc854.html) to see how the telnet protocol works.
Basically your program is going to connect to the server then do protocol negotiations and then in a loop get any output from the server and send anything that needs to be sent untill the program or server closes the connection or the connection is broken.
And to simulate "expect", you will need at least two threads, a reader and a writer, maybe more. This is a bit of a rough project for a first shot at C.