Solved

How to open a telnet session using C?

Posted on 2003-11-12
11
326 Views
Last Modified: 2008-02-26
In Perl, I learned to use the Net::Telnet module. It includes the following commands: login, waitfor, print cmd, close.

Is there a telnet library in C with the equivalent commands? How do I use them?
0
Comment
Question by:elvin226
  • 4
  • 3
  • 2
11 Comments
 
LVL 8

Expert Comment

by:ssnkumar
ID: 9737536
For doing this in C, you will have to write your own code using socket programming.
The commands you will be using are socket(), bind(), listen(), accept(), send() and receive().
So, the first thing is to learn socket programming!:-)
But, both windows and Unix provide telnet program. Why don't you use this itself!?

In C, you can call telnet using the following statement: system("telnet ip_addr");
Or you can use exec() to do the same.

Hope I answered your question....
0
 
LVL 8

Assisted Solution

by:ssnkumar
ssnkumar earned 150 total points
ID: 9737563
For doing this in C, you will have to write your own code using socket programming.
The commands you will be using are socket(), bind(), listen(), accept(), send() and receive().
So, the first thing is to learn socket programming!:-)
But, both windows and Unix provide telnet program. Why don't you use this itself!?

In C, you can call telnet using the following statement: system("telnet ip_addr");
Or you can use exec() to do the same.

Hope I answered your question....
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 150 total points
ID: 9737564
A seesion can be initiated with
system ( "telnet ... ");
or by
fork()
followed by exec()....

for full library, have a look at TCPware
http://vms.process.com/ftp/tcpware/documentation/html/programmer/httoc.htm
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:elvin226
ID: 9745069
What I'm trying to do is an automated telnet script, not interactive, so I can't use system("telnet"). The program will be the one to send messages, not the user, and it has to wait for the remote machine's response before sending another message.
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 9745116
If you want a interactive telnet session, then you will have to write the complete program!
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9745364
download the telent library ... it provides the API do the work ...
If you wish to do it with script, then use expect
http://expect.nist.gov/

using them, you wont have to write the whle code
0
 

Author Comment

by:elvin226
ID: 9745452
sunnycoder,

what I'm asking for is the C library for telnet and examples of how to use it's functions...if there exists one.

I've already done it with Perl, now I want to learn how to do it in C.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9745583
take a look at any telent client coded in C
http://www.sofotex.com/download/Networking/Telnet/more3.html
http://linux.tucows.com/preview/220521.html
http://www.ararat.cz/synapse/

you would be having one with your own linux distribution too !!! tucows site has lots of clients ... search it for more info
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 10400537
I too deserve points!:-))

-ssnkumar
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question