|
Home > Archive > Unix Programming > July 2007 > funky TCP problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
funky TCP problems
|
|
| grocery_stocker 2007-07-22, 7:17 pm |
| Given the following
#!/usr/bin/perl -w
use IO::Socket;
my($handle, $line, $kidpid);
$handle =3D IO::Socket::INET->new(
PeerAddr =3D>"137.104.128.2",
PeerPort =3D>"23",
Proto=3D>"tcp",
)
or die "cant connect to port: $!";
$handle->autoflush(1);
print STDERR "[Connected]\n";
die "can't fork: $!" unless defined($kidpid =3D fork());
if($kidpid) {
while(defined($line =3D <$handle> )){
print STDOUT $line;
}
kill("TERM", $kidpid);
}
else {
while(defined ($line =3D <STDIN> )){
print $handle $line;
}
}
When I run it, I get
[cdalten@localhost]$ ./foo.pl
[Connected]
now, when I hit the 'enter' key on my keyboard, I get
?????
University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
Then after a few seconds, I get
Username:
Error reading command input
However, what I really want to see is
Trying 137.104.128.2...
Connected to uwplatt.edu (137.104.128.2).
Escape character is '^]'.
University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
Username:
What's my error in logic?
| |
| Sherm Pendley 2007-07-22, 7:17 pm |
| grocery_stocker <cdalten@gmail.com> writes:
> now, when I hit the 'enter' key on my keyboard, I get
> ?????
>
>
> university of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Then after a few seconds, I get
> Username:
> Error reading command input
>
>
> However, what I really want to see is
> Trying 137.104.128.2...
> Connected to uwplatt.edu (137.104.128.2).
> Escape character is '^]'.
>
>
>
> university of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Username:
>
>
>
> What's my error in logic?
You're simply connecting to a socket and printing what you get back.
The problem is that terminal emulation is not that simple; there are
also control sequences that your app must act upon instead of simply
printing them.
You might want to have a look at the Term::VT102 module on CPAN.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
| |
| Alan Curry 2007-07-23, 7:22 am |
| In article <1185145624.206414.244940@d30g2000prg.googlegroups.com>,
grocery_stocker <cdalten@gmail.com> wrote:
>
>However, what I really want to see is
>Trying 137.104.128.2...
>Connected to uwplatt.edu (137.104.128.2).
>Escape character is '^]'.
The above three lines would normally be printed by the telnet client reporting
on its progress. If you're trying to make a PERL script that behaves exactly
like /usr/bin/telnet, you'll have to print those lines yourself. (Not to
mention the actual handling of the ^] escape)
>
> What's my error in logic?
The basic error is thinking that telnet is a raw TCP stream. It's not. When
you connect to the telnet server, the first few bytes you get are telnet
option negotiation. See RFC854 for the specification, and the Net::Telnet
module for a perly way to deal with that option negoation.
People often use the telnet client to speak to non-telnet servers like FTP or
SMTP, which works because the client doesn't attempt any option negotiation
unless you ask it to. Even here, though, it's not acting as a raw TCP
pass-through. It's adding carriage returns (which happens to be the right
thing for FTP and SMTP and several others) and mangling 0xFF bytes.
--
Alan Curry
pacman@world.std.com
|
|
|
|
|