]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-telnet.c
Use more the ND_TTEST_1() macro
[tcpdump] / print-telnet.c
index 7c5a737d33252d8e3f2c59d3a8cabdcfca132bc3..41e24462e199caa9ed1a1be0015e595caff1b2ca 100644 (file)
  *      are preserved in all copies.
  */
 
  *      are preserved in all copies.
  */
 
-#define NETDISSECT_REWORKED
+/* \summary: Telnet option printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
-#include "interface.h"
+#include "netdissect.h"
+#include "extract.h"
+
+static const char tstr[] = " [|telnet]";
 
 #define TELCMDS
 #define TELOPTS
 
 #define TELCMDS
 #define TELOPTS
@@ -88,7 +92,7 @@
 #define SYNCH  242             /* for telfunc calls */
 
 #ifdef TELCMDS
 #define SYNCH  242             /* for telfunc calls */
 
 #ifdef TELCMDS
-const char *telcmds[] = {
+static const char *telcmds[] = {
        "EOF", "SUSP", "ABORT", "EOR",
        "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
        "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
        "EOF", "SUSP", "ABORT", "EOR",
        "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
        "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
@@ -149,7 +153,7 @@ extern char *telcmds[];
 
 #define        NTELOPTS        (1+TELOPT_NEW_ENVIRON)
 #ifdef TELOPTS
 
 #define        NTELOPTS        (1+TELOPT_NEW_ENVIRON)
 #ifdef TELOPTS
-const char *telopts[NTELOPTS+1] = {
+static const char *telopts[NTELOPTS+1] = {
        "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
        "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
        "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
        "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
        "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
        "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
@@ -434,11 +438,13 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
                /* IAC SB .... IAC SE */
                p = sp;
                while (length > (u_int)(p + 1 - sp)) {
                /* IAC SB .... IAC SE */
                p = sp;
                while (length > (u_int)(p + 1 - sp)) {
-                       if (p[0] == IAC && p[1] == SE)
+                       ND_TCHECK_2(p);
+                       if (EXTRACT_U_1(p) == IAC && EXTRACT_U_1(p + 1) == SE)
                                break;
                        p++;
                }
                                break;
                        p++;
                }
-               if (*p != IAC)
+               ND_TCHECK_1(p);
+               if (EXTRACT_U_1(p) != IAC)
                        goto pktend;
 
                switch (x) {
                        goto pktend;
 
                switch (x) {
@@ -494,7 +500,7 @@ done:
        return sp - osp;
 
 trunc:
        return sp - osp;
 
 trunc:
-       ND_PRINT((ndo, "[|telnet]"));
+       ND_PRINT((ndo, "%s", tstr));
 pktend:
        return -1;
 #undef FETCH
 pktend:
        return -1;
 #undef FETCH
@@ -509,12 +515,12 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
 
        osp = sp;
 
 
        osp = sp;
 
-       if (ndo->ndo_qflag) {
-               ND_PRINT((ndo, "[telnet]"));
-               return;
-       }
-
-       while (length > 0 && *sp == IAC) {
+       ND_TCHECK_1(sp);
+       while (length > 0 && EXTRACT_U_1(sp) == IAC) {
+               /*
+                * Parse the Telnet command without printing it,
+                * to determine its length.
+                */
                l = telnet_parse(ndo, sp, length, 0);
                if (l < 0)
                        break;
                l = telnet_parse(ndo, sp, length, 0);
                if (l < 0)
                        break;
@@ -538,6 +544,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
 
                sp += l;
                length -= l;
 
                sp += l;
                length -= l;
+               ND_TCHECK_1(sp);
        }
        if (!first) {
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)
        }
        if (!first) {
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)
@@ -545,4 +552,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
                else
                        ND_PRINT((ndo, "]"));
        }
                else
                        ND_PRINT((ndo, "]"));
        }
+       return;
+trunc:
+       ND_PRINT((ndo, "%s", tstr));
 }
 }