Nuno Carvalho wrote:

>  Still talking about socket programming ...

This isn't strictly socket programming, as the same principles apply
to any kind of terminal access.

>  I have a a file called menu and it has the following lines:
>  
> ---------cut here----------------
> -----------------------------------------
>             \e[4mW E L C O M E \e[m
> \e[1m BBS @ DEI\e[m (Bulletin Board System)
> -----------------------------------------
> --------cut here ----------------

This is the wrong thing to do. The `\e[4m' sequence corresponds to
`enter underline mode' for an ANSI terminal. On other types of
terminal it may do something completely different. The same applies to
`\e[1m' (bold).

If you wish to use underlining, look up the sequence corresponding to
the `enter_underline_mode' entry (`smul' capability) in the terminfo
database, and use that (if it is defined).

>  This file is sent through client descriptor without problems, I think!
>  My "problem" is:
>  
>   When I get a connetion to my server on a tty console(not in X) I get
> the text is selected as with bold characters! ;)

Some terminals may adopt a different interpretation of particular
escape sequences (e.g. if the terminal doesn't support underlining, it
may use bold type or colour instead).

>   If I get a connection but on X on a rxvt session i see all the text
> with escape codes ! :(

Odd. `infocmp rxvt' indicates that the rxvt terminal type uses `\e[4m'
for underline.

>   Both sessions(on console as well rxvt) have TERM variable as vt100 !
>   If I run a xterm session output it will look really as I want (with bold
> and underline) - on that TERM=xterm-debian! 

The TERM variable is irrelevant unless you actually use it to
determine which escape sequences to send. Even then, you can't
guarantee that the terminal will accurately emulate the type of
terminal which it claims to emulate.

>   How can I protect users from this situation - if they don't support
> "bold", "underline", etc don't let them see escape codes ?

Use terminfo.

>  I tried to detect ENVIRONMENT variable on remote machine like:
> 
> ------ cut here --------- 
> buffer[0] = IAC ;
> buffer[1] = DO ; 
> buffer[2] = TELOPT_TTYPE ;
> write(client_fd, buffer, 3);
> 
> /* Sub negotiation */
> buffer[0] = IAC ;
> buffer[1] = SB ;             /* Begin subnegotiation */
> buffer[2] = TELOPT_TTYPE ;
> buffer[3] = TELQUAL_SEND ;
> buffer[4] = IAC ;
> buffer[5] = SE ;             /* End subnegotiation */
> write(client_fd, buffer, 6);
> leu=read(client_fd, buffer, 48);
> buffer[leu]='\0' ;
> --------cut here-----------------

Why are you trying to implement the telnet protocol yourself? Wouldn't
it be easier to just have telnetd invoke your program as the login
shell?

>  But I get on buffer's variable, 6 strange characters !
>  It should return a string, I think!

The terminal type option should be sent by the client to the server.
If you are going to implement the telnet protocol yourself, you need
to:

1. Watch for the terminal sending `WILL TERMINAL-TYPE'.
2. Reply with `DO TERMINAL-TYPE'.
3. Send `SB TERMINAL-TYPE SEND'.
4. Watch for `SB TERMINAL-TYPE IS ...'.
5. Store the terminal type which the terminal sends.

If the client never sends either of the `WILL TERMINAL-TYPE' or
`SB TERMINAL-TYPE IS ...' sequences, you need to assume that it is a
dumb terminal, and not send any escape sequences.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to