]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-telnet.c
Fix the pointer tests in the non-ndoified TTEST2() macro as well.
[tcpdump] / print-telnet.c
index af1218f6454e52b6ebb443934baf85e9437a4590..4911e5caf2385375daae78d32a592216342f8c7c 100644 (file)
  */
 /*
  *      @(#)Copyright (c) 1994, Simon J. Gerraty.
- *      
+ *
  *      This is free software.  It comes with NO WARRANTY.
- *      Permission to use, modify and distribute this source code 
+ *      Permission to use, modify and distribute this source code
  *      is granted subject to the following conditions.
- *      1/ that the above copyright notice and this notice 
+ *      1/ that the above copyright notice and this notice
  *      are preserved in all copies.
  */
 
 #endif
 
 #ifndef lint
-static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.16 2001-06-26 03:01:10 itojun Exp $";
+static const char rcsid[] _U_ =
+     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.24 2003-12-29 11:05:10 hannes Exp $";
 #endif
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <ctype.h>
-
-#include <netinet/in.h>
-
-#define TELCMDS
-#define TELOPTS
-#include <arpa/telnet.h>
+#include <tcpdump-stdinc.h>
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 
 #include "interface.h"
 #include "addrtoname.h"
 
-#ifndef TELCMD_FIRST
-# define TELCMD_FIRST SE
-#endif
+#define TELCMDS
+#define TELOPTS
+#include "telnet.h"
 
 /* normal */
 static const char *cmds[] = {
@@ -115,22 +105,19 @@ numstr(int x)
        return buf;
 }
 
-/* sp points to IAB byte */
+/* sp points to IAC byte */
 static int
 telnet_parse(const u_char *sp, u_int length, int print)
 {
-       int i, c, x;
+       int i, x;
+       u_int c;
        const u_char *osp, *p;
-#define PEEK(c, sp, length) \
-       do { \
-               if (length < 1) \
-                       goto trunc; \
-               c = *sp; \
-       } while (0)
 #define FETCH(c, sp, length) \
        do { \
-               PEEK((c), (sp), (length)); \
-               sp++; \
+               if (length < 1) \
+                       goto pktend; \
+               TCHECK(*sp); \
+               c = *sp++; \
                length--; \
        } while (0)
 
@@ -138,7 +125,7 @@ telnet_parse(const u_char *sp, u_int length, int print)
 
        FETCH(c, sp, length);
        if (c != IAC)
-               goto trunc;
+               goto pktend;
        FETCH(c, sp, length);
        if (c == IAC) {         /* <IAC><IAC>! */
                if (print)
@@ -148,7 +135,7 @@ telnet_parse(const u_char *sp, u_int length, int print)
 
        i = c - TELCMD_FIRST;
        if (i < 0 || i > IAC - TELCMD_FIRST)
-               goto trunc;
+               goto pktend;
 
        switch (c) {
        case DONT:
@@ -169,13 +156,13 @@ telnet_parse(const u_char *sp, u_int length, int print)
                        break;
                /* IAC SB .... IAC SE */
                p = sp;
-               while (length > p + 1 - sp) {
+               while (length > (u_int)(p + 1 - sp)) {
                        if (p[0] == IAC && p[1] == SE)
                                break;
                        p++;
                }
                if (*p != IAC)
-                       goto trunc;
+                       goto pktend;
 
                switch (x) {
                case TELOPT_AUTHENTICATION:
@@ -231,8 +218,9 @@ done:
        return sp - osp;
 
 trunc:
+       (void)printf("[|telnet]");
+pktend:
        return -1;
-#undef PEEK
 #undef FETCH
 }
 
@@ -244,7 +232,7 @@ telnet_print(const u_char *sp, u_int length)
        int l;
 
        osp = sp;
-       
+
        while (length > 0 && *sp == IAC) {
                l = telnet_parse(sp, length, 0);
                if (l < 0)
@@ -256,7 +244,7 @@ telnet_print(const u_char *sp, u_int length)
                if (Xflag && 2 < vflag) {
                        if (first)
                                printf("\nTelnet:");
-                       hex_print_with_offset(sp, l, sp - osp);
+                       hex_print_with_offset("\n", sp, l, sp - osp);
                        if (l > 8)
                                printf("\n\t\t\t\t");
                        else