Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: $ENV{TERM} and Net::Telnet

by Fastolfe (Vicar)
on Jun 12, 2002 at 02:57 UTC ( #173720=note: print w/replies, xml ) Need Help??

in reply to $ENV{TERM} and Net::Telnet

I don't believe Net::Telnet does terminal type option negotiation. As a result, setting this environment variable probably isn't having any effect.

To see the types of option negotiation performed with your stock 'telnet' application, use the "toggle options" command:

$ telnet telnet> toggle options Will show option processing. telnet> open ...
You should then get a bunch of diagnostic output showing the telnet options being passed back and forth, and among those should be options specifying a willingness to negotiate terminal type and the request and reply with the actual information.

Your job, should you choose to really need it, would be to get your Net::Telnet object to send these options when you make your connection, probably through callbacks and the like. Looking at documentation for the module, the 'option_send' function should start you on the track, but it doesn't look like it's implemented. You've gotta let the other end know you're willing to do terminal type negotiation, and presumably then you could use the option_callback function to respond to a request for the terminal type. :/

Replies are listed 'Best First'.
Re: Re: $ENV{TERM} and Net::Telnet
by bbutler (Initiate) on Jun 12, 2002 at 18:12 UTC
    this was the key. thanks much, fastolfe!

    the solution by mr. muskrat was interesting, but really not the right way to go about this. thanks to him also though.

    the reply by abigail is not right - Net::Telnet *does* correctly implement the telnet protocol, and establishes the connection in the proper way.

    i was under the impression that the terminal type was always negotiated in a telnet session, but this is not the case. it turns out in my particular application, the remote client asks for the terminal type, but that particular negotiation is *not* enabled by default, so the local side was rejecting the request. i figured this out by doing a $connection->option_log('option.log'); statement (equivalently, i could have included the option in the object creation, but i like to keep them separate - makes it easier to comment them out as i go). so, i had to figure out how to make the local side not only accept a request for the terminal type, but then to send it back to the remote client. this is not trivial. fortunately, i found some help on the web at: which shows how to do it.

    note that this takes advantage of a completely undocumented part of Net::Telnet (suboption_callback), and if i had not found this example on the web, i would have been pulling my hair out for days trying to figure it out. so, here is the modified code, which works perfectly:

    #!/usr/local/bin/perl use Net::Telnet qw (TELOPT_TTYPE); $termtype = 'no-resize-vt100'; $telopt_ttype_ok = ''; $connection = new Net::Telnet ( Host=>'', Port=>6775 ); $connection->option_callback(\&opt_callback); $connection->option_accept(Do=>TELOPT_TTYPE); $connection->suboption_callback(\&subopt_callback); $connection->open(); $connection->waitfor('/Horizons> /'); $connection->print('load vla-1'); $connection->waitfor('/Horizons> /'); $connection->print('page'); $connection->waitfor('/Horizons> /'); $connection->print('799'); $connection->waitfor('/.*Select.*: $/'); $connection->print('e'); $connection->waitfor('/.*Observe.*: $/'); $connection->print('o'); $connection->waitfor('/.*Coordinate.*: $/'); $connection->print('-5@399'); $connection->waitfor('/.*Starting.*: $/'); $connection->print('1981-Mar-07 08:00'); $connection->waitfor('/.*Ending.*: $/'); $connection->print('1981-Mar-07 17:00'); $connection->waitfor('/.*interval.*: $/'); $connection->print('10m'); $connection->waitfor('/.*Accept.*: $/'); $connection->print('y'); $connection->input_log('horizons.ephem.log'); $connection->waitfor('/.*Select.*: $/'); $connection->input_log(''); $connection->print('q'); $connection->close; exit 0; sub opt_callback { my ($obj, $option, $is_remote, $is_enabled, $was_enabled, $buf_positi +on) = @_; if ($option == TELOPT_TTYPE and $is_enabled and !$is_remote) { $telopt_ttype_ok = 1; } 1; } sub subopt_callback { my ($obj, $option, $parameters) = @_; my $ors_old; if ($option == TELOPT_TTYPE) { $ors_old = $obj->output_record_separator(""); $obj->print("\xff\xfa", pack("CC", $option, 0), $termtype, "\xff\xf0 +"); $obj->output_record_separator($ors_old); } 1; }
    thanks again to fastolfe for pointing me in the right direction!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://173720]
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2017-05-01 05:29 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (544 votes). Check out past polls.