Solved

How to open a telnet session using C?

Posted on 2003-11-12
11
319 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:elvin226
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

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

Expert Comment

by:sunnycoder
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I too deserve points!:-))

-ssnkumar
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
FILE closing 11 68
jquery/ajax to code behind 7 156
C dll call freezes 5 88
Handling string inputs in C/Linux 23 167
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
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.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now