Ethereal-dev: [Ethereal-dev] Hethereal new version

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Carsten Buchenau <c.buchenau@xxxxxxxxxxxx>
Date: Sun, 22 Apr 2001 19:23:18 +0200
[Hethereal is an HTML/Javascript Interface to Ethereal and still under heavy 
development]

I've patched hethereal.c and additional files to work with the current 
CVS-version of ethereal:

print.h and print.c are the same patches as Guy Harris posted some days before

changed Makefile.am and configure.in to install hethereal to $bindir. Added 
generation and installation of hethereal.1. Prepared supply of cgi-bin path 
to configure.in, but I don't know how to integrade it to install the binary 
really into that location...

In this Version Win32 is not supported.

the library cgihtml is compiled, but with the current configuration the dir 
cgihtml/ must be present to compile any ethereal-program

The needed images for the HTML-interface must still be installed manually.

Attachments:
patchfile for Makefile.am, configure.in, print.c, print.h and doc/Makefile.am.
tgz including hethereal.c and doc/hethereal.pod.template
tgz including cgihtml/
tgz including pictures for Hethereal

Configuring & Installing
configure --enable-hethereal ...
make
cp hethereal /path-to-cgi-bin/hethereal.cgi

Then extract  hethereal_addons-0.1.tar.gz to DocumentRoot/ of your WebServer.

Hope I didn't forget anything....

cheers, carsten
? cgihtml
? hethereal.c
? hethereal
? hethereal.1
? doc/hethereal.pod.template
? doc/hethereal.pod
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ethereal/Makefile.am,v
retrieving revision 1.313
diff -u -r1.313 Makefile.am
--- Makefile.am	2001/04/21 07:56:58	1.313
+++ Makefile.am	2001/04/22 17:09:12
@@ -61,11 +61,11 @@
 # automake will arrange that the Makefile define it as the union of all
 # the "man{section}_MANS" variables.
 #
-bin_PROGRAMS = @ethereal_bin@ @editcap_bin@ @tethereal_bin@ @dftest_bin@ @randpkt_bin@
-man1_MANS = @ethereal_man@ @editcap_man@ @tethereal_man@
+bin_PROGRAMS = @ethereal_bin@ @editcap_bin@ @tethereal_bin@ @hethereal_bin@ @dftest_bin@ @randpkt_bin@
+man1_MANS = @ethereal_man@ @editcap_man@ @tethereal_man@ @hethereal_man@
 man_MANS = 
 
-EXTRA_PROGRAMS = ethereal ethereal_static tethereal tethereal_static editcap dftest
+EXTRA_PROGRAMS = ethereal ethereal_static tethereal tethereal_static hethereal hethereal_static editcap dftest
 
 sysconf_DATA = manuf
 
@@ -515,6 +515,54 @@
 tethereal_LDFLAGS = -export-dynamic
 tethereal_static_LDFLAGS = -Wl,-static
 
+hethereal_SOURCES = \
+	$(DISSECTOR_SOURCES) \
+	$(ETHEREAL_COMMON_SOURCES) \
+	hethereal.c
+
+hethereal_static_SOURCES = \
+	$(hethereal_SOURCES)
+
+# Additional libs that I know how to build. These will be
+# linked into the hethereal executable.
+hethereal_additional_libs =		\
+	wiretap/libwiretap.a		\
+	epan/libethereal.a		\
+	epan/ftypes/libftypes.a		\
+	epan/dfilter/libdfilter.a	\
+	cgihtml/cgihtml.a
+
+# This is the automake dependency variable for the executable
+hethereal_DEPENDENCIES = \
+	$(ethereal_optional_objects)	\
+	$(hethereal_additional_libs)	\
+	plugins/gryphon/gryphon.la	\
+	plugins/mgcp/mgcp.la
+
+hethereal_static_DEPENDENCIES = \
+	$(ethereal_optional_objects)	\
+	$(hethereal_additional_libs)	
+
+# This automake variable adds to the link-line for the executable
+hethereal_LDADD = wiretap/libwiretap.a	\
+	$(ethereal_optional_objects)	\
+	$(hethereal_additional_libs)	\
+	@SNMP_LIBS@ @SSL_LIBS@		\
+	"-dlopen" self	\
+	"-dlopen" plugins/gryphon/gryphon.la @GLIB_LIBS@ -lm \
+	"-dlopen" plugins/mgcp/mgcp.la @GLIB_LIBS@ -lm \
+	@PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@
+
+hethereal_static_LDADD = wiretap/libwiretap.a	\
+	$(ethereal_optional_objects)	\
+	$(hethereal_additional_libs)	\
+	@SNMP_LIBS@ @SSL_LIBS@		\
+	@GLIB_LIBS@ -lm \
+	@PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@
+
+hethereal_LDFLAGS = -export-dynamic
+hethereal_static_LDFLAGS = -Wl,-static
+
 editcap_SOURCES = editcap.c
 
 # This is the automake dependency variable for the executable
