X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/38700c7f24646dfbc6ac0ed529d3ed727c545cd0..61c422a88caefe986c2bc0a7f2f3028f696fa5cd:/print-telnet.c diff --git a/print-telnet.c b/print-telnet.c index b3f17ed2..8ff527b4 100644 --- a/print-telnet.c +++ b/print-telnet.c @@ -45,15 +45,20 @@ * are preserved in all copies. */ +/* \summary: Telnet option printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include -#include "interface.h" +#include "netdissect.h" +#include "extract.h" + +static const char tstr[] = " [|telnet]"; #define TELCMDS #define TELOPTS @@ -87,7 +92,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 +153,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", @@ -433,10 +438,12 @@ 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)) { - 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++; } + ND_TCHECK(*p); if (*p != IAC) goto pktend; @@ -493,7 +500,7 @@ done: return sp - osp; trunc: - ND_PRINT((ndo, "[|telnet]")); + ND_PRINT((ndo, "%s", tstr)); pktend: return -1; #undef FETCH @@ -508,7 +515,8 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) osp = sp; - while (length > 0 && *sp == IAC) { + ND_TCHECK(*sp); + while (length > 0 && EXTRACT_U_1(sp) == IAC) { /* * Parse the Telnet command without printing it, * to determine its length. @@ -536,6 +544,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) @@ -543,4 +552,7 @@ telnet_print(netdissect_options *ndo, const u_char *sp, u_int length) else ND_PRINT((ndo, "]")); } + return; +trunc: + ND_PRINT((ndo, "%s", tstr)); }