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