@@ -630,6 +678,7 @@
 	doc/ethereal.pod.template \
 	doc/randpkt.txt		\
 	doc/tethereal.pod.template \
+	doc/hethereal.pod.template \
 	editcap.c		\
 	getopt.c		\
 	getopt.h		\
@@ -670,6 +719,7 @@
 install-exec-hook:
 	-chmod +s $(DESTDIR)$(bindir)/ethereal
 	-chmod +s $(DESTDIR)$(bindir)/tethereal
+	-chmod +s $(DESTDIR)$(bindir)/hethereal
 	-chmod +s $(DESTDIR)$(bindir)/ethereal_static
 else
 install-exec-hook:
@@ -693,7 +743,7 @@
 #dist-hook:
 #	@rm -f $(distdir)/register.c
 
-SUBDIRS = tools wiretap epan plugins packaging @ethereal_SUBDIRS@
+SUBDIRS = tools wiretap epan plugins packaging cgihtml @ethereal_SUBDIRS@
 
 ethereal.1: ethereal doc/ethereal.pod.template
 	(cd doc ; \
@@ -702,6 +752,10 @@
 tethereal.1: tethereal doc/tethereal.pod.template
 	(cd doc ; \
 	$(MAKE) ../tethereal.1 )
+
+hethereal.1: hethereal doc/hethereal.pod.template
+	(cd doc ; \
+	$(MAKE) ../hethereal.1 )
 
 editcap.1: doc/editcap.pod
 	(cd doc ; \
Index: configure.in
===================================================================
RCS file: /cvsroot/ethereal/configure.in,v
retrieving revision 1.120
diff -u -r1.120 configure.in
--- configure.in	2001/04/19 01:08:16	1.120
+++ configure.in	2001/04/22 17:09:12
@@ -122,11 +122,12 @@
 
 #
 # Arrange that we search for header files in the source directory
-# and in its "wiretap" subdirectory, as well as in "/usr/local/include",
-# as various packages we use ("libpcap", "zlib", an SNMP library)
-# may have been installed under "/usr/local/include".
+# and in its "wiretap" and "cgihtml" subdirectory, as well as in
+# "/usr/local/include", as various packages we use ("libpcap",
+# "zlib", an SNMP library) may have been installed under
+# "/usr/local/include".
 #
-CFLAGS="$CFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/wiretap -I\$(top_srcdir)/epan -I/usr/local/include"
+CFLAGS="$CFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/wiretap -I\$(top_srcdir)/cgihtml -I\$(top_srcdir)/epan -I/usr/local/include"
 CPPFLAGS="$CPPFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/wiretap -I\$(top_srcdir)/epan -I/usr/local/include"
 
 #
@@ -221,6 +222,49 @@
 
 
 
+# Enable/disable hethereal
+
+AC_ARG_ENABLE(hethereal,
+[  --enable-hethereal      build hethereal.  [default=no]],,enable_hethereal=no)
+
+if test "x$enable_hethereal" = "xyes" ; then
+	hethereal_bin="hethereal"
+	hethereal_man="hethereal.1"
+else
+	hethereal_bin=""
+	hethereal_man=""
+fi
+AC_SUBST(hethereal_bin)
+AC_SUBST(hethereal_man)
+
+# Set where to install hethereal
+
+CGIBIN_DIR="$bindir"
+AC_ARG_WITH(cgibindir,
+  [  --with-cgibindir=DIR    install hethereal in DIR],
+  [
+  case "$withval" in
+  "" | y | ye | yes )
+    AC_MSG_ERROR([*** You must supply an argument to the --with-cgibindir option.])
+  ;;
+  n | no)
+    AC_MSG_ERROR([*** The --without-cgibindir option is not supported.])
+  ;;
+  *) CGIBIN_DIR="$withval"
+  esac
+  ]
+)
+
+CGIBIN_DIR=`(
+  test "x$prefix" = xNONE && prefix=$ac_default_prefix
+  test "x$exec_prefix" = xNONE && exec_prefix=${prefix}
+  eval echo "$CGIBIN_DIR"
+)`
+AC_DEFINE_UNQUOTED(CGIBIN_DIR,"$CGIBIN_DIR", [hethereal installation directory])
+AC_SUBST(CGIBIN_DIR)
+
+
+
 # Enable/disable editcap
 
 AC_ARG_ENABLE(editcap,
@@ -501,7 +545,7 @@
 AC_SUBST(LIBTOOL_DEPS)
 
 AM_CONFIG_HEADER(config.h)
-AC_CONFIG_SUBDIRS(epan wiretap)
+AC_CONFIG_SUBDIRS(epan wiretap cgihtml)
 AC_OUTPUT(
   Makefile
   doc/Makefile
@@ -541,6 +585,7 @@
 echo "The Ethereal package has been configured with the following options."
 echo "                    Build ethereal : $enable_ethereal"
 echo "                   Build tethereal : $enable_tethereal"
+echo "                   Build hethereal : $enable_hethereal"
 echo "                     Build editcap : $enable_editcap"
 echo "                     Build randpkt : $enable_randpkt"
 echo "                      Build dftest : $enable_dftest"
Index: print.c
===================================================================
RCS file: /cvsroot/ethereal/print.c,v
retrieving revision 1.32
diff -u -r1.32 print.c
--- print.c	2001/03/24 23:49:14	1.32
+++ print.c	2001/04/22 17:09:12
@@ -9,6 +9,23 @@
  * By Gerald Combs <gerald@xxxxxxxx>
  * Copyright 1998 Gerald Combs
  *
+ * HTML/JavaScript extensions by
+ *      Carsten Buchenau <carsten@xxxxxxxxxxxx>
+ *      Tim Abenath <tim@xxxxxxxxxxxx>
+ *      University of Applied Science, Dortmund, Germany
+ *
+ *	New functions:
+ *		proto_tree_print_node_html
+ *		print_hex_data_html
+ *	Modified functions:
+ *		proto_tree_print
+ *		print_hex_data
+ *	Modified structs:
+ *		print_data, additional values:
+ *			int	js_level;
+ *			int	js_parent_idx;
+ *			int	js_self_idx;
+ *		
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -42,11 +59,14 @@
 #include "util.h"
 
 static void proto_tree_print_node_text(GNode *node, gpointer data);
+static void proto_tree_print_node_html(GNode *node, gpointer data);
 static void proto_tree_print_node_ps(GNode *node, gpointer data);
 static void ps_clean_string(unsigned char *out, const unsigned char *in,
 			int outbuf_size);
 static void print_hex_data_text(FILE *fh, register const u_char *cp,
 		register u_int length, char_enc encoding);
+static void print_hex_data_html(FILE *fh, register const u_char *cp,
+		register u_int length, char_enc encoding);
 static void print_hex_data_ps(FILE *fh, register const u_char *cp,
 		register u_int length, char_enc encoding);
 
@@ -60,8 +80,13 @@
 	gboolean	print_all_levels;
 	gboolean	print_hex_for_data;
 	char_enc	encoding;
+	/* HTML/JavaScript extension (hethereal): add 3 new values */
+	int		js_level;
+	int		js_parent_idx;
+	int		js_self_idx;
 } print_data;
 
+
 FILE *open_print_dest(int to_file, const char *dest)
 {
 	FILE	*fh;
@@ -110,10 +135,17 @@
 	data.print_hex_for_data = !print_args->print_hex;
 	    /* If we're printing the entire packet in hex, don't
 	       print uninterpreted data fields in hex as well. */
+	data.js_level = 0;
+	data.js_self_idx = 0;
+	data.js_parent_idx = 0;
 
+	/* HTML/JavaScript: PR_FMT_HTML must be defined in hethereal.c */
 	if (print_args->format == PR_FMT_TEXT) {
 		g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
 			proto_tree_print_node_text, &data);
+	} else if (print_args->format == PR_FMT_HTML) {
+		g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
+			proto_tree_print_node_html, &data);
 	} else {
 		g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
 			proto_tree_print_node_ps, &data);
@@ -177,6 +209,72 @@
 	}
 }
 
+/* HTML/JavaScript extension (hethereal): */
+/* Print a tree's data, and any child nodes, in HTML */
+static
+void proto_tree_print_node_html(GNode *node, gpointer data)
+{
+	field_info	*fi = (field_info*) (node->data);
+	print_data	*pdata = (print_data*) data;
+	gchar		label_str[ITEM_LABEL_LENGTH];
+	gchar		*label_ptr;
+	/* for JavaScript Menu-traversal */
+	int		saved_js_parent_idx=0;
+
+	/* Don't print invisible entries. */
+	if (!fi->visible)
+		return;
+
+	/* was a free format label produced? */
+	if (fi->representation) {
+		label_ptr = fi->representation;
+	}
+	else { /* no, make a generic label */
+		label_ptr = label_str;
+		proto_item_fill_label(fi, label_str);
+	}
+
+	
+	switch (g_node_n_children(node)) {
+	  case 0:
+	    fprintf(pdata->fh,
+	      "mD.neu(new LE(\"%d\",\"%s\",\"javascript:parent.print_hex_data(%d,%d)\",\"\",\"leer.gif\",\"%s\"))\n",
+	      pdata->js_parent_idx, label_ptr, fi->start, fi->length, label_ptr);
+	    break;
+	  default:
+	    pdata->js_self_idx++;
+	    fprintf(pdata->fh,
+	      "mD.neu(new VE(\"%d\",\"%d\",\"%s\",\"javascript:parent.print_hex_data(%d,%d)\",\"\",\"\",\"%s\"))\n",
+	      pdata->js_self_idx, pdata->js_parent_idx, label_ptr, fi->start, fi->length, label_ptr);
+	}
+
+
+	/* If it's uninterpreted data, dump it (unless our caller will
+	   be printing the entire packet in hex). */
+	if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data)
+		print_hex_data_html(pdata->fh, &pdata->pd[fi->start],
+				fi->length, pdata->encoding);
+
+	/* If we're printing all levels, or if this level is expanded,
+	   recurse into the subtree, if it exists. */
+	if (pdata->print_all_levels || tree_is_expanded[fi->tree_type]) {
+		if (g_node_n_children(node) > 0) {
+			/* - Increment pdata->level each time we finde a new node */
+			/* - Save present pdata->js_parent_idx, enter recursion
+			     with new value from pdata->level and restore old value
+			     afterwards. */
+			pdata->level++;
+			pdata->js_level++;
+			saved_js_parent_idx = pdata->js_parent_idx;
+			pdata->js_parent_idx = pdata->js_level;
+			g_node_children_foreach(node, G_TRAVERSE_ALL,
+				proto_tree_print_node_html, pdata);
+			pdata->js_parent_idx = saved_js_parent_idx;
+			pdata->level--;
+		}
+	}
+}
+
 void print_hex_data(FILE *fh, gint format, frame_data *fd)
 {
 	gboolean multiple_sources;
@@ -208,10 +306,23 @@
 		}
 		length = tvb_length(tvb);
 		cp = tvb_get_ptr(tvb, 0, length);
