diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-09-11 16:16:13 +0000 |
---|---|---|
committer | Gilbert Ramirez <gram@alumni.rice.edu> | 2000-09-11 16:16:13 +0000 |
commit | 9941aabd64835e9c2e855b44cf0a6e336443b468 (patch) | |
tree | 28e1aeb36631c1474511888f369601cf33640617 /packet.c | |
parent | bf98417be05a76e93fd3976fef85110be51be780 (diff) | |
download | wireshark-9941aabd64835e9c2e855b44cf0a6e336443b468.tar.gz wireshark-9941aabd64835e9c2e855b44cf0a6e336443b468.tar.bz2 wireshark-9941aabd64835e9c2e855b44cf0a6e336443b468.zip |
Move format_text(), get_token_len(), and fine_line_end(), into strutil.c
This keeps tvbuff.c generic; it doesn't have to pull in packet.h and all
of it's included files.
svn path=/trunk/; revision=2409
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 188 |
1 files changed, 1 insertions, 187 deletions
@@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.104 2000/09/10 06:44:35 guy Exp $ + * $Id: packet.c,v 1.105 2000/09/11 16:16:11 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -409,192 +409,6 @@ display_signed_time(gchar *buf, int buflen, gint32 sec, gint32 usec) snprintf(buf, buflen, "%s%d.%06d", sign, sec, usec); } -/* - * Given a pointer into a data buffer, and to the end of the buffer, - * find the end of the (putative) line at that position in the data - * buffer. - * Return a pointer to the EOL character(s) in "*eol". - */ -const u_char * -find_line_end(const u_char *data, const u_char *dataend, const u_char **eol) -{ - const u_char *lineend; - - lineend = memchr(data, '\n', dataend - data); - if (lineend == NULL) { - /* - * No LF - line is probably continued in next TCP segment. - */ - lineend = dataend; - *eol = dataend; - } else { - /* - * Is the LF at the beginning of the line? - */ - if (lineend > data) { - /* - * No - is it preceded by a carriage return? - * (Perhaps it's supposed to be, but that's not guaranteed....) - */ - if (*(lineend - 1) == '\r') { - /* - * Yes. The EOL starts with the CR. - */ - *eol = lineend - 1; - } else { - /* - * No. The EOL starts with the LF. - */ - *eol = lineend; - - /* - * I seem to remember that we once saw lines ending with LF-CR - * in an HTTP request or response, so check if it's *followed* - * by a carriage return. - */ - if (lineend < (dataend - 1) && *(lineend + 1) == '\r') { - /* - * It's <non-LF><LF><CR>; say it ends with the CR. - */ - lineend++; - } - } - } - - /* - * Point to the character after the last character. - */ - lineend++; - } - return lineend; -} - -#define MAX_COLUMNS_LINE_DETAIL 62 - -/* - * Get the length of the next token in a line, and the beginning of the - * next token after that (if any). - * Return 0 if there is no next token. - */ -int -get_token_len(const u_char *linep, const u_char *lineend, - const u_char **next_token) -{ - const u_char *tokenp; - int token_len; - - tokenp = linep; - - /* - * Search for a blank, a CR or an LF, or the end of the buffer. - */ - while (linep < lineend && *linep != ' ' && *linep != '\r' && *linep != '\n') - linep++; - token_len = linep - tokenp; - - /* - * Skip trailing blanks. - */ - while (linep < lineend && *linep == ' ') - linep++; - - *next_token = linep; - - return token_len; -} - -/* - * Given a string, generate a string from it that shows non-printable - * characters as C-style escapes, and return a pointer to it. - */ -gchar * -format_text(const u_char *string, int len) -{ - static gchar fmtbuf[MAX_COLUMNS_LINE_DETAIL + 3 + 4 + 1]; - gchar *fmtbufp; - int column; - const u_char *stringend = string + len; - u_char c; - int i; - - column = 0; - fmtbufp = &fmtbuf[0]; - while (string < stringend) { - if (column >= MAX_COLUMNS_LINE_DETAIL) { - /* - * Put "..." and quit. - */ - strcpy(fmtbufp, " ..."); - fmtbufp += 4; - break; - } - c = *string++; - if (isprint(c)) { - *fmtbufp++ = c; - column++; - } else { - *fmtbufp++ = '\\'; - column++; - switch (c) { - - case '\\': - *fmtbufp++ = '\\'; - column++; - break; - - case '\a': - *fmtbufp++ = 'a'; - column++; - break; - - case '\b': - *fmtbufp++ = 'b'; - column++; - break; - - case '\f': - *fmtbufp++ = 'f'; - column++; - break; - - case '\n': - *fmtbufp++ = 'n'; - column++; - break; - - case '\r': - *fmtbufp++ = 'r'; - column++; - break; - - case '\t': - *fmtbufp++ = 't'; - column++; - break; - - case '\v': - *fmtbufp++ = 'v'; - column++; - break; - - default: - i = (c>>6)&03; - *fmtbufp++ = i + '0'; - column++; - i = (c>>3)&07; - *fmtbufp++ = i + '0'; - column++; - i = (c>>0)&07; - *fmtbufp++ = i + '0'; - column++; - break; - } - } - } - *fmtbufp = '\0'; - return fmtbuf; -} - /* Tries to match val against each element in the value_string array vs. Returns the associated string ptr on a match. |