[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-net
Subject:    Re: telnet programming: CAI IP does NOT stop telnet???
From:       <quix.robins.af.mil!msmith () yggdrasil ! com>
Date:       1997-03-27 14:53:59
[Download RAW message or body]

> I am trying to make a programm that checks TCP ports. It works fine, except 
> for the telnet port, where it produces an error message on the daemon side.

When you say "alive" is the connect success not good enough to determine?
 
> The messages are like:
> telnetd[944]:ttloop: peer died: No such file or directory
> telnetd[944]:ttloop: peer died: Try again
> telnetd[944]:ttloop: read: Broken pipe
> 
> What I want to do is do a connect() to the port and close it as soon as 
> possible. I just want to know whether it is alive. I tried several ways:
> 
> 1) according to RFC854 I should do an IAC IP (255,244), or perhaps first 
> answer the incoming IAC DO with an IAC WON'T, but neither gives the correct 
> result
> 
> 2) tracing the existing telnet gives just a shutdown(sock, 2) and a close(), 
> but that doesn't do the trick either.
> 
> Has anybody any experience with programming telnet? Can you please give me 
> some advise?

Yes, telnetd will init the conversation if you don't first, usually.
Just try reading 1 byte from the stream and see if it is IAC. If so,
you are connected. Here is a typical telnetd <-> client initialization
which the client writes data first. The negotiation is sort of a
state machine, you have to keep up with what the client said he WILL
or WONT do, and if client doesn't respond with a WONT, maybe assume WILL.
etc., etc., etc. Not an expert here.

Connect
telnet client writes
               (IAC)(DO)(SGA)
               (IAC)(WILL)(TTYPE)
               .....
 
telnetd writes (IAC)(DO)(TTYPE)
               (IAC)(DO)(TSPEED)
               (IAC)(DO)(XDISPLOC) 
               (IAC)(DO)(NEW_ENVIRON)
               (IAC)(DO)(OLD_ENVIRON)

telnet client writes
               (IAC)(WONT)(NEW_ENVIRON)

...

> Any help is much appreciated, please include me an email if you respond in 
> this newsgroup.

I connect, read 1 byte or send something like IAC DO SGA and read 1 byte
and see if it is IAC. That should be enough.

I've written a little plug transparent proxy for debugging protocols,
if you want it I'd be happy to put it up on the Web.

To debug the telnet protocol, you probably need two machines, or
run your telnetd on a high port and run the plug on 23, because
telnet client assumes and tries some things when it connects to
port 23 that it wouldn't otherwise. Example, edit your inetd.conf
and put telnetd on port 1234, then run plug on 23

   23 <-> plug <-> 1234
           |
          log file dump

Hope that helps,

---
	Melvin Smith
	msmith@quix.robins.af.mil

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic