implement ipprotostr() in ipproto.c, which basically does ipprotobynumber()

for ip.ip_p and ip6.ip6_nxt (and other IPv6 header chain).

use val_to_str() as much as possible in dissect_{ipv6,pim,ripng}().

make --disable-zlib a default for netbsd (temporary workaround).

svn path=/trunk/; revision=827
This commit is contained in:
Jun-ichiro itojun Hagino 1999-10-14 03:50:51 +00:00
parent 92907001c3
commit 810a67a6d0
10 changed files with 209 additions and 76 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
# $Id: Makefile.am,v 1.83 1999/10/14 01:28:27 guy Exp $
# $Id: Makefile.am,v 1.84 1999/10/14 03:50:26 itojun Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@ -53,6 +53,7 @@ ethereal_SOURCES = \
follow.c \
follow.h \
globals.h \
ipproto.c \
packet-aarp.c \
packet-arp.c \
packet-ascend.c\

View File

@ -1,4 +1,4 @@
# $Id: configure.in,v 1.49 1999/10/11 07:38:21 guy Exp $
# $Id: configure.in,v 1.50 1999/10/14 03:50:27 itojun Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT(etypes.h)
@ -73,7 +73,11 @@ fi
dnl zlib check
AC_ARG_ENABLE(zlib,
[ --enable-zlib use zlib to read compressed data. [default=yes]],,enable_zlib=yes)
[ --enable-zlib use zlib to read compressed data. [default=yes]],, [dnl
case "$host_os" in
netbsd*) enable_zlib=no;;
*) enable_zlib=yes;;
esac])
AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
if test "x$enable_zlib" = "xno" ; then
@ -192,6 +196,8 @@ fi
AC_SUBST(INET_ATON_C)
AC_SUBST(INET_ATON_O)
AC_CHECK_FUNCS(getprotobynumber)
dnl blank for now, but will be used in future
AC_SUBST(ethereal_SUBDIRS)

118
ipproto.c Normal file
View File

