forked from osmocom/wireshark
Move the bitfield-decoding routines to "packet.h", along with other
helper routines for packet dissecting, and away from "util.c", which is now all GUI-related. (Among other things, this makes life more pleasant for Gilbert Ramirez's "tethereal" stuff, although a lot more separation of GUI from other stuff needs to be done to make that - or a "curses"-based variant of Ethereal, or a variant using some other GUI toolkit - work smoothly.) svn path=/trunk/; revision=235
This commit is contained in:
parent
ccba477d7f
commit
f1e024b605
82
packet.c
82
packet.c
|
@ -1,7 +1,7 @@
|
|||
/* packet.c
|
||||
* Routines for packet disassembly
|
||||
*
|
||||
* $Id: packet.c,v 1.23 1999/03/30 04:41:01 guy Exp $
|
||||
* $Id: packet.c,v 1.24 1999/03/31 08:20:28 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -360,6 +360,86 @@ match_strval(guint32 val, const value_string *vs) {
|
|||
return(NULL);
|
||||
}
|
||||
|
||||
/* Generate, into "buf", a string showing the bits of a bitfield.
|
||||
Return a pointer to the character after that string. */
|
||||
static char *
|
||||
decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width)
|
||||
{
|
||||
int i;
|
||||
guint32 bit;
|
||||
char *p;
|
||||
|
||||
i = 0;
|
||||
p = buf;
|
||||
bit = 1 << (width - 1);
|
||||
for (;;) {
|
||||
if (mask & bit) {
|
||||
/* This bit is part of the field. Show its value. */
|
||||
if (val & bit)
|
||||
*p++ = '1';
|
||||
else
|
||||
*p++ = '0';
|
||||
} else {
|
||||
/* This bit is not part of the field. */
|
||||
*p++ = '.';
|
||||
}
|
||||
bit >>= 1;
|
||||
i++;
|
||||
if (i >= width)
|
||||
break;
|
||||
if (i % 4 == 0)
|
||||
*p++ = ' ';
|
||||
}
|
||||
strcpy(p, " = ");
|
||||
p += 3;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Generate a string describing a Boolean bitfield (a one-bit field that
|
||||
says something is either true of false). */
|
||||
const char *
|
||||
decode_boolean_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *truedesc, const char *falsedesc)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
if (val & mask)
|
||||
strcpy(p, truedesc);
|
||||
else
|
||||
strcpy(p, falsedesc);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Generate a string describing an enumerated bitfield (an N-bit field
|
||||
with various specific values having particular names). */
|
||||
const char *
|
||||
decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
|
||||
const value_string *tab, const char *fmt)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
sprintf(p, fmt, val_to_str(val & mask, tab, "Unknown"));
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Generate a string describing a numeric bitfield (an N-bit field whose
|
||||
value is just a number). */
|
||||
const char *
|
||||
decode_numeric_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *fmt)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
sprintf(p, fmt, val & mask);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Checks to see if a particular packet information element is needed for
|
||||
the packet list */
|
||||
gint
|
||||
|
|
8
packet.h
8
packet.h
|
@ -1,7 +1,7 @@
|
|||
/* packet.h
|
||||
* Definitions for packet disassembly structures and routines
|
||||
*
|
||||
* $Id: packet.h,v 1.43 1999/03/30 04:41:00 guy Exp $
|
||||
* $Id: packet.h,v 1.44 1999/03/31 08:20:27 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -243,6 +243,12 @@ int get_token_len(const u_char *linep, const u_char *lineend,
|
|||
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*);
|
||||
const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *truedesc, const char *falsedesc);
|
||||
const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
|
||||
const value_string *tab, const char *fmt);
|
||||
const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *fmt);
|
||||
gint check_col(frame_data *, gint);
|
||||
#if __GNUC__ == 2
|
||||
void col_add_fstr(frame_data *, gint, gchar *, ...)
|
||||
|
|
87
util.c
87
util.c
|
@ -1,7 +1,7 @@
|
|||
/* util.c
|
||||
* Utility routines
|
||||
*
|
||||
* $Id: util.c,v 1.11 1999/03/23 03:14:46 gram Exp $
|
||||
* $Id: util.c,v 1.12 1999/03/31 08:20:28 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -27,10 +27,6 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -48,7 +44,6 @@
|
|||
# include "snprintf.h"
|
||||
#endif
|
||||
|
||||
#include "packet.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "image/icon-excl.xpm"
|
||||
|
@ -172,83 +167,3 @@ simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
|
|||
*btn_mask = ESD_BTN_CANCEL;
|
||||
gtk_widget_destroy(GTK_WIDGET(win));
|
||||
}
|
||||
|
||||
/* Generate, into "buf", a string showing the bits of a bitfield.
|
||||
Return a pointer to the character after that string. */
|
||||
static char *
|
||||
decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width)
|
||||
{
|
||||
int i;
|
||||
guint32 bit;
|
||||
char *p;
|
||||
|
||||
i = 0;
|
||||
p = buf;
|
||||
bit = 1 << (width - 1);
|
||||
for (;;) {
|
||||
if (mask & bit) {
|
||||
/* This bit is part of the field. Show its value. */
|
||||
if (val & bit)
|
||||
*p++ = '1';
|
||||
else
|
||||
*p++ = '0';
|
||||
} else {
|
||||
/* This bit is not part of the field. */
|
||||
*p++ = '.';
|
||||
}
|
||||
bit >>= 1;
|
||||
i++;
|
||||
if (i >= width)
|
||||
break;
|
||||
if (i % 4 == 0)
|
||||
*p++ = ' ';
|
||||
}
|
||||
strcpy(p, " = ");
|
||||
p += 3;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Generate a string describing a Boolean bitfield (a one-bit field that
|
||||
says something is either true of false). */
|
||||
const char *
|
||||
decode_boolean_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *truedesc, const char *falsedesc)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
if (val & mask)
|
||||
strcpy(p, truedesc);
|
||||
else
|
||||
strcpy(p, falsedesc);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Generate a string describing an enumerated bitfield (an N-bit field
|
||||
with various specific values having particular names). */
|
||||
const char *
|
||||
decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
|
||||
const value_string *tab, const char *fmt)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
sprintf(p, fmt, val_to_str(val & mask, tab, "Unknown"));
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Generate a string describing a numeric bitfield (an N-bit field whose
|
||||
value is just a number). */
|
||||
const char *
|
||||
decode_numeric_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *fmt)
|
||||
{
|
||||
static char buf[1025];
|
||||
char *p;
|
||||
|
||||
p = decode_bitfield_value(buf, val, mask, width);
|
||||
sprintf(p, fmt, val & mask);
|
||||
return buf;
|
||||
}
|
||||
|
|
12
util.h
12
util.h
|
@ -1,7 +1,7 @@
|
|||
/* util.h
|
||||
* Utility definitions
|
||||
*
|
||||
* $Id: util.h,v 1.7 1999/03/23 03:14:46 gram Exp $
|
||||
* $Id: util.h,v 1.8 1999/03/31 08:20:28 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -46,16 +46,6 @@ void simple_dialog(gint, gint *, gchar *, ...)
|
|||
void simple_dialog(gint, gint *, gchar *, ...);
|
||||
#endif
|
||||
|
||||
|
||||
const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *truedesc, const char *falsedesc);
|
||||
|
||||
const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
|
||||
const value_string *tab, const char *fmt);
|
||||
|
||||
const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
|
||||
const char *fmt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
Loading…
Reference in New Issue