-		if (format == PR_FMT_PS)
-			print_hex_data_ps(fh, cp, length, fd->flags.encoding);
-		else
+		switch (format) {
+
+		case PR_FMT_TEXT:
 			print_hex_data_text(fh, cp, length, fd->flags.encoding);
+			break;
+
+		case PR_FMT_PS:
+			print_hex_data_ps(fh, cp, length, fd->flags.encoding);
+			break;
+
+		case PR_FMT_HTML:
+			print_hex_data_html(fh, cp, length, fd->flags.encoding);
+			break;
+
+		default:
+			g_assert_not_reached();
+		}
 	}
 }
 
@@ -252,6 +363,68 @@
         fprintf(fh, "\n");
         return;
 
+}
+
+/*
+ * HTML/JavaScript extension (hethereal):
+ * This routine was created by Dan Lasley <DLASLEY@xxxxxxxxxx>, only
+ * slightly modified for ethereal by Gilbert Ramirez, and then duplicated
+ * and modified for hethereal by carsten@xxxxxxxxxxxx and tim@xxxxxxxxxxxx.
+ */
+static
+void print_hex_data_html(FILE *fh, register const u_char *cp,
+		register u_int length, char_enc encoding)
+{
+        register int i;
+        u_char c;
+	u_char c_ascii_str[3];
+	u_char *cp_ascii = (u_char *)cp;
+	
+	void convert_to_ascii(u_char c_ascii_str[3], const u_char c)
+	{
+	  u_char c_ascii;
+	  
+	  c_ascii = c >= 0x20 && c < 0x7f ? c : '.';
+	  switch (c_ascii) {
+	    case 0x22:
+	    case 0x5c:
+	      sprintf(c_ascii_str, "\\%c", c_ascii);
+	      break;
+	    default:
+	      sprintf(c_ascii_str, "%c", c_ascii);
+	  }
+	}
+
+	/* close open JavaScript function first */
+	fprintf(fh, "}\n\n");
+	
+
+	/* Now build JavaScript array for hex-data */
+	fprintf(fh, "var hexdaten = new Array(");
+        for (i=0; i<length-1; i++) {
+                c = *cp++;
+		if (encoding == CHAR_EBCDIC) c = EBCDIC_to_ASCII1(c);
+	        fprintf(fh, "\"%02X\",", c);
+        }
+	/* print last byte and close hex-array */
+	c = *cp++;
+	fprintf(fh, "\"%02X\")\n", c);
+
+
+	/* Now build JavaScript array for ASCII-data */
+	fprintf(fh, "var asciidaten = new Array(");
+	for (i=0; i<length-1; i++) {
+                c = *cp_ascii++;
+		if (encoding == CHAR_EBCDIC) c = EBCDIC_to_ASCII1(c);
+		convert_to_ascii(c_ascii_str, c);
+		fprintf(fh, "\"%s\",", c_ascii_str);
+	}
+	/* print last byte and close ascii-array */
+	c = *cp_ascii++;
+	convert_to_ascii(c_ascii_str, c);
+	fprintf(fh, "\"%s\")\n", c_ascii_str);
+	
+        return;
 }
 
 #define MAX_LINE_LENGTH 256
