Add a "val_to_str()" routine that calls "match_strval()" and, if
it returns NULL, formats the value with the format passed in as an argument, and returns a pointer to that static buffer. Change several "match_strval()" calls to use "val_to_str()". In "dissect_ospf()", use "match_strval()" to look up the packet type, and use "Unknown" if it doesn't find a match. svn path=/trunk/; revision=66
This commit is contained in:
parent
7867e7441d
commit
0bb16cb989
|
@ -82,19 +82,8 @@ dissect_ddp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
|
|||
|
||||
if (fd->win_info[COL_NUM]) {
|
||||
strcpy(fd->win_info[COL_PROTOCOL], "DDP");
|
||||
switch (ddp.type) {
|
||||
case DDP_RTMPDATA:
|
||||
case DDP_RTMPREQ:
|
||||
case DDP_NBP:
|
||||
case DDP_ATP:
|
||||
case DDP_AEP:
|
||||
case DDP_ZIP:
|
||||
case DDP_ADSP:
|
||||
strcpy(fd->win_info[COL_INFO], match_strval(ddp.type,op_vals));
|
||||
break;
|
||||
default:
|
||||
sprintf(fd->win_info[COL_INFO], "Unknown DDP protocol (%02x)", ddp.type);
|
||||
}
|
||||
strcpy(fd->win_info[COL_INFO],
|
||||
val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
|
||||
|
||||
sprintf(fd->win_info[COL_SOURCE],"%d.%d:%d",ddp.snet,ddp.snode,ddp.sport);
|
||||
sprintf(fd->win_info[COL_DESTINATION], "%d.%d:%d",ddp.dnet,ddp.dnode,ddp.dport);
|
||||
|
|
28
packet-ip.c
28
packet-ip.c
|
@ -1,7 +1,7 @@
|
|||
/* packet-ip.c
|
||||
* Routines for IP and miscellaneous IP protocol packet disassembly
|
||||
*
|
||||
* $Id: packet-ip.c,v 1.8 1998/10/16 01:18:31 gerald Exp $
|
||||
* $Id: packet-ip.c,v 1.9 1998/10/20 05:31:00 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -53,7 +53,6 @@ dissect_ipopt_security(GtkWidget *opt_tree, const char *name,
|
|||
{
|
||||
GtkWidget *field_tree = NULL, *tf;
|
||||
guint val;
|
||||
gchar *secl_str;
|
||||
static value_string secl_vals[] = {
|
||||
{IPSEC_UNCLASSIFIED, "Unclassified"},
|
||||
{IPSEC_CONFIDENTIAL, "Confidential"},
|
||||
|
@ -78,12 +77,8 @@ dissect_ipopt_security(GtkWidget *opt_tree, const char *name,
|
|||
offset += 2;
|
||||
|
||||
val = pntohs(opd);
|
||||
if ((secl_str = match_strval(val, secl_vals)))
|
||||
add_item_to_tree(field_tree, offset, 2,
|
||||
"Security: %s", secl_str);
|
||||
else
|
||||
add_item_to_tree(field_tree, offset, 2,
|
||||
"Security: Unknown (0x%x)", val);
|
||||
add_item_to_tree(field_tree, offset, 2,
|
||||
"Security: %s", val_to_str(val, secl_vals, "Unknown (0x%x)"));
|
||||
offset += 2;
|
||||
opd += 2;
|
||||
|
||||
|
@ -166,7 +161,6 @@ dissect_ipopt_timestamp(GtkWidget *opt_tree, const char *name, const u_char *opd
|
|||
int ptr;
|
||||
int optoffset = 0;
|
||||
int flg;
|
||||
gchar *flg_str;
|
||||
static value_string flag_vals[] = {
|
||||
{IPOPT_TS_TSONLY, "Time stamps only" },
|
||||
{IPOPT_TS_TSANDADDR, "Time stamp and address" },
|
||||
|
@ -197,12 +191,8 @@ dissect_ipopt_timestamp(GtkWidget *opt_tree, const char *name, const u_char *opd
|
|||
add_item_to_tree(field_tree, offset + optoffset, 1,
|
||||
"Overflow: %d", flg >> 4);
|
||||
flg &= 0xF;
|
||||
if ((flg_str = match_strval(flg, flag_vals)))
|
||||
add_item_to_tree(field_tree, offset + optoffset, 1,
|
||||
"Flag: %s", flg_str);
|
||||
else
|
||||
add_item_to_tree(field_tree, offset + optoffset, 1,
|
||||
"Flag: Unknown (0x%x)", flg);
|
||||
add_item_to_tree(field_tree, offset + optoffset, 1,
|
||||
"Flag: %s", val_to_str(flg, flag_vals, "Unknown (0x%x)"));
|
||||
optoffset++;
|
||||
opd++;
|
||||
optlen--;
|
||||
|
@ -396,7 +386,6 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
|
|||
GtkWidget *ip_tree, *ti, *field_tree, *tf;
|
||||
gchar tos_str[32];
|
||||
guint hlen, optlen;
|
||||
gchar *proto_str;
|
||||
static value_string proto_vals[] = { {IP_PROTO_ICMP, "ICMP"},
|
||||
{IP_PROTO_IGMP, "IGMP"},
|
||||
{IP_PROTO_TCP, "TCP" },
|
||||
|
@ -471,11 +460,8 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
|
|||
iph.ip_off & IP_OFFSET);
|
||||
add_item_to_tree(ip_tree, offset + 8, 1, "Time to live: %d",
|
||||
iph.ip_ttl);
|
||||
if ((proto_str = match_strval(iph.ip_p, proto_vals)))
|
||||
add_item_to_tree(ip_tree, offset + 9, 1, "Protocol: %s", proto_str);
|
||||
else
|
||||
add_item_to_tree(ip_tree, offset + 9, 1, "Protocol: Unknown (%x)",
|
||||
iph.ip_p);
|
||||
add_item_to_tree(ip_tree, offset + 9, 1, "Protocol: %s",
|
||||
val_to_str(iph.ip_p, proto_vals, "Unknown (%x)"));
|
||||
add_item_to_tree(ip_tree, offset + 10, 2, "Header checksum: 0x%04x",
|
||||
iph.ip_sum);
|
||||
add_item_to_tree(ip_tree, offset + 12, 4, "Source address: %s",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Routines for OSPF packet disassembly
|
||||
* (c) Copyright Hannes R. Boehm <hannes@boehm.org>
|
||||
*
|
||||
* $Id: packet-ospf.c,v 1.6 1998/10/13 07:03:34 guy Exp $
|
||||
* $Id: packet-ospf.c,v 1.7 1998/10/20 05:31:01 guy Exp $
|
||||
*
|
||||
* At this time, this module is able to analyze OSPF
|
||||
* packets as specified in RFC2328. MOSPF (RFC1584) and other
|
||||
|
@ -61,33 +61,22 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
|
|||
GtkWidget *ospf_header_tree;
|
||||
char auth_data[9]="";
|
||||
char *packet_type;
|
||||
static value_string pt_vals[] = { {OSPF_HELLO, "Hello Packet" },
|
||||
{OSPF_DB_DESC, "DB Descr." },
|
||||
{OSPF_LS_REQ, "LS Request" },
|
||||
{OSPF_LS_UPD, "LS Update" },
|
||||
{OSPF_LS_ACK, "LS Acknowledge" },
|
||||
{0, NULL } };
|
||||
|
||||
memcpy(&ospfh, &pd[offset], sizeof(e_ospfhdr));
|
||||
|
||||
switch(ospfh.packet_type) {
|
||||
case OSPF_HELLO:
|
||||
packet_type="Hello Packet";
|
||||
break;
|
||||
case OSPF_DB_DESC:
|
||||
packet_type="DB Descr.";
|
||||
break;
|
||||
case OSPF_LS_REQ:
|
||||
packet_type="LS Request";
|
||||
break;
|
||||
case OSPF_LS_UPD:
|
||||
packet_type="LS Update";
|
||||
break;
|
||||
case OSPF_LS_ACK:
|
||||
packet_type="LS Acknowledge";
|
||||
break;
|
||||
default:
|
||||
/* XXX - set it to some string with the value of
|
||||
"ospfh.packet_type"? */
|
||||
break;
|
||||
}
|
||||
packet_type = match_strval(ospfh.packet_type, pt_vals);
|
||||
if (fd->win_info[COL_NUM]) {
|
||||
strcpy(fd->win_info[COL_PROTOCOL], "OSPF");
|
||||
sprintf(fd->win_info[COL_INFO], "%s", packet_type);
|
||||
if (packet_type != NULL)
|
||||
sprintf(fd->win_info[COL_INFO], "%s", packet_type);
|
||||
else
|
||||
sprintf(fd->win_info[COL_INFO], "Unknown (%d)", ospfh.packet_type);
|
||||
}
|
||||
|
||||
if (tree) {
|
||||
|
@ -101,7 +90,10 @@ dissect_ospf(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
|
|||
|
||||
add_item_to_tree(ospf_header_tree, offset, 1, "OSPF Version: %d", ospfh.version);
|
||||
add_item_to_tree(ospf_header_tree, offset + 1 , 1, "OSPF Packet Type: %d (%s)",
|
||||
ospfh.packet_type, packet_type);
|
||||
ospfh.packet_type,
|
||||
(packet_type != NULL ?
|
||||
packet_type :
|
||||
"Unknown"));
|
||||
add_item_to_tree(ospf_header_tree, offset + 2 , 2, "Packet Legth: %d",
|
||||
ntohs(ospfh.length));
|
||||
add_item_to_tree(ospf_header_tree, offset + 4 , 4, "Source OSPF Router ID: %s",
|
||||
|
|
28
packet.c
28
packet.c
|
@ -1,7 +1,7 @@
|
|||
/* packet.c
|
||||
* Routines for packet disassembly
|
||||
*
|
||||
* $Id: packet.c,v 1.7 1998/10/16 01:18:32 gerald Exp $
|
||||
* $Id: packet.c,v 1.8 1998/10/20 05:31:02 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -195,8 +195,30 @@ collapse_tree(GtkWidget *w, gpointer data) {
|
|||
}
|
||||
|
||||
/* Tries to match val against each element in the value_string array vs.
|
||||
Returns the associated string ptr on a match, or NULL on failure.
|
||||
Len is the length of the array. */
|
||||
Returns the associated string ptr on a match.
|
||||
Formats val with fmt, and returns the resulting string, on failure. */
|
||||
gchar*
|
||||
val_to_str(guint32 val, value_string *vs, char *fmt) {
|
||||
gchar *ret;
|
||||
static gchar str[3][64];
|
||||
static gchar *cur;
|
||||
|
||||
ret = match_strval(val, vs);
|
||||
if (ret != NULL)
|
||||
return ret;
|
||||
if (cur == &str[0][0]) {
|
||||
cur = &str[1][0];
|
||||
} else if (cur == &str[1][0]) {
|
||||
cur = &str[2][0];
|
||||
} else {
|
||||
cur = &str[0][0];
|
||||
}
|
||||
snprintf(cur, 64, fmt, val);
|
||||
return cur;
|
||||
}
|
||||
|
||||
/* Tries to match val against each element in the value_string array vs.
|
||||
Returns the associated string ptr on a match, or NULL on failure. */
|
||||
gchar*
|
||||
match_strval(guint32 val, value_string *vs) {
|
||||
gint i = 0;
|
||||
|
|
3
packet.h
3
packet.h
|
@ -1,7 +1,7 @@
|
|||
/* packet.h
|
||||
* Definitions for packet disassembly structures and routines
|
||||
*
|
||||
* $Id: packet.h,v 1.20 1998/10/16 06:46:55 guy Exp $
|
||||
* $Id: packet.h,v 1.21 1998/10/20 05:31:03 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -486,6 +486,7 @@ GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...)
|
|||
#else
|
||||
GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...);
|
||||
#endif
|
||||
gchar* val_to_str(guint32 val, value_string *vs, char *fmt);
|
||||
gchar* match_strval(guint32, value_string*);
|
||||
|
||||
/* Routines in packet.c */
|
||||
|
|
Loading…
Reference in New Issue