utility.c revision 1.8 1 1.1 cgd /*
2 1.5 cgd * Copyright (c) 1989, 1993
3 1.5 cgd * The Regents of the University of California. All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.8 jtk /* from: static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; */
36 1.8 jtk static char rcsid[] = "$NetBSD: utility.c,v 1.8 1996/02/24 01:22:28 jtk Exp $";
37 1.1 cgd #endif /* not lint */
38 1.1 cgd
39 1.6 cgd #include <sys/utsname.h>
40 1.1 cgd #define PRINTOPTIONS
41 1.1 cgd #include "telnetd.h"
42 1.1 cgd
43 1.1 cgd /*
44 1.1 cgd * utility functions performing io related tasks
45 1.1 cgd */
46 1.1 cgd
47 1.1 cgd /*
48 1.1 cgd * ttloop
49 1.1 cgd *
50 1.1 cgd * A small subroutine to flush the network output buffer, get some data
51 1.1 cgd * from the network, and pass it through the telnet state machine. We
52 1.1 cgd * also flush the pty input buffer (by dropping its data) if it becomes
53 1.1 cgd * too full.
54 1.1 cgd */
55 1.1 cgd
56 1.1 cgd void
57 1.1 cgd ttloop()
58 1.1 cgd {
59 1.1 cgd void netflush();
60 1.1 cgd
61 1.1 cgd DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop\r\n");
62 1.1 cgd nfrontp += strlen(nfrontp);});
63 1.1 cgd if (nfrontp-nbackp) {
64 1.1 cgd netflush();
65 1.1 cgd }
66 1.1 cgd ncc = read(net, netibuf, sizeof netibuf);
67 1.1 cgd if (ncc < 0) {
68 1.1 cgd syslog(LOG_INFO, "ttloop: read: %m\n");
69 1.1 cgd exit(1);
70 1.1 cgd } else if (ncc == 0) {
71 1.1 cgd syslog(LOG_INFO, "ttloop: peer died: %m\n");
72 1.1 cgd exit(1);
73 1.1 cgd }
74 1.1 cgd DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc);
75 1.1 cgd nfrontp += strlen(nfrontp);});
76 1.1 cgd netip = netibuf;
77 1.1 cgd telrcv(); /* state machine */
78 1.1 cgd if (ncc > 0) {
79 1.1 cgd pfrontp = pbackp = ptyobuf;
80 1.1 cgd telrcv();
81 1.1 cgd }
82 1.1 cgd } /* end of ttloop */
83 1.1 cgd
84 1.1 cgd /*
85 1.1 cgd * Check a descriptor to see if out of band data exists on it.
86 1.1 cgd */
87 1.1 cgd int
88 1.1 cgd stilloob(s)
89 1.1 cgd int s; /* socket number */
90 1.1 cgd {
91 1.1 cgd static struct timeval timeout = { 0 };
92 1.1 cgd fd_set excepts;
93 1.1 cgd int value;
94 1.1 cgd
95 1.1 cgd do {
96 1.1 cgd FD_ZERO(&excepts);
97 1.1 cgd FD_SET(s, &excepts);
98 1.1 cgd value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
99 1.1 cgd } while ((value == -1) && (errno == EINTR));
100 1.1 cgd
101 1.1 cgd if (value < 0) {
102 1.1 cgd fatalperror(pty, "select");
103 1.1 cgd }
104 1.1 cgd if (FD_ISSET(s, &excepts)) {
105 1.1 cgd return 1;
106 1.1 cgd } else {
107 1.1 cgd return 0;
108 1.1 cgd }
109 1.1 cgd }
110 1.1 cgd
111 1.1 cgd void
112 1.1 cgd ptyflush()
113 1.1 cgd {
114 1.1 cgd int n;
115 1.1 cgd
116 1.1 cgd if ((n = pfrontp - pbackp) > 0) {
117 1.1 cgd DIAG((TD_REPORT | TD_PTYDATA),
118 1.1 cgd { sprintf(nfrontp, "td: ptyflush %d chars\r\n", n);
119 1.1 cgd nfrontp += strlen(nfrontp); });
120 1.1 cgd DIAG(TD_PTYDATA, printdata("pd", pbackp, n));
121 1.1 cgd n = write(pty, pbackp, n);
122 1.1 cgd }
123 1.1 cgd if (n < 0) {
124 1.1 cgd if (errno == EWOULDBLOCK || errno == EINTR)
125 1.1 cgd return;
126 1.1 cgd cleanup(0);
127 1.1 cgd }
128 1.1 cgd pbackp += n;
129 1.1 cgd if (pbackp == pfrontp)
130 1.1 cgd pbackp = pfrontp = ptyobuf;
131 1.1 cgd }
132 1.1 cgd
133 1.1 cgd /*
134 1.1 cgd * nextitem()
135 1.1 cgd *
136 1.1 cgd * Return the address of the next "item" in the TELNET data
137 1.1 cgd * stream. This will be the address of the next character if
138 1.1 cgd * the current address is a user data character, or it will
139 1.1 cgd * be the address of the character following the TELNET command
140 1.1 cgd * if the current address is a TELNET IAC ("I Am a Command")
141 1.1 cgd * character.
142 1.1 cgd */
143 1.1 cgd char *
144 1.1 cgd nextitem(current)
145 1.1 cgd char *current;
146 1.1 cgd {
147 1.1 cgd if ((*current&0xff) != IAC) {
148 1.1 cgd return current+1;
149 1.1 cgd }
150 1.1 cgd switch (*(current+1)&0xff) {
151 1.1 cgd case DO:
152 1.1 cgd case DONT:
153 1.1 cgd case WILL:
154 1.1 cgd case WONT:
155 1.1 cgd return current+3;
156 1.1 cgd case SB: /* loop forever looking for the SE */
157 1.1 cgd {
158 1.1 cgd register char *look = current+2;
159 1.1 cgd
160 1.1 cgd for (;;) {
161 1.1 cgd if ((*look++&0xff) == IAC) {
162 1.1 cgd if ((*look++&0xff) == SE) {
163 1.1 cgd return look;
164 1.1 cgd }
165 1.1 cgd }
166 1.1 cgd }
167 1.1 cgd }
168 1.1 cgd default:
169 1.1 cgd return current+2;
170 1.1 cgd }
171 1.1 cgd } /* end of nextitem */
172 1.1 cgd
173 1.1 cgd
174 1.1 cgd /*
175 1.1 cgd * netclear()
176 1.1 cgd *
177 1.1 cgd * We are about to do a TELNET SYNCH operation. Clear
178 1.1 cgd * the path to the network.
179 1.1 cgd *
180 1.1 cgd * Things are a bit tricky since we may have sent the first
181 1.1 cgd * byte or so of a previous TELNET command into the network.
182 1.1 cgd * So, we have to scan the network buffer from the beginning
183 1.1 cgd * until we are up to where we want to be.
184 1.1 cgd *
185 1.1 cgd * A side effect of what we do, just to keep things
186 1.1 cgd * simple, is to clear the urgent data pointer. The principal
187 1.1 cgd * caller should be setting the urgent data pointer AFTER calling
188 1.1 cgd * us in any case.
189 1.1 cgd */
190 1.1 cgd void
191 1.1 cgd netclear()
192 1.1 cgd {
193 1.1 cgd register char *thisitem, *next;
194 1.1 cgd char *good;
195 1.1 cgd #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
196 1.1 cgd ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
197 1.1 cgd
198 1.1 cgd thisitem = netobuf;
199 1.1 cgd
200 1.1 cgd while ((next = nextitem(thisitem)) <= nbackp) {
201 1.1 cgd thisitem = next;
202 1.1 cgd }
203 1.1 cgd
204 1.1 cgd /* Now, thisitem is first before/at boundary. */
205 1.1 cgd
206 1.1 cgd good = netobuf; /* where the good bytes go */
207 1.1 cgd
208 1.1 cgd while (nfrontp > thisitem) {
209 1.1 cgd if (wewant(thisitem)) {
210 1.1 cgd int length;
211 1.1 cgd
212 1.1 cgd next = thisitem;
213 1.1 cgd do {
214 1.1 cgd next = nextitem(next);
215 1.1 cgd } while (wewant(next) && (nfrontp > next));
216 1.1 cgd length = next-thisitem;
217 1.8 jtk memmove(good, thisitem, length);
218 1.1 cgd good += length;
219 1.1 cgd thisitem = next;
220 1.1 cgd } else {
221 1.1 cgd thisitem = nextitem(thisitem);
222 1.1 cgd }
223 1.1 cgd }
224 1.1 cgd
225 1.1 cgd nbackp = netobuf;
226 1.1 cgd nfrontp = good; /* next byte to be sent */
227 1.1 cgd neturg = 0;
228 1.1 cgd } /* end of netclear */
229 1.1 cgd
230 1.1 cgd /*
231 1.1 cgd * netflush
232 1.1 cgd * Send as much data as possible to the network,
233 1.1 cgd * handling requests for urgent data.
234 1.1 cgd */
235 1.1 cgd void
236 1.1 cgd netflush()
237 1.1 cgd {
238 1.1 cgd int n;
239 1.1 cgd extern int not42;
240 1.1 cgd
241 1.1 cgd if ((n = nfrontp - nbackp) > 0) {
242 1.1 cgd DIAG(TD_REPORT,
243 1.1 cgd { sprintf(nfrontp, "td: netflush %d chars\r\n", n);
244 1.1 cgd n += strlen(nfrontp); /* get count first */
245 1.1 cgd nfrontp += strlen(nfrontp); /* then move pointer */
246 1.1 cgd });
247 1.1 cgd /*
248 1.1 cgd * if no urgent data, or if the other side appears to be an
249 1.1 cgd * old 4.2 client (and thus unable to survive TCP urgent data),
250 1.1 cgd * write the entire buffer in non-OOB mode.
251 1.1 cgd */
252 1.1 cgd if ((neturg == 0) || (not42 == 0)) {
253 1.1 cgd n = write(net, nbackp, n); /* normal write */
254 1.1 cgd } else {
255 1.1 cgd n = neturg - nbackp;
256 1.1 cgd /*
257 1.1 cgd * In 4.2 (and 4.3) systems, there is some question about
258 1.1 cgd * what byte in a sendOOB operation is the "OOB" data.
259 1.1 cgd * To make ourselves compatible, we only send ONE byte
260 1.1 cgd * out of band, the one WE THINK should be OOB (though
261 1.1 cgd * we really have more the TCP philosophy of urgent data
262 1.1 cgd * rather than the Unix philosophy of OOB data).
263 1.1 cgd */
264 1.1 cgd if (n > 1) {
265 1.1 cgd n = send(net, nbackp, n-1, 0); /* send URGENT all by itself */
266 1.1 cgd } else {
267 1.1 cgd n = send(net, nbackp, n, MSG_OOB); /* URGENT data */
268 1.1 cgd }
269 1.1 cgd }
270 1.1 cgd }
271 1.1 cgd if (n < 0) {
272 1.1 cgd if (errno == EWOULDBLOCK || errno == EINTR)
273 1.1 cgd return;
274 1.1 cgd cleanup(0);
275 1.1 cgd }
276 1.1 cgd nbackp += n;
277 1.1 cgd if (nbackp >= neturg) {
278 1.1 cgd neturg = 0;
279 1.1 cgd }
280 1.1 cgd if (nbackp == nfrontp) {
281 1.1 cgd nbackp = nfrontp = netobuf;
282 1.1 cgd }
283 1.1 cgd return;
284 1.1 cgd } /* end of netflush */
285 1.1 cgd
286 1.1 cgd
287 1.1 cgd /*
288 1.1 cgd * writenet
289 1.1 cgd *
290 1.1 cgd * Just a handy little function to write a bit of raw data to the net.
291 1.1 cgd * It will force a transmit of the buffer if necessary
292 1.1 cgd *
293 1.1 cgd * arguments
294 1.1 cgd * ptr - A pointer to a character string to write
295 1.1 cgd * len - How many bytes to write
296 1.1 cgd */
297 1.1 cgd void
298 1.1 cgd writenet(ptr, len)
299 1.1 cgd register unsigned char *ptr;
300 1.1 cgd register int len;
301 1.1 cgd {
302 1.1 cgd /* flush buffer if no room for new data) */
303 1.1 cgd if ((&netobuf[BUFSIZ] - nfrontp) < len) {
304 1.1 cgd /* if this fails, don't worry, buffer is a little big */
305 1.1 cgd netflush();
306 1.1 cgd }
307 1.1 cgd
308 1.8 jtk memmove(nfrontp, ptr, len);
309 1.1 cgd nfrontp += len;
310 1.1 cgd
311 1.1 cgd } /* end of writenet */
312 1.1 cgd
313 1.1 cgd
314 1.1 cgd /*
315 1.1 cgd * miscellaneous functions doing a variety of little jobs follow ...
316 1.1 cgd */
317 1.1 cgd
318 1.1 cgd
319 1.1 cgd void
320 1.1 cgd fatal(f, msg)
321 1.1 cgd int f;
322 1.1 cgd char *msg;
323 1.1 cgd {
324 1.1 cgd char buf[BUFSIZ];
325 1.1 cgd
326 1.1 cgd (void) sprintf(buf, "telnetd: %s.\r\n", msg);
327 1.1 cgd (void) write(f, buf, (int)strlen(buf));
328 1.1 cgd sleep(1); /*XXX*/
329 1.1 cgd exit(1);
330 1.1 cgd }
331 1.1 cgd
332 1.1 cgd void
333 1.1 cgd fatalperror(f, msg)
334 1.1 cgd int f;
335 1.1 cgd char *msg;
336 1.1 cgd {
337 1.1 cgd char buf[BUFSIZ], *strerror();
338 1.1 cgd
339 1.8 jtk (void) sprintf(buf, "%s: %s", msg, strerror(errno));
340 1.1 cgd fatal(f, buf);
341 1.1 cgd }
342 1.1 cgd
343 1.1 cgd char editedhost[32];
344 1.1 cgd
345 1.1 cgd void
346 1.1 cgd edithost(pat, host)
347 1.1 cgd register char *pat;
348 1.1 cgd register char *host;
349 1.1 cgd {
350 1.1 cgd register char *res = editedhost;
351 1.1 cgd char *strncpy();
352 1.1 cgd
353 1.1 cgd if (!pat)
354 1.1 cgd pat = "";
355 1.1 cgd while (*pat) {
356 1.1 cgd switch (*pat) {
357 1.1 cgd
358 1.1 cgd case '#':
359 1.1 cgd if (*host)
360 1.1 cgd host++;
361 1.1 cgd break;
362 1.1 cgd
363 1.1 cgd case '@':
364 1.1 cgd if (*host)
365 1.1 cgd *res++ = *host++;
366 1.1 cgd break;
367 1.1 cgd
368 1.1 cgd default:
369 1.1 cgd *res++ = *pat;
370 1.1 cgd break;
371 1.1 cgd }
372 1.1 cgd if (res == &editedhost[sizeof editedhost - 1]) {
373 1.1 cgd *res = '\0';
374 1.1 cgd return;
375 1.1 cgd }
376 1.1 cgd pat++;
377 1.1 cgd }
378 1.1 cgd if (*host)
379 1.1 cgd (void) strncpy(res, host,
380 1.1 cgd sizeof editedhost - (res - editedhost) -1);
381 1.1 cgd else
382 1.1 cgd *res = '\0';
383 1.1 cgd editedhost[sizeof editedhost - 1] = '\0';
384 1.1 cgd }
385 1.1 cgd
386 1.1 cgd static char *putlocation;
387 1.1 cgd
388 1.1 cgd void
389 1.1 cgd putstr(s)
390 1.1 cgd register char *s;
391 1.1 cgd {
392 1.1 cgd
393 1.1 cgd while (*s)
394 1.1 cgd putchr(*s++);
395 1.1 cgd }
396 1.1 cgd
397 1.1 cgd void
398 1.1 cgd putchr(cc)
399 1.1 cgd int cc;
400 1.1 cgd {
401 1.1 cgd *putlocation++ = cc;
402 1.1 cgd }
403 1.1 cgd
404 1.1 cgd /*
405 1.1 cgd * This is split on two lines so that SCCS will not see the M
406 1.1 cgd * between two % signs and expand it...
407 1.1 cgd */
408 1.1 cgd static char fmtstr[] = { "%l:%M\
409 1.8 jtk %p on %A, %d %B %Y" };
410 1.1 cgd
411 1.1 cgd void
412 1.1 cgd putf(cp, where)
413 1.1 cgd register char *cp;
414 1.1 cgd char *where;
415 1.1 cgd {
416 1.1 cgd char *slash;
417 1.1 cgd time_t t;
418 1.1 cgd char db[100];
419 1.6 cgd struct utsname utsinfo;
420 1.5 cgd #ifdef STREAMSPTY
421 1.8 jtk extern char *strchr();
422 1.5 cgd #else
423 1.8 jtk extern char *strrchr();
424 1.5 cgd #endif
425 1.1 cgd
426 1.6 cgd uname(&utsinfo);
427 1.6 cgd
428 1.1 cgd putlocation = where;
429 1.1 cgd
430 1.1 cgd while (*cp) {
431 1.1 cgd if (*cp != '%') {
432 1.1 cgd putchr(*cp++);
433 1.1 cgd continue;
434 1.1 cgd }
435 1.1 cgd switch (*++cp) {
436 1.1 cgd
437 1.1 cgd case 't':
438 1.5 cgd #ifdef STREAMSPTY
439 1.5 cgd /* names are like /dev/pts/2 -- we want pts/2 */
440 1.8 jtk slash = strchr(line+1, '/');
441 1.5 cgd #else
442 1.8 jtk slash = strrchr(line, '/');
443 1.5 cgd #endif
444 1.1 cgd if (slash == (char *) 0)
445 1.1 cgd putstr(line);
446 1.1 cgd else
447 1.1 cgd putstr(&slash[1]);
448 1.1 cgd break;
449 1.1 cgd
450 1.1 cgd case 'h':
451 1.1 cgd putstr(editedhost);
452 1.1 cgd break;
453 1.1 cgd
454 1.1 cgd case 'd':
455 1.1 cgd (void)time(&t);
456 1.1 cgd (void)strftime(db, sizeof(db), fmtstr, localtime(&t));
457 1.1 cgd putstr(db);
458 1.1 cgd break;
459 1.1 cgd
460 1.1 cgd case '%':
461 1.1 cgd putchr('%');
462 1.3 mycroft break;
463 1.6 cgd
464 1.6 cgd case 's':
465 1.6 cgd putstr(utsinfo.sysname);
466 1.6 cgd break;
467 1.6 cgd
468 1.6 cgd case 'm':
469 1.6 cgd putstr(utsinfo.machine);
470 1.6 cgd break;
471 1.6 cgd
472 1.6 cgd case 'r':
473 1.6 cgd putstr(utsinfo.release);
474 1.6 cgd break;
475 1.6 cgd
476 1.6 cgd case 'v':
477 1.6 cgd puts(utsinfo.version);
478 1.6 cgd break;
479 1.1 cgd }
480 1.1 cgd cp++;
481 1.1 cgd }
482 1.1 cgd }
483 1.1 cgd
484 1.1 cgd #ifdef DIAGNOSTICS
485 1.1 cgd /*
486 1.1 cgd * Print telnet options and commands in plain text, if possible.
487 1.1 cgd */
488 1.1 cgd void
489 1.1 cgd printoption(fmt, option)
490 1.1 cgd register char *fmt;
491 1.1 cgd register int option;
492 1.1 cgd {
493 1.1 cgd if (TELOPT_OK(option))
494 1.1 cgd sprintf(nfrontp, "%s %s\r\n", fmt, TELOPT(option));
495 1.1 cgd else if (TELCMD_OK(option))
496 1.1 cgd sprintf(nfrontp, "%s %s\r\n", fmt, TELCMD(option));
497 1.1 cgd else
498 1.1 cgd sprintf(nfrontp, "%s %d\r\n", fmt, option);
499 1.1 cgd nfrontp += strlen(nfrontp);
500 1.1 cgd return;
501 1.1 cgd }
502 1.1 cgd
503 1.1 cgd void
504 1.1 cgd printsub(direction, pointer, length)
505 1.1 cgd char direction; /* '<' or '>' */
506 1.1 cgd unsigned char *pointer; /* where suboption data sits */
507 1.1 cgd int length; /* length of suboption data */
508 1.1 cgd {
509 1.1 cgd register int i;
510 1.1 cgd char buf[512];
511 1.1 cgd
512 1.8 jtk if (!(diagnostic & TD_OPTIONS))
513 1.1 cgd return;
514 1.1 cgd
515 1.1 cgd if (direction) {
516 1.1 cgd sprintf(nfrontp, "td: %s suboption ",
517 1.1 cgd direction == '<' ? "recv" : "send");
518 1.1 cgd nfrontp += strlen(nfrontp);
519 1.1 cgd if (length >= 3) {
520 1.1 cgd register int j;
521 1.1 cgd
522 1.1 cgd i = pointer[length-2];
523 1.1 cgd j = pointer[length-1];
524 1.1 cgd
525 1.1 cgd if (i != IAC || j != SE) {
526 1.1 cgd sprintf(nfrontp, "(terminated by ");
527 1.1 cgd nfrontp += strlen(nfrontp);
528 1.1 cgd if (TELOPT_OK(i))
529 1.1 cgd sprintf(nfrontp, "%s ", TELOPT(i));
530 1.1 cgd else if (TELCMD_OK(i))
531 1.1 cgd sprintf(nfrontp, "%s ", TELCMD(i));
532 1.1 cgd else
533 1.1 cgd sprintf(nfrontp, "%d ", i);
534 1.1 cgd nfrontp += strlen(nfrontp);
535 1.1 cgd if (TELOPT_OK(j))
536 1.1 cgd sprintf(nfrontp, "%s", TELOPT(j));
537 1.1 cgd else if (TELCMD_OK(j))
538 1.1 cgd sprintf(nfrontp, "%s", TELCMD(j));
539 1.1 cgd else
540 1.1 cgd sprintf(nfrontp, "%d", j);
541 1.1 cgd nfrontp += strlen(nfrontp);
542 1.1 cgd sprintf(nfrontp, ", not IAC SE!) ");
543 1.1 cgd nfrontp += strlen(nfrontp);
544 1.1 cgd }
545 1.1 cgd }
546 1.1 cgd length -= 2;
547 1.1 cgd }
548 1.1 cgd if (length < 1) {
549 1.5 cgd sprintf(nfrontp, "(Empty suboption??\?)");
550 1.1 cgd nfrontp += strlen(nfrontp);
551 1.1 cgd return;
552 1.1 cgd }
553 1.1 cgd switch (pointer[0]) {
554 1.1 cgd case TELOPT_TTYPE:
555 1.1 cgd sprintf(nfrontp, "TERMINAL-TYPE ");
556 1.1 cgd nfrontp += strlen(nfrontp);
557 1.1 cgd switch (pointer[1]) {
558 1.1 cgd case TELQUAL_IS:
559 1.1 cgd sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2);
560 1.1 cgd break;
561 1.1 cgd case TELQUAL_SEND:
562 1.1 cgd sprintf(nfrontp, "SEND");
563 1.1 cgd break;
564 1.1 cgd default:
565 1.1 cgd sprintf(nfrontp,
566 1.1 cgd "- unknown qualifier %d (0x%x).",
567 1.1 cgd pointer[1], pointer[1]);
568 1.1 cgd }
569 1.1 cgd nfrontp += strlen(nfrontp);
570 1.1 cgd break;
571 1.1 cgd case TELOPT_TSPEED:
572 1.1 cgd sprintf(nfrontp, "TERMINAL-SPEED");
573 1.1 cgd nfrontp += strlen(nfrontp);
574 1.1 cgd if (length < 2) {
575 1.5 cgd sprintf(nfrontp, " (empty suboption??\?)");
576 1.1 cgd nfrontp += strlen(nfrontp);
577 1.1 cgd break;
578 1.1 cgd }
579 1.1 cgd switch (pointer[1]) {
580 1.1 cgd case TELQUAL_IS:
581 1.1 cgd sprintf(nfrontp, " IS %.*s", length-2, (char *)pointer+2);
582 1.1 cgd nfrontp += strlen(nfrontp);
583 1.1 cgd break;
584 1.1 cgd default:
585 1.1 cgd if (pointer[1] == 1)
586 1.1 cgd sprintf(nfrontp, " SEND");
587 1.1 cgd else
588 1.1 cgd sprintf(nfrontp, " %d (unknown)", pointer[1]);
589 1.1 cgd nfrontp += strlen(nfrontp);
590 1.1 cgd for (i = 2; i < length; i++) {
591 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
592 1.1 cgd nfrontp += strlen(nfrontp);
593 1.1 cgd }
594 1.1 cgd break;
595 1.1 cgd }
596 1.1 cgd break;
597 1.1 cgd
598 1.1 cgd case TELOPT_LFLOW:
599 1.1 cgd sprintf(nfrontp, "TOGGLE-FLOW-CONTROL");
600 1.1 cgd nfrontp += strlen(nfrontp);
601 1.1 cgd if (length < 2) {
602 1.5 cgd sprintf(nfrontp, " (empty suboption??\?)");
603 1.1 cgd nfrontp += strlen(nfrontp);
604 1.1 cgd break;
605 1.1 cgd }
606 1.1 cgd switch (pointer[1]) {
607 1.5 cgd case LFLOW_OFF:
608 1.1 cgd sprintf(nfrontp, " OFF"); break;
609 1.5 cgd case LFLOW_ON:
610 1.1 cgd sprintf(nfrontp, " ON"); break;
611 1.5 cgd case LFLOW_RESTART_ANY:
612 1.5 cgd sprintf(nfrontp, " RESTART-ANY"); break;
613 1.5 cgd case LFLOW_RESTART_XON:
614 1.5 cgd sprintf(nfrontp, " RESTART-XON"); break;
615 1.1 cgd default:
616 1.1 cgd sprintf(nfrontp, " %d (unknown)", pointer[1]);
617 1.1 cgd }
618 1.1 cgd nfrontp += strlen(nfrontp);
619 1.1 cgd for (i = 2; i < length; i++) {
620 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
621 1.1 cgd nfrontp += strlen(nfrontp);
622 1.1 cgd }
623 1.1 cgd break;
624 1.1 cgd
625 1.1 cgd case TELOPT_NAWS:
626 1.1 cgd sprintf(nfrontp, "NAWS");
627 1.1 cgd nfrontp += strlen(nfrontp);
628 1.1 cgd if (length < 2) {
629 1.5 cgd sprintf(nfrontp, " (empty suboption??\?)");
630 1.1 cgd nfrontp += strlen(nfrontp);
631 1.1 cgd break;
632 1.1 cgd }
633 1.1 cgd if (length == 2) {
634 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[1]);
635 1.1 cgd nfrontp += strlen(nfrontp);
636 1.1 cgd break;
637 1.1 cgd }
638 1.1 cgd sprintf(nfrontp, " %d %d (%d)",
639 1.1 cgd pointer[1], pointer[2],
640 1.1 cgd (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
641 1.1 cgd nfrontp += strlen(nfrontp);
642 1.1 cgd if (length == 4) {
643 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[3]);
644 1.1 cgd nfrontp += strlen(nfrontp);
645 1.1 cgd break;
646 1.1 cgd }
647 1.1 cgd sprintf(nfrontp, " %d %d (%d)",
648 1.1 cgd pointer[3], pointer[4],
649 1.1 cgd (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
650 1.1 cgd nfrontp += strlen(nfrontp);
651 1.1 cgd for (i = 5; i < length; i++) {
652 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
653 1.1 cgd nfrontp += strlen(nfrontp);
654 1.1 cgd }
655 1.1 cgd break;
656 1.1 cgd
657 1.1 cgd case TELOPT_LINEMODE:
658 1.1 cgd sprintf(nfrontp, "LINEMODE ");
659 1.1 cgd nfrontp += strlen(nfrontp);
660 1.1 cgd if (length < 2) {
661 1.5 cgd sprintf(nfrontp, " (empty suboption??\?)");
662 1.1 cgd nfrontp += strlen(nfrontp);
663 1.1 cgd break;
664 1.1 cgd }
665 1.1 cgd switch (pointer[1]) {
666 1.1 cgd case WILL:
667 1.1 cgd sprintf(nfrontp, "WILL ");
668 1.1 cgd goto common;
669 1.1 cgd case WONT:
670 1.1 cgd sprintf(nfrontp, "WONT ");
671 1.1 cgd goto common;
672 1.1 cgd case DO:
673 1.1 cgd sprintf(nfrontp, "DO ");
674 1.1 cgd goto common;
675 1.1 cgd case DONT:
676 1.1 cgd sprintf(nfrontp, "DONT ");
677 1.1 cgd common:
678 1.1 cgd nfrontp += strlen(nfrontp);
679 1.1 cgd if (length < 3) {
680 1.5 cgd sprintf(nfrontp, "(no option??\?)");
681 1.1 cgd nfrontp += strlen(nfrontp);
682 1.1 cgd break;
683 1.1 cgd }
684 1.1 cgd switch (pointer[2]) {
685 1.1 cgd case LM_FORWARDMASK:
686 1.1 cgd sprintf(nfrontp, "Forward Mask");
687 1.1 cgd nfrontp += strlen(nfrontp);
688 1.1 cgd for (i = 3; i < length; i++) {
689 1.1 cgd sprintf(nfrontp, " %x", pointer[i]);
690 1.1 cgd nfrontp += strlen(nfrontp);
691 1.1 cgd }
692 1.1 cgd break;
693 1.1 cgd default:
694 1.1 cgd sprintf(nfrontp, "%d (unknown)", pointer[2]);
695 1.1 cgd nfrontp += strlen(nfrontp);
696 1.1 cgd for (i = 3; i < length; i++) {
697 1.1 cgd sprintf(nfrontp, " %d", pointer[i]);
698 1.1 cgd nfrontp += strlen(nfrontp);
699 1.1 cgd }
700 1.1 cgd break;
701 1.1 cgd }
702 1.1 cgd break;
703 1.8 jtk
704 1.1 cgd case LM_SLC:
705 1.1 cgd sprintf(nfrontp, "SLC");
706 1.1 cgd nfrontp += strlen(nfrontp);
707 1.1 cgd for (i = 2; i < length - 2; i += 3) {
708 1.1 cgd if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
709 1.1 cgd sprintf(nfrontp, " %s", SLC_NAME(pointer[i+SLC_FUNC]));
710 1.1 cgd else
711 1.1 cgd sprintf(nfrontp, " %d", pointer[i+SLC_FUNC]);
712 1.1 cgd nfrontp += strlen(nfrontp);
713 1.1 cgd switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
714 1.1 cgd case SLC_NOSUPPORT:
715 1.1 cgd sprintf(nfrontp, " NOSUPPORT"); break;
716 1.1 cgd case SLC_CANTCHANGE:
717 1.1 cgd sprintf(nfrontp, " CANTCHANGE"); break;
718 1.1 cgd case SLC_VARIABLE:
719 1.1 cgd sprintf(nfrontp, " VARIABLE"); break;
720 1.1 cgd case SLC_DEFAULT:
721 1.1 cgd sprintf(nfrontp, " DEFAULT"); break;
722 1.1 cgd }
723 1.1 cgd nfrontp += strlen(nfrontp);
724 1.1 cgd sprintf(nfrontp, "%s%s%s",
725 1.1 cgd pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
726 1.1 cgd pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
727 1.1 cgd pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
728 1.1 cgd nfrontp += strlen(nfrontp);
729 1.1 cgd if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
730 1.1 cgd SLC_FLUSHOUT| SLC_LEVELBITS)) {
731 1.1 cgd sprintf(nfrontp, "(0x%x)", pointer[i+SLC_FLAGS]);
732 1.1 cgd nfrontp += strlen(nfrontp);
733 1.1 cgd }
734 1.1 cgd sprintf(nfrontp, " %d;", pointer[i+SLC_VALUE]);
735 1.1 cgd nfrontp += strlen(nfrontp);
736 1.1 cgd if ((pointer[i+SLC_VALUE] == IAC) &&
737 1.1 cgd (pointer[i+SLC_VALUE+1] == IAC))
738 1.1 cgd i++;
739 1.1 cgd }
740 1.1 cgd for (; i < length; i++) {
741 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
742 1.1 cgd nfrontp += strlen(nfrontp);
743 1.1 cgd }
744 1.1 cgd break;
745 1.1 cgd
746 1.1 cgd case LM_MODE:
747 1.1 cgd sprintf(nfrontp, "MODE ");
748 1.1 cgd nfrontp += strlen(nfrontp);
749 1.1 cgd if (length < 3) {
750 1.5 cgd sprintf(nfrontp, "(no mode??\?)");
751 1.1 cgd nfrontp += strlen(nfrontp);
752 1.1 cgd break;
753 1.1 cgd }
754 1.1 cgd {
755 1.1 cgd char tbuf[32];
756 1.1 cgd sprintf(tbuf, "%s%s%s%s%s",
757 1.1 cgd pointer[2]&MODE_EDIT ? "|EDIT" : "",
758 1.1 cgd pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
759 1.1 cgd pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
760 1.1 cgd pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
761 1.1 cgd pointer[2]&MODE_ACK ? "|ACK" : "");
762 1.1 cgd sprintf(nfrontp, "%s", tbuf[1] ? &tbuf[1] : "0");
763 1.1 cgd nfrontp += strlen(nfrontp);
764 1.1 cgd }
765 1.1 cgd if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) {
766 1.1 cgd sprintf(nfrontp, " (0x%x)", pointer[2]);
767 1.1 cgd nfrontp += strlen(nfrontp);
768 1.1 cgd }
769 1.1 cgd for (i = 3; i < length; i++) {
770 1.1 cgd sprintf(nfrontp, " ?0x%x?", pointer[i]);
771 1.1 cgd nfrontp += strlen(nfrontp);
772 1.1 cgd }
773 1.1 cgd break;
774 1.1 cgd default:
775 1.1 cgd sprintf(nfrontp, "%d (unknown)", pointer[1]);
776 1.1 cgd nfrontp += strlen(nfrontp);
777 1.1 cgd for (i = 2; i < length; i++) {
778 1.1 cgd sprintf(nfrontp, " %d", pointer[i]);
779 1.1 cgd nfrontp += strlen(nfrontp);
780 1.1 cgd }
781 1.1 cgd }
782 1.1 cgd break;
783 1.1 cgd
784 1.1 cgd case TELOPT_STATUS: {
785 1.1 cgd register char *cp;
786 1.1 cgd register int j, k;
787 1.1 cgd
788 1.1 cgd sprintf(nfrontp, "STATUS");
789 1.1 cgd nfrontp += strlen(nfrontp);
790 1.1 cgd
791 1.1 cgd switch (pointer[1]) {
792 1.1 cgd default:
793 1.1 cgd if (pointer[1] == TELQUAL_SEND)
794 1.1 cgd sprintf(nfrontp, " SEND");
795 1.1 cgd else
796 1.1 cgd sprintf(nfrontp, " %d (unknown)", pointer[1]);
797 1.1 cgd nfrontp += strlen(nfrontp);
798 1.1 cgd for (i = 2; i < length; i++) {
799 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
800 1.1 cgd nfrontp += strlen(nfrontp);
801 1.1 cgd }
802 1.1 cgd break;
803 1.1 cgd case TELQUAL_IS:
804 1.1 cgd sprintf(nfrontp, " IS\r\n");
805 1.1 cgd nfrontp += strlen(nfrontp);
806 1.1 cgd
807 1.1 cgd for (i = 2; i < length; i++) {
808 1.1 cgd switch(pointer[i]) {
809 1.1 cgd case DO: cp = "DO"; goto common2;
810 1.1 cgd case DONT: cp = "DONT"; goto common2;
811 1.1 cgd case WILL: cp = "WILL"; goto common2;
812 1.1 cgd case WONT: cp = "WONT"; goto common2;
813 1.1 cgd common2:
814 1.1 cgd i++;
815 1.5 cgd if (TELOPT_OK(pointer[i]))
816 1.1 cgd sprintf(nfrontp, " %s %s", cp, TELOPT(pointer[i]));
817 1.1 cgd else
818 1.1 cgd sprintf(nfrontp, " %s %d", cp, pointer[i]);
819 1.1 cgd nfrontp += strlen(nfrontp);
820 1.1 cgd
821 1.1 cgd sprintf(nfrontp, "\r\n");
822 1.1 cgd nfrontp += strlen(nfrontp);
823 1.1 cgd break;
824 1.1 cgd
825 1.1 cgd case SB:
826 1.1 cgd sprintf(nfrontp, " SB ");
827 1.1 cgd nfrontp += strlen(nfrontp);
828 1.1 cgd i++;
829 1.1 cgd j = k = i;
830 1.1 cgd while (j < length) {
831 1.1 cgd if (pointer[j] == SE) {
832 1.1 cgd if (j+1 == length)
833 1.1 cgd break;
834 1.1 cgd if (pointer[j+1] == SE)
835 1.1 cgd j++;
836 1.1 cgd else
837 1.1 cgd break;
838 1.1 cgd }
839 1.1 cgd pointer[k++] = pointer[j++];
840 1.1 cgd }
841 1.1 cgd printsub(0, &pointer[i], k - i);
842 1.1 cgd if (i < length) {
843 1.1 cgd sprintf(nfrontp, " SE");
844 1.1 cgd nfrontp += strlen(nfrontp);
845 1.1 cgd i = j;
846 1.1 cgd } else
847 1.1 cgd i = j - 1;
848 1.1 cgd
849 1.1 cgd sprintf(nfrontp, "\r\n");
850 1.1 cgd nfrontp += strlen(nfrontp);
851 1.1 cgd
852 1.1 cgd break;
853 1.8 jtk
854 1.1 cgd default:
855 1.1 cgd sprintf(nfrontp, " %d", pointer[i]);
856 1.1 cgd nfrontp += strlen(nfrontp);
857 1.1 cgd break;
858 1.1 cgd }
859 1.1 cgd }
860 1.1 cgd break;
861 1.1 cgd }
862 1.1 cgd break;
863 1.1 cgd }
864 1.1 cgd
865 1.1 cgd case TELOPT_XDISPLOC:
866 1.1 cgd sprintf(nfrontp, "X-DISPLAY-LOCATION ");
867 1.1 cgd nfrontp += strlen(nfrontp);
868 1.1 cgd switch (pointer[1]) {
869 1.1 cgd case TELQUAL_IS:
870 1.1 cgd sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2);
871 1.1 cgd break;
872 1.1 cgd case TELQUAL_SEND:
873 1.1 cgd sprintf(nfrontp, "SEND");
874 1.1 cgd break;
875 1.1 cgd default:
876 1.1 cgd sprintf(nfrontp, "- unknown qualifier %d (0x%x).",
877 1.1 cgd pointer[1], pointer[1]);
878 1.1 cgd }
879 1.1 cgd nfrontp += strlen(nfrontp);
880 1.1 cgd break;
881 1.1 cgd
882 1.5 cgd case TELOPT_NEW_ENVIRON:
883 1.5 cgd sprintf(nfrontp, "NEW-ENVIRON ");
884 1.5 cgd goto env_common1;
885 1.5 cgd case TELOPT_OLD_ENVIRON:
886 1.5 cgd sprintf(nfrontp, "OLD-ENVIRON");
887 1.5 cgd env_common1:
888 1.1 cgd nfrontp += strlen(nfrontp);
889 1.1 cgd switch (pointer[1]) {
890 1.1 cgd case TELQUAL_IS:
891 1.1 cgd sprintf(nfrontp, "IS ");
892 1.1 cgd goto env_common;
893 1.1 cgd case TELQUAL_SEND:
894 1.1 cgd sprintf(nfrontp, "SEND ");
895 1.1 cgd goto env_common;
896 1.1 cgd case TELQUAL_INFO:
897 1.1 cgd sprintf(nfrontp, "INFO ");
898 1.1 cgd env_common:
899 1.5 cgd nfrontp += strlen(nfrontp);
900 1.1 cgd {
901 1.1 cgd register int noquote = 2;
902 1.1 cgd for (i = 2; i < length; i++ ) {
903 1.1 cgd switch (pointer[i]) {
904 1.5 cgd case NEW_ENV_VAR:
905 1.1 cgd sprintf(nfrontp, "\" VAR " + noquote);
906 1.1 cgd nfrontp += strlen(nfrontp);
907 1.1 cgd noquote = 2;
908 1.1 cgd break;
909 1.1 cgd
910 1.5 cgd case NEW_ENV_VALUE:
911 1.1 cgd sprintf(nfrontp, "\" VALUE " + noquote);
912 1.1 cgd nfrontp += strlen(nfrontp);
913 1.1 cgd noquote = 2;
914 1.1 cgd break;
915 1.1 cgd
916 1.1 cgd case ENV_ESC:
917 1.1 cgd sprintf(nfrontp, "\" ESC " + noquote);
918 1.1 cgd nfrontp += strlen(nfrontp);
919 1.1 cgd noquote = 2;
920 1.1 cgd break;
921 1.1 cgd
922 1.5 cgd case ENV_USERVAR:
923 1.5 cgd sprintf(nfrontp, "\" USERVAR " + noquote);
924 1.5 cgd nfrontp += strlen(nfrontp);
925 1.5 cgd noquote = 2;
926 1.5 cgd break;
927 1.5 cgd
928 1.1 cgd default:
929 1.1 cgd def_case:
930 1.1 cgd if (isprint(pointer[i]) && pointer[i] != '"') {
931 1.1 cgd if (noquote) {
932 1.1 cgd *nfrontp++ = '"';
933 1.1 cgd noquote = 0;
934 1.1 cgd }
935 1.1 cgd *nfrontp++ = pointer[i];
936 1.1 cgd } else {
937 1.1 cgd sprintf(nfrontp, "\" %03o " + noquote,
938 1.1 cgd pointer[i]);
939 1.1 cgd nfrontp += strlen(nfrontp);
940 1.1 cgd noquote = 2;
941 1.1 cgd }
942 1.1 cgd break;
943 1.1 cgd }
944 1.1 cgd }
945 1.1 cgd if (!noquote)
946 1.1 cgd *nfrontp++ = '"';
947 1.1 cgd break;
948 1.1 cgd }
949 1.1 cgd }
950 1.1 cgd break;
951 1.1 cgd
952 1.5 cgd #if defined(AUTHENTICATION)
953 1.1 cgd case TELOPT_AUTHENTICATION:
954 1.1 cgd sprintf(nfrontp, "AUTHENTICATION");
955 1.1 cgd nfrontp += strlen(nfrontp);
956 1.8 jtk
957 1.1 cgd if (length < 2) {
958 1.5 cgd sprintf(nfrontp, " (empty suboption??\?)");
959 1.1 cgd nfrontp += strlen(nfrontp);
960 1.1 cgd break;
961 1.1 cgd }
962 1.1 cgd switch (pointer[1]) {
963 1.1 cgd case TELQUAL_REPLY:
964 1.1 cgd case TELQUAL_IS:
965 1.1 cgd sprintf(nfrontp, " %s ", (pointer[1] == TELQUAL_IS) ?
966 1.1 cgd "IS" : "REPLY");
967 1.1 cgd nfrontp += strlen(nfrontp);
968 1.1 cgd if (AUTHTYPE_NAME_OK(pointer[2]))
969 1.1 cgd sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[2]));
970 1.1 cgd else
971 1.1 cgd sprintf(nfrontp, "%d ", pointer[2]);
972 1.1 cgd nfrontp += strlen(nfrontp);
973 1.1 cgd if (length < 3) {
974 1.5 cgd sprintf(nfrontp, "(partial suboption??\?)");
975 1.1 cgd nfrontp += strlen(nfrontp);
976 1.1 cgd break;
977 1.1 cgd }
978 1.1 cgd sprintf(nfrontp, "%s|%s",
979 1.1 cgd ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
980 1.1 cgd "CLIENT" : "SERVER",
981 1.1 cgd ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
982 1.1 cgd "MUTUAL" : "ONE-WAY");
983 1.1 cgd nfrontp += strlen(nfrontp);
984 1.1 cgd
985 1.1 cgd auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
986 1.1 cgd sprintf(nfrontp, "%s", buf);
987 1.1 cgd nfrontp += strlen(nfrontp);
988 1.1 cgd break;
989 1.1 cgd
990 1.1 cgd case TELQUAL_SEND:
991 1.1 cgd i = 2;
992 1.1 cgd sprintf(nfrontp, " SEND ");
993 1.1 cgd nfrontp += strlen(nfrontp);
994 1.1 cgd while (i < length) {
995 1.1 cgd if (AUTHTYPE_NAME_OK(pointer[i]))
996 1.1 cgd sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[i]));
997 1.1 cgd else
998 1.1 cgd sprintf(nfrontp, "%d ", pointer[i]);
999 1.1 cgd nfrontp += strlen(nfrontp);
1000 1.1 cgd if (++i >= length) {
1001 1.5 cgd sprintf(nfrontp, "(partial suboption??\?)");
1002 1.1 cgd nfrontp += strlen(nfrontp);
1003 1.1 cgd break;
1004 1.1 cgd }
1005 1.1 cgd sprintf(nfrontp, "%s|%s ",
1006 1.1 cgd ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
1007 1.1 cgd "CLIENT" : "SERVER",
1008 1.1 cgd ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
1009 1.1 cgd "MUTUAL" : "ONE-WAY");
1010 1.1 cgd nfrontp += strlen(nfrontp);
1011 1.1 cgd ++i;
1012 1.1 cgd }
1013 1.1 cgd break;
1014 1.1 cgd
1015 1.1 cgd case TELQUAL_NAME:
1016 1.1 cgd i = 2;
1017 1.1 cgd sprintf(nfrontp, " NAME \"");
1018 1.1 cgd nfrontp += strlen(nfrontp);
1019 1.1 cgd while (i < length)
1020 1.1 cgd *nfrontp += pointer[i++];
1021 1.1 cgd *nfrontp += '"';
1022 1.1 cgd break;
1023 1.1 cgd
1024 1.1 cgd default:
1025 1.1 cgd for (i = 2; i < length; i++) {
1026 1.1 cgd sprintf(nfrontp, " ?%d?", pointer[i]);
1027 1.1 cgd nfrontp += strlen(nfrontp);
1028 1.1 cgd }
1029 1.1 cgd break;
1030 1.1 cgd }
1031 1.1 cgd break;
1032 1.1 cgd #endif
1033 1.1 cgd
1034 1.1 cgd
1035 1.1 cgd default:
1036 1.1 cgd if (TELOPT_OK(pointer[0]))
1037 1.8 jtk sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0]));
1038 1.1 cgd else
1039 1.8 jtk sprintf(nfrontp, "%d (unknown)", pointer[i]);
1040 1.1 cgd nfrontp += strlen(nfrontp);
1041 1.1 cgd for (i = 1; i < length; i++) {
1042 1.1 cgd sprintf(nfrontp, " %d", pointer[i]);
1043 1.1 cgd nfrontp += strlen(nfrontp);
1044 1.1 cgd }
1045 1.1 cgd break;
1046 1.1 cgd }
1047 1.1 cgd sprintf(nfrontp, "\r\n");
1048 1.1 cgd nfrontp += strlen(nfrontp);
1049 1.1 cgd }
1050 1.1 cgd
1051 1.1 cgd /*
1052 1.1 cgd * Dump a data buffer in hex and ascii to the output data stream.
1053 1.1 cgd */
1054 1.1 cgd void
1055 1.1 cgd printdata(tag, ptr, cnt)
1056 1.1 cgd register char *tag;
1057 1.1 cgd register char *ptr;
1058 1.1 cgd register int cnt;
1059 1.1 cgd {
1060 1.1 cgd register int i;
1061 1.1 cgd char xbuf[30];
1062 1.1 cgd
1063 1.1 cgd while (cnt) {
1064 1.1 cgd /* flush net output buffer if no room for new data) */
1065 1.1 cgd if ((&netobuf[BUFSIZ] - nfrontp) < 80) {
1066 1.1 cgd netflush();
1067 1.1 cgd }
1068 1.1 cgd
1069 1.1 cgd /* add a line of output */
1070 1.1 cgd sprintf(nfrontp, "%s: ", tag);
1071 1.1 cgd nfrontp += strlen(nfrontp);
1072 1.1 cgd for (i = 0; i < 20 && cnt; i++) {
1073 1.1 cgd sprintf(nfrontp, "%02x", *ptr);
1074 1.8 jtk nfrontp += strlen(nfrontp);
1075 1.1 cgd if (isprint(*ptr)) {
1076 1.1 cgd xbuf[i] = *ptr;
1077 1.1 cgd } else {
1078 1.1 cgd xbuf[i] = '.';
1079 1.1 cgd }
1080 1.8 jtk if (i % 2) {
1081 1.1 cgd *nfrontp = ' ';
1082 1.1 cgd nfrontp++;
1083 1.1 cgd }
1084 1.1 cgd cnt--;
1085 1.1 cgd ptr++;
1086 1.1 cgd }
1087 1.1 cgd xbuf[i] = '\0';
1088 1.1 cgd sprintf(nfrontp, " %s\r\n", xbuf );
1089 1.1 cgd nfrontp += strlen(nfrontp);
1090 1.8 jtk }
1091 1.1 cgd }
1092 1.1 cgd #endif /* DIAGNOSTICS */
1093