Index: print.h
===================================================================
RCS file: /cvsroot/ethereal/print.h,v
retrieving revision 1.21
diff -u -r1.21 print.h
--- print.h	2001/03/23 18:44:20	1.21
+++ print.h	2001/04/22 17:09:12
@@ -32,6 +32,7 @@
 
 #define PR_FMT_TEXT 0
 #define PR_FMT_PS   1
+#define PR_FMT_HTML 2
 
 typedef struct {
   gboolean	to_file;	/* TRUE if we're printing to a file */
Index: doc/Makefile.am
===================================================================
RCS file: /cvsroot/ethereal/doc/Makefile.am,v
retrieving revision 1.9
diff -u -r1.9 Makefile.am
--- Makefile.am	2001/03/06 18:38:47	1.9
+++ Makefile.am	2001/04/22 17:09:13
@@ -43,6 +43,15 @@
 tethereal.pod: tethereal.pod.template  ../tethereal
 	../tethereal -G | $(PERL) $(srcdir)/dfilter2pod.pl $(srcdir)/tethereal.pod.template > tethereal.pod
 
+../hethereal.1: hethereal.pod ../config.h
+	pod2man hethereal.pod                     \
+	--center="The Hethereal Network Analyzer" \
+	--release=$(VERSION)                     \
+	> ../hethereal.1
+ 
+hethereal.pod: hethereal.pod.template  ../hethereal
+	../hethereal -G | $(PERL) $(srcdir)/dfilter2pod.pl $(srcdir)/hethereal.pod.template > hethereal.pod
+
 ../editcap.1: editcap.pod ../config.h
 	pod2man $(srcdir)/editcap.pod                     \
 	--center="The Ethereal Network Analyzer" \

Attachment: hethereal_addons-0.1.tar.gz
Description: GNU Zip compressed data

Attachment: cgihtml.tgz
Description: GNU Zip compressed data

Attachment: hethereal_new_files.tgz
Description: GNU Zip compressed data