forked from osmocom/wireshark
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
This commit is contained in:
parent
bf98417be0
commit
9941aabd64
|
@ -1,7 +1,7 @@
|
|||
# Makefile.am
|
||||
# Automake file for Ethereal
|
||||
#
|
||||
# $Id: Makefile.am,v 1.225 2000/08/30 12:42:30 sharpe Exp $
|
||||
# $Id: Makefile.am,v 1.226 2000/09/11 16:16:00 gram Exp $
|
||||
#
|
||||
# Ethereal - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@zing.org>
|
||||
|
@ -306,6 +306,8 @@ ETHEREAL_COMMON_SOURCES = \
|
|||
resolv.c \
|
||||
resolv.h \
|
||||
smb.h \
|
||||
strutil.c \
|
||||
strutil.h \
|
||||
timestamp.h \
|
||||
tvbuff.c \
|
||||
tvbuff.h \
|
||||
|
@ -472,8 +474,8 @@ randpkt.o: randpkt.c
|
|||
randpkt: randpkt.o wiretap/libwiretap.a
|
||||
$(LINK) -o randpkt randpkt.o wiretap/libwiretap.a `glib-config --libs` -lz
|
||||
|
||||
tvbtest: tvbtest.o tvbuff.o except.o
|
||||
$(LINK) -o tvbtest tvbtest.o tvbuff.o except.o `glib-config --libs`
|
||||
tvbtest: tvbtest.o tvbuff.o except.o strutil.o
|
||||
$(LINK) -o tvbtest tvbtest.o tvbuff.o except.o strutil.o `glib-config --libs`
|
||||
|
||||
DISTCLEANFILES = \
|
||||
register.c \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## Makefile for building ethereal.exe with Microsoft C and nmake
|
||||
## Use: nmake -f makefile.nmake
|
||||
#
|
||||
# $Id: Makefile.nmake,v 1.53 2000/08/18 15:26:52 gram Exp $
|
||||
# $Id: Makefile.nmake,v 1.54 2000/09/11 16:16:01 gram Exp $
|
||||
|
||||
include config.nmake
|
||||
|
||||
|
@ -177,6 +177,7 @@ ETHEREAL_COMMON_OBJECTS = \
|
|||
ptvcursor.obj \
|
||||
register.obj \
|
||||
resolv.obj \
|
||||
strutil.obj \
|
||||
tvbuff.obj \
|
||||
util.obj \
|
||||
xdlc.obj \
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for ftp packet dissection
|
||||
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
* $Id: packet-ftp.c,v 1.18 2000/08/13 14:08:11 deniel Exp $
|
||||
* $Id: packet-ftp.c,v 1.19 2000/09/11 16:16:01 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_ftp = -1;
|
||||
static int hf_ftp_response = -1;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Guy Harris <guy@alum.mit.edu>
|
||||
*
|
||||
* $Id: packet-http.c,v 1.21 2000/08/13 14:08:12 deniel Exp $
|
||||
* $Id: packet-http.c,v 1.22 2000/09/11 16:16:02 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -41,6 +41,7 @@
|
|||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "packet-ipp.h"
|
||||
#include "strutil.h"
|
||||
|
||||
typedef enum _http_type {
|
||||
HTTP_REQUEST,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for nntp packet dissection
|
||||
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
* $Id: packet-nntp.c,v 1.12 2000/08/13 14:08:31 deniel Exp $
|
||||
* $Id: packet-nntp.c,v 1.13 2000/09/11 16:16:02 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -40,6 +40,7 @@
|
|||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_nntp = -1;
|
||||
static int hf_nntp_response = -1;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Robert Tsai <rtsai@netapp.com>
|
||||
* Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
|
||||
*
|
||||
* $Id: packet-rsh.c,v 1.3 2000/08/13 14:08:43 deniel Exp $
|
||||
* $Id: packet-rsh.c,v 1.4 2000/09/11 16:16:02 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_rsh = -1;
|
||||
static int hf_rsh_response = -1;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Jason Lango <jal@netapp.com>
|
||||
*
|
||||
* $Id: packet-rtcp.c,v 1.4 2000/08/13 14:08:43 deniel Exp $
|
||||
* $Id: packet-rtcp.c,v 1.5 2000/09/11 16:16:02 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "packet-rtcp.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_rtcp = -1;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Jason Lango <jal@netapp.com>
|
||||
* Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
|
||||
*
|
||||
* $Id: packet-rtsp.c,v 1.17 2000/08/21 18:36:33 guy Exp $
|
||||
* $Id: packet-rtsp.c,v 1.18 2000/09/11 16:16:03 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include "packet-rtp.h"
|
||||
#include "packet-rtcp.h"
|
||||
#include "conversation.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_rtsp = -1;
|
||||
static gint ett_rtsp = -1;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Jason Lango <jal@netapp.com>
|
||||
* Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
|
||||
*
|
||||
* $Id: packet-sdp.c,v 1.9 2000/08/13 14:08:46 deniel Exp $
|
||||
* $Id: packet-sdp.c,v 1.10 2000/09/11 16:16:03 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_sdp = -1;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for smb packet dissection
|
||||
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
* $Id: packet-smb-pipe.c,v 1.10 2000/08/13 14:08:49 deniel Exp $
|
||||
* $Id: packet-smb-pipe.c,v 1.11 2000/09/11 16:16:03 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -47,6 +47,7 @@
|
|||
#include "conversation.h"
|
||||
#include "smb.h"
|
||||
#include "alignment.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_smb_lanman = -1;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for smb packet dissection
|
||||
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
* $Id: packet-smb.c,v 1.71 2000/08/13 14:08:50 deniel Exp $
|
||||
* $Id: packet-smb.c,v 1.72 2000/09/11 16:16:04 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -47,6 +47,7 @@
|
|||
#include "conversation.h"
|
||||
#include "smb.h"
|
||||
#include "alignment.h"
|
||||
#include "strutil.h"
|
||||
|
||||
guint32 dissect_mailslot_smb(const u_char *, int, frame_data *, proto_tree *, proto_tree *, struct smb_info, int, int, int, int, const u_char *, int, int, int, int);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* packet-smtp.c
|
||||
* Routines for SMTP packet disassembly
|
||||
*
|
||||
* $Id: packet-smtp.c,v 1.5 2000/08/26 11:25:28 sharpe Exp $
|
||||
* $Id: packet-smtp.c,v 1.6 2000/09/11 16:16:07 gram Exp $
|
||||
*
|
||||
* Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
|
@ -45,6 +45,7 @@
|
|||
#include "conversation.h"
|
||||
#include "resolv.h"
|
||||
#include "prefs.h"
|
||||
#include "strutil.h"
|
||||
|
||||
#define TCP_PORT_SMTP 25
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for socks versions 4 &5 packet dissection
|
||||
* Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
|
||||
*
|
||||
* $Id: packet-socks.c,v 1.11 2000/08/21 18:36:33 guy Exp $
|
||||
* $Id: packet-socks.c,v 1.12 2000/09/11 16:16:07 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -76,6 +76,7 @@
|
|||
|
||||
#include "packet-tcp.h"
|
||||
#include "packet-udp.h"
|
||||
#include "strutil.h"
|
||||
|
||||
|
||||
#define CHECK_PACKET_LENGTH(X) if (!BYTES_ARE_IN_FRAME(offset, X)){ \
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* In particular I have not had an opportunity to see how it
|
||||
* responds to SRVLOC over TCP.
|
||||
*
|
||||
* $Id: packet-srvloc.c,v 1.14 2000/08/13 14:09:02 deniel Exp $
|
||||
* $Id: packet-srvloc.c,v 1.15 2000/09/11 16:16:08 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -54,6 +54,7 @@
|
|||
|
||||
#include "packet.h"
|
||||
#include "packet-ipv6.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_srvloc = -1;
|
||||
static int hf_srvloc_version = -1;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* packet-tcp.c
|
||||
* Routines for TCP packet disassembly
|
||||
*
|
||||
* $Id: packet-tcp.c,v 1.81 2000/08/13 14:08:47 deniel Exp $
|
||||
* $Id: packet-tcp.c,v 1.82 2000/09/11 16:16:10 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -50,6 +50,7 @@
|
|||
#include "packet-tcp.h"
|
||||
#include "packet-ip.h"
|
||||
#include "conversation.h"
|
||||
#include "strutil.h"
|
||||
|
||||
/* Place TCP summary in proto tree */
|
||||
gboolean g_tcp_summary_in_tree = TRUE;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for telnet packet dissection
|
||||
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
|
||||
*
|
||||
* $Id: packet-telnet.c,v 1.15 2000/08/13 14:08:44 deniel Exp $
|
||||
* $Id: packet-telnet.c,v 1.16 2000/09/11 16:16:11 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -42,6 +42,7 @@
|
|||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "packet.h"
|
||||
#include "strutil.h"
|
||||
|
||||
static int proto_telnet = -1;
|
||||
|
||||
|
|
188
packet.c
188
packet.c
|
@ -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.
|
||||
|
|
7
packet.h
7
packet.h
|
@ -1,7 +1,7 @@
|
|||
/* packet.h
|
||||
* Definitions for packet disassembly structures and routines
|
||||
*
|
||||
* $Id: packet.h,v 1.200 2000/09/10 06:44:36 guy Exp $
|
||||
* $Id: packet.h,v 1.201 2000/09/11 16:16:12 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -252,11 +252,6 @@ gchar* abs_time_to_str(struct timeval*);
|
|||
gchar* rel_time_to_str(struct timeval*);
|
||||
gchar* time_secs_to_str(guint32);
|
||||
gchar* bytes_to_str(const guint8 *, int);
|
||||
const u_char *find_line_end(const u_char *data, const u_char *dataend,
|
||||
const u_char **eol);
|
||||
int get_token_len(const u_char *linep, const u_char *lineend,
|
||||
const u_char **next_token);
|
||||
gchar* format_text(const u_char *line, int len);
|
||||
gchar* val_to_str(guint32, const value_string *, const char *);
|
||||
gchar* match_strval(guint32, const value_string*);
|
||||
char * decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width);
|
||||
|
|
|
@ -0,0 +1,221 @@
|
|||
/* strutil.c
|
||||
* String utility routines
|
||||
*
|
||||
* $Id: strutil.c,v 1.1 2000/09/11 16:16:13 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <glib.h>
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
#define MAX_COLUMNS_LINE_DETAIL 62
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/* util.h
|
||||
* Utility definitions
|
||||
*
|
||||
* $Id: strutil.h,v 1.1 2000/09/11 16:16:13 gram Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __STRUTIL_H__
|
||||
#define __STRUTIL_H__
|
||||
|
||||
const u_char *find_line_end(const u_char *data, const u_char *dataend,
|
||||
const u_char **eol);
|
||||
int get_token_len(const u_char *linep, const u_char *lineend,
|
||||
const u_char **next_token);
|
||||
gchar* format_text(const u_char *line, int len);
|
||||
|
||||
|
||||
#endif /* __STRUTIL_H__ */
|
5
tvbuff.c
5
tvbuff.c
|
@ -9,7 +9,7 @@
|
|||
* the data of a backing tvbuff, or can be a composite of
|
||||
* other tvbuffs.
|
||||
*
|
||||
* $Id: tvbuff.c,v 1.13 2000/09/11 07:33:56 sharpe Exp $
|
||||
* $Id: tvbuff.c,v 1.14 2000/09/11 16:16:13 gram Exp $
|
||||
*
|
||||
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
|
||||
*
|
||||
|
@ -37,8 +37,7 @@
|
|||
|
||||
#include "pint.h"
|
||||
#include "tvbuff.h"
|
||||
#include "packet.h"
|
||||
|
||||
#include "strutil.h"
|
||||
|
||||
typedef struct {
|
||||
/* The backing tvbuff_t */
|
||||
|
|
Loading…
Reference in New Issue