X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/0115c33ed793638394a3480818271fbc443c0c53..ebb51ef0e725737ca8c1d618da6527a58660d2bf:/print-telnet.c diff --git a/print-telnet.c b/print-telnet.c index fa59b1fe..a6640346 100644 --- a/print-telnet.c +++ b/print-telnet.c @@ -45,16 +45,19 @@ * are preserved in all copies. */ -#define NETDISSECT_REWORKED +/* \summary: Telnet option printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include -#include "interface.h" +#include "netdissect.h" + +static const char tstr[] = " [|telnet]"; #define TELCMDS #define TELOPTS @@ -88,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, @@ -149,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", @@ -434,6 +437,7 @@ 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)) { + ND_TCHECK2(*p, 2); if (p[0] == IAC && p[1] == SE) break; p++; @@ -494,7 +498,7 @@ done: return sp - osp; trunc: - ND_PRINT((ndo, "[|telnet]")); + ND_PRINT((ndo, "%s", tstr)); pktend: return -1; #undef FETCH @@ -509,6 +513,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) osp = sp; + ND_TCHECK(*sp); while (length > 0 && *sp == IAC) { /* * Parse the Telnet command without printing it, @@ -537,6 +542,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) sp += l; length -= l; + ND_TCHECK(*sp); } if (!first) { if (ndo->ndo_Xflag && 2 < ndo->ndo_vflag) @@ -544,4 +550,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) else ND_PRINT((ndo, "]")); } + return; +trunc: + ND_PRINT((ndo, "%s", tstr)); }