@ -0,0 +1,118 @@
/* ipproto.c
* Routines for converting IPv4 protocol/v6 nxthdr field into string
*
* $Id: ipproto.c,v 1.1 1999/10/14 03:50:27 itojun Exp $
*
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
*
* 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
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
# include <stdarg.h>
# else
# include <varargs.h>
# endif
# include "snprintf.h"
#endif
#include <glib.h>
#include "packet.h"
#include "etypes.h"
#include "packet-ip.h"
#include "packet-ipv6.h"
static const value_string ipproto_val[] = {
{ IP_PROTO_ICMP, "ICMP" },
{ IP_PROTO_IGMP, "IGMP" },
{ IP_PROTO_TCP, "TCP" },
{ IP_PROTO_UDP, "UDP" },
{ IP_PROTO_OSPF, "OSPF" },
#if 0
{ IP_PROTO_IP, "IPv4" },
#endif
{ IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" },
{ IP_PROTO_ICMP, "ICMP" },
{ IP_PROTO_IGMP, "IGMP" },
{ IP_PROTO_GGP, "GGP" },
{ IP_PROTO_IPIP, "IPIP" },
{ IP_PROTO_IPV4, "IPv4" },
{ IP_PROTO_TCP, "TCP" },
{ IP_PROTO_EGP, "EGP" },
{ IP_PROTO_PUP, "PUP" },
{ IP_PROTO_UDP, "UDP" },
{ IP_PROTO_IDP, "IDP" },
{ IP_PROTO_TP, "TP" },
{ IP_PROTO_IPV6, "IPv6" },
{ IP_PROTO_ROUTING, "IPv6 routing" },
{ IP_PROTO_FRAGMENT, "IPv6 fragment" },
{ IP_PROTO_RSVP, "RSVP" },
{ IP_PROTO_GRE, "GRE" },
{ IP_PROTO_ESP, "ESP" },
{ IP_PROTO_AH, "AH" },
{ IP_PROTO_ICMPV6, "ICMPv6" },
{ IP_PROTO_NONE, "IPv6 no next header" },
{ IP_PROTO_DSTOPTS, "IPv6 dstination option" },
{ IP_PROTO_EON, "EON" },
{ IP_PROTO_OSPF, "OSPF" },
{ IP_PROTO_ENCAP, "ENCAP" },
{ IP_PROTO_PIM, "PIM" },
{ 0, NULL },
};
const char *ipprotostr(int proto) {
static char buf[128];
const char *s;
#ifdef HAVE_GETPROTOBYNUMBER
struct protoent *pe;
#endif
if ((s = val_to_str(proto, ipproto_val, NULL)) != NULL)
goto ok;
#ifdef HAVE_GETPROTOBYNUMBER
if (g_resolving_actif) {
pe = getprotobynumber(proto);
if (pe) {
s = pe->p_name;
goto ok;
}
}
#endif
s = "Unknown";
ok:
snprintf(buf, sizeof(buf), "%s", s);
return buf;
}

View File

@ -1,7 +1,7 @@
/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
* $Id: packet-ip.c,v 1.52 1999/10/13 06:47:44 guy Exp $
* $Id: packet-ip.c,v 1.53 1999/10/14 03:50:27 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -717,7 +717,8 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (check_col(fd, COL_PROTOCOL))
col_add_str(fd, COL_PROTOCOL, "IP");
if (check_col(fd, COL_INFO))
col_add_fstr(fd, COL_INFO, "Unknown IP protocol (0x%02x)", iph.ip_p);
col_add_fstr(fd, COL_INFO, "%s (0x%02x)",
ipprotostr(iph.ip_p), iph.ip_p);
}
if (check_col(fd, COL_RES_NET_SRC))
@ -800,7 +801,8 @@ dissect_ip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree_add_item(ip_tree, hf_ip_frag_offset, offset + 6, 2,
iph.ip_off & IP_OFFSET);
proto_tree_add_item(ip_tree, hf_ip_ttl, offset + 8, 1, iph.ip_ttl);
proto_tree_add_item(ip_tree, hf_ip_proto, offset + 9, 1, iph.ip_p);
proto_tree_add_item_format(ip_tree, hf_ip_proto, offset + 9, 1, iph.ip_p,
"Protocol: %s (0x%02x)", ipprotostr(iph.ip_p), iph.ip_p);
proto_tree_add_item_format(ip_tree, hf_ip_checksum, offset + 10, 2, iph.ip_sum,
"Header checksum: 0x%04x", iph.ip_sum);

View File

@ -1,7 +1,7 @@
/* packet-ipsec.c
* Routines for IPsec packet disassembly
*
* $Id: packet-ipsec.c,v 1.5 1999/10/12 06:20:09 gram Exp $
* $Id: packet-ipsec.c,v 1.6 1999/10/14 03:50:29 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -96,7 +96,7 @@ dissect_ah(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
ah_tree = proto_item_add_subtree(ti, ETT_AH);
proto_tree_add_text(ah_tree, offset + offsetof(struct newah, ah_nxt), 1,
"Next Header: %d", ah.ah_nxt);
"Next Header: %s (0x%02x)", ipprotostr(ah.ah_nxt), ah.ah_nxt);
proto_tree_add_text(ah_tree, offset + offsetof(struct newah, ah_len), 1,
"Length: %d", ah.ah_len << 2);
proto_tree_add_item_format(ah_tree, hf_ah_spi,

View File

@ -1,7 +1,7 @@
/* packet-ipv6.c
* Routines for IPv6 packet disassembly
*
* $Id: packet-ipv6.c,v 1.18 1999/10/13 06:47:47 guy Exp $
* $Id: packet-ipv6.c,v 1.19 1999/10/14 03:50:29 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -80,7 +80,7 @@ dissect_routing6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
proto_tree_add_text(rthdr_tree,
offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
"Next header: 0x%02x", rt.ip6r_nxt);
"Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
proto_tree_add_text(rthdr_tree,
offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
"Length: %d (%d bytes)", rt.ip6r_len, len);
@ -130,8 +130,9 @@ dissect_frag6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (check_col(fd, COL_INFO)) {
col_add_fstr(fd, COL_INFO,
"IPv6 fragment (nxt=0x%02x off=0x%04x id=0x%x)",
frag.ip6f_nxt, (frag.ip6f_offlg >> 3) & 0x1fff, frag.ip6f_ident);
"IPv6 fragment (nxt=%s (0x%02x) off=0x%04x id=0x%x)",
ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
(frag.ip6f_offlg >> 3) & 0x1fff, frag.ip6f_ident);
}
return len;
}
@ -144,6 +145,10 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
proto_tree *dstopt_tree;
proto_item *ti;
u_char *p;
static const value_string rtalertvals[] = {
{ IP6OPT_RTALERT_MLD, "MLD" },
{ IP6OPT_RTALERT_RSVP, "RSVP" },
};
memcpy(&ext, (void *) &pd[offset], sizeof(ext));
len = (ext.ip6e_len + 1) << 3;
@ -156,7 +161,7 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
proto_tree_add_text(dstopt_tree,
offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
"Next header: 0x%02x", ext.ip6e_nxt);
"Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt), ext.ip6e_nxt);
proto_tree_add_text(dstopt_tree,
offset + offsetof(struct ip6_ext, ip6e_len), 1,
"Length: %d (%d bytes)", ext.ip6e_len, len);
@ -182,7 +187,7 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
ntohl(*(guint32 *)&p[2]), p[1] + 2);
} else {
proto_tree_add_text(dstopt_tree, p - pd, p[1] + 2,
"Jumbo payload: invalid length (%d bytes)",
"Jumbo payload: Invalid length (%d bytes)",
p[1] + 2);
}
p += p[1];
@ -193,19 +198,10 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
char *rta;
if (p[1] == 2) {
switch (ntohs(*(guint16 *)&p[2])) {
case IP6OPT_RTALERT_MLD:
rta = "MLD";
break;
case IP6OPT_RTALERT_RSVP:
rta = "RSVP";
break;
default:
rta = "unknown";
break;
}
rta = val_to_str(ntohs(*(guint16 *)&p[2]), rtalertvals,
"Unknown");
} else
rta = "invalid length";
rta = "Invalid length";
ti = proto_tree_add_text(dstopt_tree, p - pd, p[1] + 2,
"Router alert: %s (%d bytes)", rta, p[1] + 2);
p += p[1];
@ -284,7 +280,8 @@ dissect_ipv6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree_add_text(ipv6_tree,
offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
"Next header: 0x%02x", ipv6.ip6_nxt);
"Next header: %s (0x%02x)",
ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
proto_tree_add_text(ipv6_tree,
offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
@ -369,8 +366,8 @@ again:
break;
default:
if (check_col(fd, COL_INFO)) {
col_add_fstr(fd, COL_INFO, "Unknown IPv6 protocol (0x%02x)",
ipv6.ip6_nxt);
col_add_fstr(fd, COL_INFO, "%s (0x%02x)",
ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
}
dissect_data(pd, offset, fd, tree);
}

View File

@ -2,7 +2,7 @@
* Routines for PIM disassembly
* (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
*
* $Id: packet-pim.c,v 1.3 1999/10/14 01:39:47 guy Exp $
* $Id: packet-pim.c,v 1.4 1999/10/14 03:50:30 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -159,13 +159,29 @@ dissect_pim_addr(const u_char *bp, const u_char *ep, enum pimv2_addrtype at,
void
dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
struct pim pim;
char *packet_type1[] = {
"Query", "Register", "Register-Stop", "Join/Prune", "RP-Reachable",
"Assert", "Graft", "Graft-Ack", "Mode"
static const value_string type1vals[] = {
{ 0, "Query" },
{ 1, "Register" },
{ 2, "Register-stop" },
{ 3, "Join/Prune" },
{ 4, "RP-Reachable" },
{ 5, "Assert" },
{ 6, "Graft" },
{ 7, "Graft-Ack" },
{ 8, "Mode" },
{ 0, NULL },
};
char *packet_type2[] = {
"Hello", "Register", "Register-Stop", "Join/Prune", "Bootstrap",
"Assert", "Graft", "Graft-Ack", "Candidate-RP-Advertisement"
static const value_string type2vals[] = {
{ 0, "Hello" },
{ 1, "Register" },
{ 2, "Register-stop" },
{ 3, "Join/Prune" },
{ 4, "Bootstrap" },
{ 5, "Assert" },
{ 6, "Graft" },
{ 7, "Graft-Ack" },
{ 8, "Candidate-RP-Advertisement" },
{ 0, NULL },
};
char *typestr;
proto_tree *pim_tree = NULL;
@ -176,17 +192,15 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
/* avoid alignment problem */
memcpy(&pim, &pd[offset], sizeof(pim));
typestr = NULL;
switch (PIM_VER(pim.pim_typever)) {
case 1:
if (PIM_TYPE(pim.pim_typever) < sizeof(packet_type1) / sizeof(packet_type1[0])) {
typestr = packet_type1[PIM_TYPE(pim.pim_typever)];
}
typestr = val_to_str(PIM_TYPE(pim.pim_typever), type1vals, "Unknown");
break;
case 2:
if (PIM_TYPE(pim.pim_typever) < sizeof(packet_type2) / sizeof(packet_type2[0])) {
typestr = packet_type2[PIM_TYPE(pim.pim_typever)];
}
typestr = val_to_str(PIM_TYPE(pim.pim_typever), type2vals, "Unknown");
break;
default:
typestr = "Unknown";
break;
}
@ -194,14 +208,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
col_add_fstr(fd, COL_PROTOCOL, "PIM version %d",
PIM_VER(pim.pim_typever));
}
if (check_col(fd, COL_INFO)) {
if (typestr)
col_add_str(fd, COL_INFO, typestr);
else {
col_add_fstr(fd, COL_INFO, "unknown type %d",
PIM_TYPE(pim.pim_typever));
}
}
if (check_col(fd, COL_INFO))
col_add_fstr(fd, COL_INFO, "%s", typestr);
if (tree) {
ti = proto_tree_add_item(tree, proto_pim, offset, END_OF_FRAME, NULL);
@ -209,13 +217,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree_add_text(pim_tree, offset, 1,
"Version: %d", PIM_VER(pim.pim_typever));
if (typestr) {
proto_tree_add_text(pim_tree, offset, 1,
"Type: %d (%s)", PIM_TYPE(pim.pim_typever), typestr);
} else {
proto_tree_add_text(pim_tree, offset, 1,
"Type: %d (unknown)", PIM_TYPE(pim.pim_typever));
}
proto_tree_add_text(pim_tree, offset, 1,
"Type: %s (%u)", typestr, PIM_TYPE(pim.pim_typever));
proto_tree_add_text(pim_tree, offset + offsetof(struct pim, pim_cksum),
sizeof(pim.pim_cksum),
@ -224,7 +227,7 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (sizeof(struct pim) < END_OF_FRAME) {
tiopt = proto_tree_add_text(pim_tree,
offset + sizeof(struct pim), END_OF_FRAME,
"PIM parameters", PIM_TYPE(pim.pim_typever), typestr);
"PIM parameters");
pimopt_tree = proto_item_add_subtree(tiopt, ETT_PIM);
} else
goto done;

View File

@ -3,7 +3,7 @@
* (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
* derived from packet-rip.c
*
* $Id: packet-ripng.c,v 1.2 1999/10/13 06:47:49 guy Exp $
* $Id: packet-ripng.c,v 1.3 1999/10/14 03:50:31 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -48,33 +48,29 @@ dissect_ripng(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
struct netinfo6 ni6;
proto_tree *ripng_tree = NULL;
proto_item *ti;
char *packet_type[] = { "*invalid*", "Request", "Response" };
char *cmd;
static const value_string cmdvals[] = {
{ RIP6_REQUEST, "Request" },
{ RIP6_RESPONSE, "Response" },
{ 0, NULL },
};
const char *cmd;
/* avoid alignment problem */
memcpy(&rip6, &pd[offset], sizeof(rip6));
switch (rip6.rip6_cmd) {
case RIP6_REQUEST:
case RIP6_RESPONSE:
cmd = packet_type[rip6.rip6_cmd];
break;
default:
cmd = packet_type[0];
break;
}
cmd = val_to_str(rip6.rip6_cmd, cmdvals, "Unknown");
if (check_col(fd, COL_PROTOCOL))
col_add_fstr(fd, COL_PROTOCOL, "RIPng version %d", rip6.rip6_vers);
if (check_col(fd, COL_INFO))
col_add_str(fd, COL_INFO, cmd);
col_add_fstr(fd, COL_INFO, "%s", cmd);
if (tree) {
ti = proto_tree_add_item(tree, proto_ripng, offset, END_OF_FRAME, NULL);
ripng_tree = proto_item_add_subtree(ti, ETT_RIPNG);
proto_tree_add_text(ripng_tree, offset, 1,
"Command: %d (%s)", rip6.rip6_cmd, cmd);
"Command: %s (%u)", cmd, rip6.rip6_cmd);
proto_tree_add_text(ripng_tree, offset + 1, 1,
"Version: %d", rip6.rip6_vers);

View File

@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
* $Id: packet.h,v 1.107 1999/10/14 01:28:28 guy Exp $
* $Id: packet.h,v 1.108 1999/10/14 03:50:31 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -499,6 +499,7 @@ void dissect_pppoed(const u_char *, int, frame_data *, proto_tree *);
void dissect_pppoes(const u_char *, int, frame_data *, proto_tree *);
void dissect_icp(const u_char *,int, frame_data *, proto_tree *);
void dissect_isakmp(const u_char *, int, frame_data *, proto_tree *);
void dissect_pim(const u_char *, int, frame_data *, proto_tree *);
void dissect_radius(const u_char *, int, frame_data *, proto_tree *);
void dissect_rip(const u_char *, int, frame_data *, proto_tree *);
void dissect_ripng(const u_char *, int, frame_data *, proto_tree *);
@ -543,6 +544,9 @@ extern const value_string etype_vals[];
gchar *arphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type);
gchar *arphrdtype_to_str(guint16 hwtype, const char *fmt);
/* ipproto.c */
extern const char *ipprotostr(int proto);
/*
* All of the possible columns in summary listing.
*

View File

@ -1,4 +1,4 @@
# $Id: configure.in,v 1.15 1999/09/24 06:38:22 guy Exp $
# $Id: configure.in,v 1.16 1999/10/14 03:50:51 itojun Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT(wtap.c)
AM_INIT_AUTOMAKE(libwtap.a, 0.0.0)
@ -77,9 +77,15 @@ dnl
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/time.h netinet/in.h)
AC_CANONICAL_HOST
dnl zlib check
AC_ARG_ENABLE(zlib,
[ --enable-zlib use zlib to read compressed data. [default=yes]],,enable_zlib=yes)
[ --enable-zlib use zlib to read compressed data. [default=yes]],, [dnl
case "$host_os" in
netbsd*) enable_zlib=no;;
*) enable_zlib=yes;;
esac])
AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
if test "x$enable_zlib" = "xno" ; then