diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-11-12 00:59:09 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-11-12 00:59:09 +0000 |
commit | 1cc38cd84c09b202cff7e68a5fa3df6690d85447 (patch) | |
tree | 06845fdff4d72546b57dc60f095536100c4031be /packet-telnet.c | |
parent | 2256e6bdc39dd51685a084f55f5904b47f83f121 (diff) |
Make "tvb_find_line_end()" and "tvb_find_line_end_unquoted()" treat CR
by itself as a line ending, as well as treating CR LF and LF as line
endings.
Tweak the Telnet dissector to treat LF and CR NUL as line endings, but
not to treat CR by itself as a line ending (that's not exactly what the
NVT specification in the Telnet RFC specifies, but the resulting output
may be a bit more readable that way).
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@2613 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'packet-telnet.c')
-rw-r--r-- | packet-telnet.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/packet-telnet.c b/packet-telnet.c index d5ca334044..28696277e6 100644 --- a/packet-telnet.c +++ b/packet-telnet.c @@ -2,7 +2,7 @@ * Routines for telnet packet dissection * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com> * - * $Id: packet-telnet.c,v 1.18 2000/11/09 10:56:32 guy Exp $ + * $Id: packet-telnet.c,v 1.19 2000/11/12 00:59:07 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -302,19 +302,59 @@ telnet_add_text(proto_tree *tree, tvbuff_t *tvb, int offset, int len) { gint next_offset; int linelen; + guint8 c; + gboolean last_char_was_cr; - while (len != 0 && tvb_length_remaining(tvb, offset)) { + while (len != 0 && tvb_length_remaining(tvb, offset) != 0) { /* * Find the end of the line. */ - tvb_find_line_end(tvb, offset, len, &next_offset); + linelen = tvb_find_line_end(tvb, offset, len, &next_offset); + len -= next_offset - offset; /* subtract out the line's characters */ + + /* + * In Telnet, CR NUL is the way you send a CR by itself in the + * default ASCII mode; don't treat CR by itself as a line ending, + * treat only CR NUL, CR LF, or LF by itself as a line ending. + */ + if (next_offset == offset + linelen + 1 && len >= 1) { + /* + * Well, we saw a one-character line ending, so either it's a CR + * or an LF; we have at least two characters left, including the + * CR. + * + * If the line ending is a CR, skip all subsequent CRs; at + * least one capture appeared to have multiple CRs at the end of + * a line. + */ + if (tvb_get_guint8(tvb, offset + linelen) == '\r') { + last_char_was_cr = TRUE; + while (len != 0 && tvb_length_remaining(tvb, next_offset) != 0) { + c = tvb_get_guint8(tvb, next_offset); + next_offset++; /* skip over that character */ + len--; + if (c == '\n' || (c == '\0' && last_char_was_cr)) { + /* + * LF is a line ending, whether preceded by CR or not. + * NUL is a line ending if preceded by CR. + */ + break; + } + last_char_was_cr = (c == '\r'); + } + } + } + + /* + * Now compute the length of the line *including* the end-of-line + * indication, if any; we display it all. + */ linelen = next_offset - offset; proto_tree_add_text(tree, tvb, offset, linelen, "Data: %s", tvb_format_text(tvb, offset, linelen)); - offset += linelen; - len -= linelen; + offset = next_offset; } } |