]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-telnet.c
Fix spaces
[tcpdump] / print-telnet.c
index ae29b4749a21092f088f8844a2e34d3241884062..3bfb19a2f77362b57c83ebc5cac72b83d9b81168 100644 (file)
  *      are preserved in all copies.
  */
 
+/* \summary: Telnet option printer */
+
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <tcpdump-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include <stdio.h>
 
 #include "netdissect.h"
+#include "extract.h"
+
 
 #define TELCMDS
 #define TELOPTS
@@ -87,7 +91,7 @@
 #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,
@@ -148,7 +152,7 @@ extern char *telcmds[];
 
 #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",
@@ -377,7 +381,7 @@ numstr(int x)
 {
        static char buf[20];
 
-       snprintf(buf, sizeof(buf), "%#x", x);
+       nd_snprintf(buf, sizeof(buf), "%#x", x);
        return buf;
 }
 
@@ -392,8 +396,9 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
        do { \
                if (length < 1) \
                        goto pktend; \
-               ND_TCHECK(*sp); \
-               c = *sp++; \
+               ND_TCHECK_1(sp); \
+               c = EXTRACT_U_1(sp); \
+               sp++; \
                length--; \
        } while (0)
 
@@ -405,7 +410,7 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
        FETCH(c, sp, length);
        if (c == IAC) {         /* <IAC><IAC>! */
                if (print)
-                       ND_PRINT((ndo, "IAC IAC"));
+                       ND_PRINT("IAC IAC");
                goto done;
        }
 
@@ -423,21 +428,23 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
                FETCH(x, sp, length);
                if (x >= 0 && x < NTELOPTS) {
                        if (print)
-                               ND_PRINT((ndo, "%s %s", telcmds[i], telopts[x]));
+                               ND_PRINT("%s %s", telcmds[i], telopts[x]);
                } else {
                        if (print)
-                               ND_PRINT((ndo, "%s %#x", telcmds[i], x));
+                               ND_PRINT("%s %#x", telcmds[i], x);
                }
                if (c != SB)
                        break;
                /* 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++;
                }
-               if (*p != IAC)
+               ND_TCHECK_1(p);
+               if (EXTRACT_U_1(p) != IAC)
                        goto pktend;
 
                switch (x) {
@@ -446,46 +453,46 @@ telnet_parse(netdissect_options *ndo, const u_char *sp, u_int length, int print)
                                break;
                        FETCH(c, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %s", STR_OR_ID(c, authcmd)));
+                               ND_PRINT(" %s", STR_OR_ID(c, authcmd));
                        if (p <= sp)
                                break;
                        FETCH(c, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %s", STR_OR_ID(c, authtype)));
+                               ND_PRINT(" %s", STR_OR_ID(c, authtype));
                        break;
                case TELOPT_ENCRYPT:
                        if (p <= sp)
                                break;
                        FETCH(c, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %s", STR_OR_ID(c, enccmd)));
+                               ND_PRINT(" %s", STR_OR_ID(c, enccmd));
                        if (p <= sp)
                                break;
                        FETCH(c, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %s", STR_OR_ID(c, enctype)));
+                               ND_PRINT(" %s", STR_OR_ID(c, enctype));
                        break;
                default:
                        if (p <= sp)
                                break;
                        FETCH(c, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %s", STR_OR_ID(c, cmds)));
+                               ND_PRINT(" %s", STR_OR_ID(c, cmds));
                        break;
                }
                while (p > sp) {
                        FETCH(x, sp, length);
                        if (print)
-                               ND_PRINT((ndo, " %#x", x));
+                               ND_PRINT(" %#x", x);
                }
                /* terminating IAC SE */
                if (print)
-                       ND_PRINT((ndo, " SE"));
+                       ND_PRINT(" SE");
                sp += 2;
                break;
        default:
                if (print)
-                       ND_PRINT((ndo, "%s", telcmds[i]));
+                       ND_PRINT("%s", telcmds[i]);
                goto done;
        }
 
@@ -493,7 +500,7 @@ done:
        return sp - osp;
 
 trunc:
-       ND_PRINT((ndo, "[|telnet]"));
+       nd_print_trunc(ndo);
 pktend:
        return -1;
 #undef FETCH
@@ -506,9 +513,11 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
        const u_char *osp;
        int l;
 
+       ndo->ndo_protocol = "telnet";
        osp = sp;
 
-       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.
@@ -522,25 +531,29 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length)
                 */
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) {
                        if (first)
-                               ND_PRINT((ndo, "\nTelnet:"));
+                               ND_PRINT("\nTelnet:");
                        hex_print_with_offset(ndo, "\n", sp, l, sp - osp);
                        if (l > 8)
-                               ND_PRINT((ndo, "\n\t\t\t\t"));
+                               ND_PRINT("\n\t\t\t\t");
                        else
-                               ND_PRINT((ndo, "%*s\t", (8 - l) * 3, ""));
+                               ND_PRINT("%*s\t", (8 - l) * 3, "");
                } else
-                       ND_PRINT((ndo, "%s", (first) ? " [telnet " : ", "));
+                       ND_PRINT("%s", (first) ? " [telnet " : ", ");
 
                (void)telnet_parse(ndo, sp, length, 1);
                first = 0;
 
                sp += l;
                length -= l;
+               ND_TCHECK_1(sp);
        }
        if (!first) {
                if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag)
-                       ND_PRINT((ndo, "\n"));
+                       ND_PRINT("\n");
                else
-                       ND_PRINT((ndo, "]"));
+                       ND_PRINT("]");
        }
+       return;
+trunc:
+       nd_print_trunc(ndo);
 }