2 * TNET A server program for MINIX which implements the TCP/IP
3 * suite of networking protocols. It is based on the
4 * TCP/IP code written by Phil Karn et al, as found in
5 * his NET package for Packet Radio communications.
7 * This module handles telnet option processing.
9 * Author: Michael Temari, <temari@temari.ae.ge.com> 01/13/93
12 #include <sys/types.h>
21 #include <sys/ioctl.h>
30 static void dowill(int c
);
31 static void dowont(int c
);
32 static void dodo(int c
);
33 static void dodont(int c
);
34 static void respond(int ack
, int option
);
35 static void respond_really(int ack
, int option
);
37 #define LASTTELOPT TELOPT_SGA
39 static int r_winch
= 0;
41 static int TelROpts
[LASTTELOPT
+1];
42 static int TelLOpts
[LASTTELOPT
+1];
50 for(i
= 0; i
<= LASTTELOPT
; i
++) {
56 void telopt(fdout
, what
, option
)
71 if(option
<= LASTTELOPT
) {
74 } else if(option
== TELOPT_WINCH
&& !r_winch
) { r_winch
= 1; len
= 3; }
77 if(option
<= LASTTELOPT
) {
83 if(option
<= LASTTELOPT
) {
89 if(option
<= LASTTELOPT
) {
96 (void) write(fdout
, buf
, len
);
99 int set_winsize(int fd
, unsigned int cols
, unsigned int rows
)
102 memset(&w
, 0, sizeof(w
));
105 ioctl(fd
, TIOCSWINSZ
, (char *) &w
);
108 int tel_in(fdout
, telout
, buffer
, len
)
114 static int InState
= IN_DATA
;
115 static int ThisOpt
= 0;
126 c
= (unsigned char)*p
++; len
--;
130 if(c
== 0 || c
== '\n')
139 if(c
== '\r') InState
= IN_CR
;
174 write(fdout
, buffer
, size
);
180 case WILL
: dowill(c
); break;
181 case WONT
: dowont(c
); break;
182 case DO
: dodo(c
); break;
183 case DONT
: dodont(c
); break;
188 static int winchpos
= -1;
189 /* Subnegotiation. */
191 static unsigned int winchbuf
[5], iacs
= 0;
192 winchbuf
[winchpos
] = c
;
193 /* IAC is escaped - unescape it. */
194 if(c
== IAC
) iacs
++; else { iacs
= 0; winchpos
++; }
195 if(iacs
== 2) { winchpos
++; iacs
= 0; }
197 /* End of WINCH data. */
199 (winchbuf
[0] << 8) | winchbuf
[1],
200 (winchbuf
[2] << 8) | winchbuf
[3]);
204 static int lastiac
= 0;
207 /* Start listening. */
211 if(lastiac
) InState
= IN_DATA
;
216 if(c
== IAC
) lastiac
= 1;
227 write(fdout
, buffer
, size
);
230 int tel_out(fdout
, buf
, size
)
242 if((p
= (char *)memchr(buf
, IAC
, size
)) != (char *)NULL
) {
249 (void) write(fdout
, buf
, len
);
251 (void) write(fdout
, p
- 1, 1);
256 static void dowill(c
)
274 respond_really(ack
, c
);
283 static void dowont(c
)
286 if(c
<= LASTTELOPT
) {
306 static void dodont(c
)
309 if(c
<= LASTTELOPT
) {
317 static void respond(ack
, option
)
325 /* write(telfdout, c, 3); */
328 static void respond_really(ack
, option
)
336 write(telfdout
, c
, 3);