ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] new add-on: Hethereal

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

From: Carsten Buchenau <carsten@xxxxxxxxxxxx>
Date: Tue, 6 Mar 2001 22:46:43 +0100
[unfortunately too late for 0.8.16...]

Hethereal provides an HTML interface to Ethereal. It uses a lot of Javascript 
and was successfully testet against Netscape-4.76 (Linux) and IE-5.5. 
Unfortunately Konqueror doesn't work and Mozilla (Linux) has big trouble with 
frames. We also use the cgihtml library, a C-API to CGI-environment. See 
below.

You can see Hethereal in action on
	http://www.abmlinux.org/cgi-bin/hethereal.cgi.

This is part of our (3 students) diploma work and is intented to build a 
protocol-analysator based on an Embedded-PC running Linux, so the only 
interface shall be the Apache (mod_ssl) WebServer. I would never recommend 
running Hethereal (we thought about naming it heathereal....) on Servers 
connected to the outside world. But it looks quite nice so give it a try 
anyway ;-)

I have compiled the binary referenced above with capturing disabled. The 
(only available) capture-file "dump" contains a new, not yet released 
dissector for BACnet (Building Automation and Control networks). See 
http://www.abmlinux.org for details about our whole work. The dissector will 
be mailed to this list soon.


new files:
	hethereal.c	(attached)
modified files:
	print.c		(diff attached)
new libraries:
	cgihtml		(see notes below)
additional files:
	hethereal_addons.tgz	(attached)
		Images and two HTML-files
To do for compiling / releasing:
	fix header of hethereal.c to work with CVS (sorry, new to that)
	expand Makefile.am, Makefile.in and Makefile.nmake to work with
		hethereal and cgihtml.

Installation:
The binary must be copied to a valid CGI-Path, like 
/usr/lib/cgi-bin/hethereal.cgi. Make it SUID root to be able to capture 
packets. Extract hethereal_addons.tgz to DocumentRoot. This creates a subdir 
/hethereal.

Changing the sources:
All parameters for hethereal's behavior are set in function main() through 
struct html_cfg. You can even change all color-defs there. Have a closer look 
to the path-variables base_path and cf_path. 

htmlcgi:
We are using version 1.61 from  Eugene Eric Kim, eekim@xxxxxxxxx. It can be 
downloaded from http://www.eekim.com/software/cgihtml/index.html. This might 
be the point where Hethereal gets incompatible to Windows...

Authors:
	Tim Abenath, tim@xxxxxxxxxxxx
	Carsten Buchenau, carsten@xxxxxxxxxxxx


cheers, Carsten Buchenau, University for Applied Science, Dortmund, Germany

/* hethereal.c
 *
 * $Id: hethereal.c,v 1.61 2001/01/04 00:16:43 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@xxxxxxxx>
 * Copyright 1998 Gerald Combs
 *
 *
 * HTML/JavaScript variant, by
 *	Carsten Buchenau <carsten@xxxxxxxxxxxx>
 *	Tim Abenath <tim@xxxxxxxxxxxx>
 *      University of Applied Science, Dortmund, Germany
 *
 *	- For capture-mode the binary (hethereal) must be SUID root!
 *	- Your Web-Server must be configured properly
 *	- Check path-names for images, .html files and base-capture-directory
 *	  ( located in function main() )
 *	
 *
 * The JavaScript code for displaying a packet's contents in a nice menu
 * with folders is adopted from:
 *	js-menue 1.4.1
 *	Ansgar Federhen/Rhein@Net
 *	http://rheinbreitbach.net/js-menue/ e-mail:js-menue@xxxxxxxxxxxxxxxxxx
 * Here's the legal disclaimer. Sorry for German, but translating is not
 * our job here:
 *	JS-Menue, dynamisches strukturiertes Menue-System auf JavaScript-Basis
 *	© 1998-2000 Ansgar Federhen/Rhein@Net (deutsch) + Colin Tucker (engl.)
 *	Script darf bei Uebernahme des Copyrightvermerks frei genutzt werden.
 *	©-Hinweis nicht loeschen! Scriptverwendung wird sonst lizenzpflichtig!
 *	http://rheinbreitbach.net/js-menue/ e-mail:js-menue@xxxxxxxxxxxxxxxxxx
 *
 * For CGI-Parameter reading and conversion we use
 * cgihtml-1.69 from Eugene Eric Kim <eekim@xxxxxxxxx>, <http://www.eekim.com/>
 * The library must be located in ./cgihtml and should be compiled by ethereal.
 *
 *
 * 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 <stdio.h>
#include <string.h>
#include <locale.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <errno.h>

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

#include <signal.h>

#ifdef NEED_SNPRINTF_H
# include "snprintf.h"
#endif

#if defined(HAVE_UCD_SNMP_SNMP_H)
#ifdef HAVE_UCD_SNMP_VERSION_H
#include <ucd-snmp/version.h>
#endif /* HAVE_UCD_SNMP_VERSION_H */
#elif defined(HAVE_SNMP_SNMP_H)
#ifdef HAVE_SNMP_VERSION_H
#include <snmp/version.h>
#endif /* HAVE_SNMP_VERSION_H */
#endif /* SNMP */

#ifdef NEED_STRERROR_H
#include "strerror.h"
#endif

#ifdef NEED_GETOPT_H
#include "getopt.h"
#endif

#include <glib.h>
#include <epan.h>

#include "globals.h"
#include "timestamp.h"
#include "packet.h"
#include "file.h"
#include "prefs.h"
#include "column.h"
#include "print.h"
#include "resolv.h"
#include "util.h"
#include "conversation.h"
#include "plugins.h"

#include "dfilter-grammar.c"


/*
 * cgihmtl support
 *
 * cgihtml-1.69 from Eugene Eric Kim <eekim@xxxxxxxxx>, <http://www.eekim.com/>
 *
 * This small library is used for reading cgi-params and some html-generation
 */
#include "cgihtml/cgi-lib.h"
#include "cgihtml/html-lib.h"

#ifdef HAVE_UNISTD_H
extern char **environ;
#endif


static guint32 firstsec, firstusec;
static guint32 prevsec, prevusec;
static gchar   comp_info_str[256];
static gboolean verbose;
static gboolean print_hex;

#ifdef HAVE_LIBPCAP
typedef struct _loop_data {
  gint           linktype;
  pcap_t        *pch;
  wtap_dumper   *pdh;
} loop_data;

static loop_data ld;

static int capture(int, int);
static void capture_pcap_cb(u_char *, const struct pcap_pkthdr *,
  const u_char *);
static void capture_cleanup(int);
#endif

typedef struct {
  capture_file *cf;
  wtap_dumper *pdh;
} cb_args_t;

static int load_cap_file(capture_file *, int);
static void wtap_dispatch_cb_write(u_char *, const struct wtap_pkthdr *, int,
    union wtap_pseudo_header *, const u_char *);
static void wtap_dispatch_cb_print(u_char *, const struct wtap_pkthdr *, int,
    union wtap_pseudo_header *, const u_char *);

packet_info  pi;
capture_file cfile;
FILE        *data_out_file = NULL;
guint        main_ctx, file_ctx;
ts_type timestamp_type = RELATIVE;
#ifdef HAVE_LIBPCAP
static int promisc_mode = TRUE;
#endif


/*
 * defining HTML- and JavaScript functions now.
 *
 * abm@xxxxxxxxxxxx since 2001-02-23
 * 
 */

static char SELFNAME[256];
static char CFNAME[256];
static char RFILTER[256];
static int LINKNR;
static char ERR_MSG[1024+1];
static gboolean HAVE_ERR;

static struct html_cfg {
  char *background;
  char *bgcolor;
  char *text;
  char *link;
  char *alink;
  char *vlink;
  char *highlight;

  char *base_path;
  char title[256];
  char *pre_title;
  char *blank_page;
  char *help_page;
  
  char *font;
  int font_size;
  
  char *method;
  char *target_read;
  char *target_capt;
  char *target_help;
 
  char *root_img;
  char *root_name;
  char *root_link;

  char *cf_default;
  char *cf_path;
   
  struct {
    int BlackOnWhite;
    char *dummy;
    char *box_close;
    char *box_open;
    char *active;
    char *follow;
    char *help;
  } img;

  gboolean enable_capture;
    
} html_cfg;


static void
print_html_menu_header(void)	/* The Packet-List */
{

  /* Print the HTML Header */

  html_header();
  printf("<HTML><HEAD>\n");
  printf("<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\">\n");
  /*   This Code will be started when the source loads, and write the first frameset */
  printf("<!--\n");
  printf("document.writeln(\"<TITLE>%s</TITLE>\")\n", html_cfg.title);
  printf("document.writeln(\"<FRAMESET ROWS=\\\"*,80%%\\\" FRAMEBORDER=yes FRAMESPACING=0 BORDER=1 onLoad=\\\"start()\\\">\");\n");
  printf("document.writeln(\"  <FRAME SRC=\\\"%s/%s\\\" NAME=\\\"menuFrame\\\" SCROLLING=\\\"auto\\\">\");\n",
  	html_cfg.base_path, html_cfg.blank_page);
  printf("document.writeln(\"  <FRAME SRC=\\\"%s/%s\\\" NAME=\\\"dataFrame\\\" SCROLLING=\\\"auto\\\">\");\n",
  	html_cfg.base_path, html_cfg.blank_page);
  printf("document.writeln(\"</FRAMESET>\")\n\n");


  /* As seen above, this function will be started from the frameset */

  printf("function start(){\n");
 
  printf("m=frames[\"menuFrame\"].window.document\n"); /* Open handle for menue Frame             */
  printf("m.open(\"text/html\")\n");                   /* and write its header and css definition */
  printf("m.write(\"<HTML><HEAD>\\n\")\n");
  printf("m.write(\"<STYLE>\")\n");
  printf("m.write(\"<!--\\n\")\n");
  printf("m.write(\"body,p,nobr,b,i,a,font {font-family:%s}\\n\")\n", html_cfg.font);
  printf("m.write(\"A{text-decoration:none;color: %s;font-size: %dpt}\\n\")\n", html_cfg.text, html_cfg.font_size);
  printf("m.write(\"A:hover{color: %s}\\n\")\n", html_cfg.alink);
  printf("m.write(\"A:active{color: %s}\\n\")\n", html_cfg.alink);
  printf("m.write(\"A:visited{color: %s}\\n\")\n", html_cfg.vlink);
  printf("m.write(\"//-->\")\n");
  printf("m.write(\"</STYLE>\\n\")\n");
  

  printf("m.write(\"<\")\n");
  printf("m.write(\"SCRIPT LANGUAGE=\\\"JavaScript\\\" TYPE=\\\"text/javascript\\\">\\n\")\n"); 
  printf("m.write(\"<!--\\n\")\n");
  printf("m.write(\"  last = -1;\\n\")\n");
  printf("m.write(\"  mark = new Image();\\n\")\n");
  printf("m.write(\"  space = new Image();\\n\")\n");
  printf("m.write(\"  mark.src = \\\"%s/%s\\\";\\n\")\n", html_cfg.base_path, html_cfg.img.active);
  printf("m.write(\"  space.src = \\\"%s/%s\\\";\\n\")\n", html_cfg.base_path, html_cfg.img.dummy);
  /* Function for changeing the Image that marks the selected Packet */
  printf("m.write(\"  function changeImage(nr,object){\\n\")\n"); 
  printf("m.write(\"    if(nr != last){\\n\")\n");
  printf("m.write(\"      window.document.images[nr].src = mark.src;\\n\")\n");
  printf("m.write(\"      window.document.images[last].src = space.src;\\n\")\n");
  printf("m.write(\"      last = nr;\\n\")\n");
  printf("m.write(\"    }\\n\")\n");
  printf("m.write(\"  }\\n\\n\")\n"); 
  printf("m.write(\"//-->\\n\")\n");
  /* we need to separate the </script> statement, else it would get interpreted in the first stage */
  printf("m.write(\"<\")\n");
  printf("m.write(\"/SCRIPT>\\n\");\n");

  printf("m.write(\"</HEAD>\\n\");\n");
  printf("m.write(\"<BODY BACKGROUND=\\\"%s\\\" BGCOLOR=\\\"%s\\\" TEXT=\\\"%s\\\">\\n\")\n", html_cfg.background, html_cfg.bgcolor, html_cfg.text);
}

static void
print_html_data_header(void) /* The Protokolltree Header */
{
  html_header();
  printf("<! JS-Menue, dynamisches strukturiertes Menue-System auf JavaScript-Basis >\n");
  printf("<! © 1998-2000 Ansgar Federhen/Rhein@Net (deutsch) + Colin Tucker (engl.) >\n"); 
  printf("<! Script darf bei Uebernahme des Copyrightvermerks frei genutzt werden.  >\n"); 
  printf("<! ©-Hinweis nicht loeschen! Scriptverwendung wird sonst lizenzpflichtig! >\n"); 
  printf("<! http://rheinbreitbach.net/js-menue/ e-mail:js-menue@xxxxxxxxxxxxxxxxxx >\n"); 
  printf("<! Hard patched by the ABM Linux Team, abm@xxxxxxxxxxx >\n"); 
  printf("<HTML><HEAD>\n");
  printf("<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\">\n");
 
  printf("<!--\n");
  printf("function loadData(){\n"); /* The function in which the tree's struktur is defined */
  printf("mD=new Packet()\n");
  /* Here is it's root entry. This is always the same. */
  printf("mD.neu(new HVE(\"0\",\"\",\"%s\",\"%s\"))\n", html_cfg.root_img, html_cfg.root_name);
}

static void
print_error_html(void) {
  /* Default output if something went wrong or frames broke up */
  printf("<TABLE border=0>\n");
  printf("<TR><TH>\n<FONT size=+1><FONT color=\"%s\">%s</FONT> / ", html_cfg.highlight, html_cfg.pre_title);
  printf("%s</FONT> / <FONT size=-1>Error notification</FONT>\n</TH></TR>\n", html_cfg.title);
  printf("<TR><TD>\n<A HREF=\"%s/%s\" target=\"%s\"><IMG SRC=\"%s/%s\" BORDER=0> open help</A>\n</TD></TR>\n",
    html_cfg.base_path, html_cfg.help_page, html_cfg.target_help, html_cfg.base_path, html_cfg.img.help);
  printf("</TABLE>\n");
  printf("<HR>\n");
  printf("<P>\nUgh, oh, something went wrong.<BR>\n");
  printf("<MENU>\n<LI>Check your input settings.</LI>\n");
  printf("<LI>If you have resized your browser's window or the inside frames, try RELOAD to reinit frame-settings.</LI>\n");
  printf("<LI>Maybe your browser doesn't support JavaScript correctly.</LI>\n");
  printf("</MENU>\n</P>\n");
  /* print saved error message if we have one... */
  if (HAVE_ERR) {
    printf("<P>\nI've received the following error-message from my sub-system:\n");
    printf("<MENU>\n<LI>%s</LI>\n</MENU>\n</P>\n", ERR_MSG);
  }
}


static void
print_html_menu_footer(void) /* The HTML footer of the Packetlist */
{
  /* print saved error message if we have one first... */
  if (HAVE_ERR)
    printf("m.writeln(\"<P>%s</P>\")\n", ERR_MSG);
    
  printf("m.writeln(\"\\n</BODY>\")\n");
  printf("m.writeln(\"</HTML>\")\n");
  printf("m.close()\n");
  printf("}\n");
  printf("//-->\n");
  printf("</SCRIPT>\n");
  printf("<TITLE>%s</TITLE>\n", html_cfg.title);
  printf("</HEAD>\n");

  print_error_html();

  html_end();
}

static void
print_html_data_footer(void) /* This is the big part, protokolltree and hexdata will get printed */
{
  printf("function print_hex_data(start, length){\n");		/* function for the hexdata	*/
  printf("hex_header();\n");                               	/* print: the header		*/
  printf("line_numbers();\n");                             	/*        the line numbers	*/
  printf("hex(start, length);\n");                         	/*        the hex-data	*/
  printf("ascii(start, length);\n");                       	/*        the ascii-data	*/
  printf("hex_footer();\n");                               	/*        the footer		*/
  printf("}\n"); 
  printf(" \n");
  printf("function hex_header(){\n");				/* so here's the header		*/
  printf("hd=frames[\"hexFrame\"].window.document\n");		/* handle for the hexframe	*/
  printf("hd.open(\"text/html\")\n");				/* open the dokument		*/
  printf("hd.write(\"<HTML><BODY BACKGROUND=\\\"%s\\\" BGCOLOR=\\\"%s\\\" TEXT=\\\"%s\\\">\\n\")\n", html_cfg.background, html_cfg.bgcolor, html_cfg.text);
  printf("hd.write(\"<TABLE BORDER=\\\"0\\\" CELLPADDING=\\\"0\\\" CELLSPACING=\\\"0\\\">\\n\")\n");
  printf("hd.write(\"<TR><TD>\\n\")\n");
  printf("hd.write(\"<FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\\n\");\n", html_cfg.font, html_cfg.text);
  printf("}\n");
  printf(" \n");
  printf("function hex_footer(){\n");				/* function for the footer	*/
  printf("hd.write(\"</TR></TABLE>\\n\")\n");
  printf("hd.write(\"</BODY></HTML>\\n\")\n");
  printf("hd.close()\n");					/* close the handle		*/
  printf("}\n");
  printf(" \n");
  printf("function line_numbers(){\n"); /* this will print out the necessary amount of linenumbers */
  /* Count in hex. Nice one :-) */
  printf("var translate = new Array(\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\");\n");
  printf("amount = hexdaten.length;\n");	/* length of the hexdata array */
  printf("rows = amount / 16;\n");		/* calculate the number of needed rows */
  printf("first = 0;\n");
  printf("second = 0;\n");
  printf("firstcount = 1;\n");
  printf("secondcount = 1;\n");
  printf("thirdcount = 0;\n");
  printf("for(i = 0; i <= rows; i++){\n");
  printf("        if(i > 255){\n");                                             /* this counts up the first digit when needed */
  printf("                if(i %% 256 == 0){\n");
  printf("                        first = translate[firstcount];\n");
  printf("                        if(firstcount == (256*16)){\n");              /* reset from f to 0 */
  printf("                                firstcount = 0;\n");
  printf("                        }\n");
  printf("                        else{\n");
  printf("                                firstcount++;\n");
  printf("                        }\n");
  printf("                }\n");
  printf("        }\n");
  printf(" \n");
  printf("        if(i > 15){\n");                                              /* this counts up the second digit when needed */
  printf("                if(i %% 16 == 0){\n");
  printf("                        second = translate[secondcount];\n");
  printf("                        if(secondcount == 255){\n");                  /* reset from f to 0 */
  printf("                                secondcount = 0;\n");
  printf("                        }\n");
  printf("                        else{\n");
  printf("                                secondcount++;\n");
  printf("                        }\n");
  printf("                }\n");
  printf("        }\n");
  printf("        third = translate[thirdcount];\n");
  printf("        thirdcount++;\n");                                            /* the third will always get modifyed */
  printf("                if(thirdcount == 16) {\n");
  printf("                        thirdcount = 0;\n");                          /* reset from f to 0 */
  printf("                }\n");
  printf("          hd.write(\"\"+first+second+third+\"0<br>\"); // iprint out the four digits, forth always zero\n");
  printf("}\n");
  printf("hd.write(\"\\n</FONT></TD>\\n\");\n");
  printf("}\n");
  printf(" \n");
  printf(" \n");
  printf("function hex(start, length){\n");	/* this prints the hex data */
  printf("hd.write(\"<TD>\\n\");\n");
  printf("hd.write(\"<FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\\n\");\n", html_cfg.font, html_cfg.text);
  printf("amount = hexdaten.length;\n");	/* amount as seen above */
  printf("stop = start+length;\n");		/* calculate the stop field */
  printf("hd.write(\"&nbsp;&nbsp;\");\n");
  printf("for(i = 0; i < amount; i++){\n");	/* print put all fields */
  printf("        if(i == start && length != 0){  // fire it only when start is here and we want to mark something\n");
  printf("                hd.write(\"</FONT><FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\");  // start with highlighting\n", html_cfg.font, html_cfg.highlight);
  printf("        }\n");
  printf(" \n");
  printf("        if(i == stop && length != 0){                       // end of highlighting?\n");
  printf("                hd.write(\"</FONT><FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\");  // turn it off\n", html_cfg.font, html_cfg.text);
  printf("        }\n");
  printf(" \n");
  printf("        if(i %% 16 == 0 && i != 0){\n");	/* do we have a complete row? */
  printf("                hd.write(\"<BR>&nbsp;\\n\")\n");
  printf("        }\n");
  printf("        hd.write(hexdaten[i]+\" \"); // print the field\n");
  printf(" \n");
  printf(" \n");
  printf("}\n");
  printf("hd.write(\"\\n</FONT></TD>\\n\");\n");
  printf("}\n");
  printf(" \n");
  printf("function ascii(start, length){\n"); /* print the ascii data, same as hex, different data array :O) */
  printf("hd.write(\"<TD>\\n\");\n");
  printf("hd.write(\"<FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\\n\");\n", html_cfg.font, html_cfg.text);
  printf("amount = asciidaten.length;\n");
  printf("stop = start+length;\n");
  printf("hd.write(\"&nbsp;\");\n");
  printf("for(i = 0; i < amount; i++){\n");
  printf("        if(i == start && length != 0){  // fire it only when start is here and we want to mark something\n");
  printf("                hd.write(\"</FONT><FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\");  // start with highlighting\n", html_cfg.font, html_cfg.highlight);
  printf("        }\n");
  printf(" \n");
  printf("        if(i == stop && length != 0){                       // end of highlighting?\n");
  printf("                hd.write(\"</FONT><FONT FACE=\\\"%s\\\" COLOR=\\\"%s\\\">\");  // turn it off\n", html_cfg.font, html_cfg.text);
  printf("        }\n");
  printf(" \n");
  printf("        if(i %% 16 == 0 && i != 0){\n");
  printf("                hd.write(\"<BR>\\n&nbsp;\")\n");
  printf("        }\n");
  printf("        hd.write(asciidaten[i]); // print the field\n");
  printf(" \n");
  printf(" \n");
  printf("}\n");
  printf("hd.write(\"</FONT></TD>\\n\");\n");
  printf("}\n");
  printf(" \n");
  /* the stuff from here on is from js-menue */
  /* Ansgar Federhen/Rhein@Net */
  /* http://rheinbreitbach.net/js-menue/ e-mail:js-menue@xxxxxxxxxxxxxxxxxx */
  printf("BOW = \"%d\";\n", html_cfg.img.BlackOnWhite); 
  printf("BildURL = \"%s/\";\n", html_cfg.base_path);     
  printf("Schrift = \"%s\";\n", html_cfg.font);
  printf("SchriftSt = \"0\";\n");
  printf("Schliessen = \"0\";\n");
  printf("CloseAll = \"1\";\n");
  printf("VerzAuf = \"Ordner &ouml;ffnen\";\n");
  printf("VerzZu = \"Ordner schlie&szlig;en\";\n");
  printf("VerzZuLink = \"1\";\n");
  printf("KlappAuf = \"Alle Ordner auf\";\n");
  printf("KlappZu = \"Alle Ordner zu\";\n");
  printf("Titel = \"%s\";\n", html_cfg.title);
  printf("StatLine = \"\";\n");
  printf("StatURL = \"0\";\n");
  printf(" \n");
  /* frame definition of the protokolltree and hextable get written here */
  printf("document.write(\"<TITLE>\"+Titel+\"</TITLE>\\n\");StatLine=(StatLine==\"\")?Titel:StatLine\n");
  printf("document.write(\"<FRAMESET FRAMEBORDER=1 FRAMESPACING=0 BORDER=1 onLoad=\\\"start()\\\" onResize=\\\"reDraw()\\\" ROWS=\\\"80%%,*\\\">\\n\")\n");
  printf("document.write(\"<FRAME NAME=\\\"packetFrame\\\" SRC=\\\"%s/%s\\\" MARGINWIDTH=\\\"0\\\" MARGINHEIGHT=\\\"0\\\" SCROLLING=\\\"Auto\\\">\\n\")\n",
  	html_cfg.base_path, html_cfg.blank_page);
  printf("document.write(\"<FRAME NAME=\\\"hexFrame\\\" SRC=\\\"%s/%s\\\" MARGINWIDTH=\\\"8\\\" MARGINHEIGHT=\\\"8\\\" SCROLLING=\\\"Auto\\\">\\n\")\n",
  	html_cfg.base_path, html_cfg.blank_page);
  printf("document.write(\"</FRAMESET>\\n\")\n");
  printf(" \n");
  printf("function start(){\n");
  printf("loadData()\n");
  printf("DrawMenu()\n");
  printf("print_hex_data('0','0')\n");
  printf("}\n");
  printf(" \n");
  printf("function reDraw(){\n");
  printf("DrawMenu()\n");
  printf("}\n");
  printf(" \n");
  printf("WH6=\"\\\" WIDTH=16 HEIGHT=16 ALIGN=TOP BORDER=0 ALT=\\\"\"\n"); /* sum stuff to short the code */
  printf("WH9=\".gif\\\" WIDTH=19 HEIGHT=16 ALIGN=TOP BORDER=0 ALT=\\\"\"\n");
  printf("WHA=\".gif\\\" WIDTH=19 HEIGHT=16 ALIGN=TOP>\"\n");
  printf("BU=\"<IMG SRC=\\\"\"+BildURL\n");
  printf("oMO=\"\\\" onMouseOver=\\\"window.status='\"\n");
  printf("rt=\"'; return true\\\" onMouseOut=\\\"window.status='\"+StatLine+\"'; return true\\\">\"\n");
  printf("jsp=\"<A HREF=\\\"javascript:parent.\"\n");
  printf(" \n");
  printf("function DrawMenu(){\n");	/* print the menu into the frame */
  printf("m=frames[\"packetFrame\"].window.document\n");
  printf("m.open(\"text/html\")\n");
  printf("m.write('<HTML>\\n<HEAD>\\n');\n");
  printf("m.write('<STYLE>\\n<!--\\nbody,p,nobr,b,i,a,font {font-family:%s}\\nA{text-decoration:none;color: %s;font-size: %dpt')\n",
  	html_cfg.font, html_cfg.text, html_cfg.font_size);
  printf("m.write('}\\nA:hover{color: %s}\\nA:active{color: %s}\\nA:visited{color: %s}\\n//-->\\n</STYLE>\\n')\n",
  	html_cfg.alink, html_cfg.alink, html_cfg.vlink);
  printf("m.write('<BODY BACKGROUND=\"%s\" BGCOLOR=\"%s\" TEXT=\"%s\">\\n')\n",
  	html_cfg.background, html_cfg.bgcolor, html_cfg.text);


  /* print saved error message if we have one first... */
  if (HAVE_ERR)
    printf("m.writeln(\"<P>%s</P>\")\n", ERR_MSG);


  /* now print menu bar in middle frame */
  printf("m.writeln(\"<P><NOBR>\")\n");
  printf("m.writeln(\"<A HREF=\\\"javascript:parent.AllOpenClose(1)\\\">\")\n");
  printf("m.writeln(\"<IMG SRC=\\\"%s/%s\\\" BORDER=0> expand all</A>&nbsp;\")\n", html_cfg.base_path, html_cfg.img.box_open);
  printf("m.writeln(\"<A HREF=\\\"javascript:parent.AllOpenClose(0)\\\">\")\n");
  printf("m.writeln(\"<IMG SRC=\\\"%s/%s\\\" BORDER=0> collapse all</A>&nbsp;\")\n", html_cfg.base_path, html_cfg.img.box_close);
/* FOLLOW TCP-STREAM is not yet implemented. */
/*
  printf("m.writeln(\"<A HREF=\\\"javascript:parent.AllOpenClose(0)\\\">\")\n");
  printf("m.writeln(\"<IMG SRC=\\\"%s/%s\\\" BORDER=0> follow TCP stream</A>&nbsp;\")\n", html_cfg.base_path, html_cfg.img.follow);
*/
  printf("m.writeln(\"<A HREF=\\\"%s/%s\\\" target=\\\"%s\\\"><IMG SRC=\\\"%s/%s\\\" BORDER=0> open help</A>&nbsp;\")\n",
  html_cfg.base_path, html_cfg.help_page, html_cfg.target_help, html_cfg.base_path, html_cfg.img.help);
  printf("m.writeln(\"<HR></NOBR>\")\n");

    
  printf("m.write('<NOBR>')\n");
  printf("m.write('<A HREF=\"%s\" TARGET=\"_top\"'+oMO)\n", html_cfg.root_link);
  printf("m.write(mD[1].stat+rt+BU+mD[1].icon+WH6+mD[1].stat+'\">&nbsp;<B>'+mD[1].text+'</B></A><BR>\\n')\n");
  printf("printNode(mD[1].name,\"\")\n");	/* jump to next function */
  printf("m.write('</NOBR>\\n</P></FONT>\\n</BODY>\\n</HTML>')\n");
  printf("m.close()\n");
  printf("window.defaultStatus=StatLine\n");
  printf("}\n");
  printf(" \n");
  printf("function printNode(sE,zE){\n");	/* print a protokolltree's node */
  printf("var after=new Packet()\n");
  printf("for(idx=1;idx<=mD.length;idx++){if((mD[idx].typ!=\"0\")&&(mD[idx].vor==sE)){after.neu(mD[idx])}}\n");
  printf("var idx=1\n");
  printf("while(idx<=after.length){\n");
  printf("m.write(zE)\n");
  printf("        if(after[idx].typ=='link'){\n");
  printf("                w1=(StatURL==0)?after[idx].text:after[idx].url\n");
  printf("                m.write((after[idx].icon==\"%s\")?BU+((idx!=after.length)?\"stamm-\":\"zwe\")+BOW+WHA:BU+((idx!=after.length)?\"zw\":\"zwe\")+BOW+WHA)\n",
  	html_cfg.img.dummy);
  printf("                lstat=(after[idx].lstat==\"\")?w1:after[idx].lstat\n");
  printf(" \n");
  printf("                if(after[idx].url != \"\"){\n");
  printf("                        m.write('<A HREF=\"'+after[idx].url)\n");
  printf("                        m.write(oMO+lstat+rt+BU+after[idx].icon)\n");
  printf("                        m.write(WH6+((after[idx].lstat==\"\")?after[idx].url:after[idx].lstat)+'\">')\n");
  printf("                }\n");
  printf(" \n");
  printf("                m.write('&nbsp;'+after[idx].text)\n");
  printf(" \n");
  printf("                if(after[idx].url != \"\"){\n");
  printf("                        m.write('</A>')\n");
  printf("                }\n");
  printf(" \n");
  printf("        m.write(\"<BR>\")\n");
  printf("        }\n");
  printf("        else{\n");
  printf("                zweig=zE\n");
  printf("                zicon=(after[idx].zicon==\"\")?\"%s\":after[idx].zicon\n", html_cfg.img.box_close);
  printf("                oicon=(after[idx].oicon==\"\")?\"%s\":after[idx].oicon\n", html_cfg.img.box_open);
  printf("                vza=(after[idx].vstat==\"\")?VerzAuf:after[idx].vstat\n");
  printf("                vzz=(after[idx].vstat==\"\")?VerzZu:after[idx].vstat\n");
  printf("                w1=(after[idx].open==0)?1:0\n");
  printf("                w2=(w1==1)?\"zwauf-\":\"zwzu-\"\n");
  printf("                w2+=(idx==after.length)?\"e\":\"\"\n");
  printf("                m.write(\"<A HREF=\\\"javascript:parent.OpenClose('\"+after[idx].name+\"',\"+w1+\")\\\"\")\n");
  printf("                m.write(\" onClick=\\\"\"+after[idx].url+oMO+((w1==1)?vza:vzz)+rt+BU+w2+BOW+WH9+vza+\"\\\">\"+BU)\n");
  printf("                m.write(((w1==1)?zicon:oicon)+WH6+((w1==1)?vza:vzz)+\"\\\">&nbsp;\"+after[idx].text+\"</A><BR>\")\n");
  printf("                if(w1==0){zweig+=BU+((idx==after.length)?\"leer\":\"stamm-\"+BOW)+WHA;printNode(after[idx].name,zweig)}}\n");
  printf("                idx++\n");
  printf("        }\n");
  printf("}\n");
  printf(" \n");
  printf("function OpenClose(name,status){\n");
  printf("for(idx=1;idx<=mD.length;idx++){if(((mD[idx].typ==\"0\")||(mD[idx].typ==\"verz\"))&&(mD[idx].name==name)){vidx=idx}}\n");
  printf("if((Schliessen==1)&&(status==1)){\n");
  printf("if((CloseAll==1)||(mD[vidx].vor==mD[1].name)){for(idx=1;idx<=mD.length;idx++){mD[idx].open=0}}\n");
  printf("if((CloseAll==1)&&(mD[vidx].vor!=mD[1].name)){for(idx=1;idx<=mD.length;idx++){\n");
  printf("if(mD[idx].typ!=\"link\"){if(mD[idx].name==mD[vidx].vor){mD[idx].open=1\n");
  printf("if(mD[idx].vor!=mD[1].name){vvidx=idx;for(idx=1;idx<=mD.length;idx++){\n");
  printf("if(mD[idx].typ!=\"link\"){if(mD[idx].name==mD[vvidx].vor){mD[idx].open=1\n");
  printf("if(mD[idx].vor!=mD[1].name){vvvidx=idx;for(idx=1;idx<=mD.length;idx++){\n");
  printf("if(mD[idx].typ!=\"link\"){if(mD[idx].name==mD[vvvidx].vor){mD[idx].open=1\n");
  printf("if(mD[idx].vor!=mD[1].name){vvvvidx=idx;for(idx=1;idx<=mD.length;idx++){\n");
  printf("if(mD[idx].typ!=\"link\"){if(mD[idx].name==mD[vvvvidx].vor){mD[idx].open=1}\n");
  printf("else{alert(\"too much structure levels, set CloseAll to 0!\");idx=mD.length}}}}}}}}}}}}}}}}}\n");
  printf("mD[vidx].open=status\n");
  printf("eval(setTimeout(\"DrawMenu()\",50))\n");
  printf("if((mD[vidx].url!=\"\")&&((status==1)||(VerzZuLink==1))){frames[\"hexFrame\"].location.href=mD[vidx].url}}\n");
  printf(" \n");
  printf("function AllOpenClose(status){\n");
  printf("for(idx=1;idx<mD.length;idx++){mD[idx].open=status}\n");
  printf("DrawMenu()}\n");
  printf(" \n");
  printf("function Packet(){\n");
  printf("this.length=0\n");
  printf("this.neu=neu\n");
  printf("return this}\n");
  printf(" \n");
  printf("function neu(object){\n");
  printf("this.length++\n");
  printf("this[this.length]=object}\n");
  printf(" \n");
  printf("function HVE(name,text,icon,stat){\n");
  printf("this.name=name\n");
  printf("this.text=text\n");
  printf("this.icon=icon\n");
  printf("this.typ=\"0\"\n");
  printf("this.stat=stat\n");
  printf("return this}\n");
  printf(" \n");
  printf("function VE(name,vor,text,url,zicon,oicon,vstat){\n");
  printf("this.name=name\n");
  printf("this.vor=vor\n");
  printf("this.text=text\n");
  printf("this.url=url\n");
  printf("this.zicon=zicon\n");
  printf("this.oicon=oicon\n");
  printf("this.typ=\"verz\"\n");
  printf("this.open=0\n");
  printf("this.vstat=vstat\n");
  printf("return this}\n");
  printf(" \n");
  printf("function LE(vor,text,url,ziel,icon,lstat){\n");
  printf("this.vor=vor\n");
  printf("this.text=text\n");
  printf("this.url=url\n");
  printf("this.ziel=ziel\n");
  printf("this.icon=icon\n");
  printf("this.typ=\"link\"\n");
  printf("this.lstat=lstat\n");
  printf("return this}\n");
  printf(" \n");
  printf("//-->\n");
  printf(" \n");
  printf("</SCRIPT>\n");
  printf("<TITLE>%s</TITLE>\n", html_cfg.title);
  printf("</HEAD>\n");

  print_error_html();

  printf("</NOFRAMES>\n");
  printf("</BODY>\n");
  printf("</HEAD>\n");
  printf("</HTML>\n");
}


static void
print_control_panel(void)
{
  html_header();
  printf("<HTML><HEAD>\n");
  printf("<TITLE>%s</TITLE>\n</HEAD>\n", html_cfg.title);
  printf("<BODY BACKGROUND=\"%s\" BGCOLOR=\"%s\" TEXT=\"%s\">\n",
    html_cfg.background, html_cfg.bgcolor, html_cfg.text);
  printf("<TABLE border=0>\n");
  printf("<TR><TH>\n<FONT size=+1><FONT color=\"%s\">%s</FONT> / ", html_cfg.highlight, html_cfg.pre_title);
  printf("%s</FONT> / <FONT size=-1>Main control panel</FONT>\n</TH></TR>\n", html_cfg.title);
  printf("<TR><TD>\n<A HREF=\"%s/%s\" target=\"%s\"><IMG SRC=\"%s/%s\" BORDER=0> open help</A>\n</TD></TR>\n",
    html_cfg.base_path, html_cfg.help_page, html_cfg.target_help, html_cfg.base_path, html_cfg.img.help);
  printf("</TABLE>\n");


  /* print saved error message if we have one first... */
  if (HAVE_ERR)
    printf("<P>%s</P>\n", ERR_MSG);


  /* Part: Read and analyze existing dump-file */
  printf("<HR><H4>Read and analyze existing dump-file</H4>\n");
  printf("<blockquote><form action=\"%s\" method=%s name=read target=%s>\n",
    SELFNAME, html_cfg.method, html_cfg.target_read);
  printf("<input type=text name=r value=\"%s\" size=30> filename to open<br>\n", html_cfg.cf_default);
  printf("<input type=text name=R size=30> read filter rules<br>\n");
  /* define target window */
  printf("<input type=hidden name=status value=%s>\n", html_cfg.target_read);
  /* remember this part of panel - we are in mode "read" here*/
  printf("<input type=hidden name=mode value=read>\n");
  printf("<input type=submit value=go> <input type=reset value=reset>\n");
  printf("</FORM></blockquote>\n");
  
  /* Part: Capture to disk and analyze */
  printf("<HR><H4>Capture to disk and analyze</H4>\n");
  printf("<blockquote>\n");
  if (! html_cfg.enable_capture)
    printf("<P><i><FONT color=\"%s\">Capturing was disabled during compilation</FONT></i></P>\n",
    	html_cfg.highlight);
  printf("<form action=\"%s\" method=%s name=capt target=%s>\n",
    SELFNAME, html_cfg.method, html_cfg.target_capt);
  printf("<input type=text name=w value=\"%s\" size=30> capture to filename<br>\n", html_cfg.cf_default);
  printf("<input type=text name=f size=30> capture filter rules<br>\n");
  printf("<input type=text name=i value=eth0 size=6> use this interface<br>\n");
  printf("<input type=text name=c value=10 size=6> number of packets to capture, 0 for infinite<br>\n");
  /* define target window */
  printf("<input type=hidden name=status value=%s>\n", html_cfg.target_capt);
  /* remember this part of panel - we are in mode "capt" here*/
  printf("<input type=hidden name=mode value=capt>\n");
  printf("<input type=submit value=go> <input type=reset value=reset>\n");
  printf("</FORM></blockquote>\n");
  
  html_end();
}

static void
print_capture_page(void)
{
  html_header();
  printf("<HTML><HEAD>\n");
  printf("<TITLE>%s</TITLE>\n</HEAD>\n", html_cfg.title);
  printf("<BODY BACKGROUND=\"%s\" BGCOLOR=\"%s\" TEXT=\"%s\">\n",
    html_cfg.background, html_cfg.bgcolor, html_cfg.text);
  printf("<TABLE border=0>\n");
  printf("<TR><TH>\n<FONT size=+1><FONT color=\"%s\">%s</FONT> / ", html_cfg.highlight, html_cfg.pre_title);
  printf("%s</FONT> / <FONT size=-1>Capture control panel</FONT>\n</TH></TR>\n", html_cfg.title);
  printf("<TR><TD>\n<A HREF=\"%s/%s\" target=\"%s\"><IMG SRC=\"%s/%s\" BORDER=0> open help</A>\n</TD></TR>\n",
    html_cfg.base_path, html_cfg.help_page, html_cfg.target_help, html_cfg.base_path, html_cfg.img.help);
  printf("</TABLE>\n");
  
  printf("<HR>\n");

  
  /* HTML-output is closed at the end of main() ! */
}

static void
print_capture_footer(void)
{
  if (HAVE_ERR) {
    printf("<P>%s</P>\n", ERR_MSG);
  }
  else
    printf("<P>\nCapture completed\n</P>\n");

  html_end();
}

static void
print_dummy_page(void)
{
  html_header();
  printf("<HTML><HEAD>\n");
  printf("<TITLE>%s</TITLE>\n</HEAD>\n", html_cfg.title);
  printf("<BODY BACKGROUND=\"%s\" BGCOLOR=\"%s\" TEXT=\"%s\">\n",
    html_cfg.background, html_cfg.bgcolor, html_cfg.text);
  printf("<TABLE border=0>\n");
  printf("<TR><TH>\n<FONT size=+1><FONT color=\"%s\">%s</FONT> / ", html_cfg.highlight, html_cfg.pre_title);
  printf("%s</FONT> / <FONT size=-1>Dummy page</FONT>\n</TH></TR>\n", html_cfg.title);
  printf("<TR><TD>\n<A HREF=\"%s/%s\" target=\"%s\"><IMG SRC=\"%s/%s\" BORDER=0> open help</A>\n</TD></TR>\n",
    html_cfg.base_path, html_cfg.help_page, html_cfg.target_help, html_cfg.base_path, html_cfg.img.help);
  printf("</TABLE>\n");
  
  printf("<HR>\n");
  
  printf("<P>\nThis is just a dummy page. Most likely nothing went wrong \n");
  printf("but you didn't specify enough valid arguments. Try again, looser ;-)\n</P>\n");
  
  /* print saved error message if we have one... */
  if (HAVE_ERR)
    printf("I've received the following error-message from my sub-system:\n");
    printf("<P><MENU><LI>%s</LI></MENU></P>\n", ERR_MSG);


  html_end();
}

char *
get_filename (const char *in) {
  static char out[256];
  char help[256];
  int i;

  sprintf(help,"%s", in);

  /*
   * we replace all occurencies of some special characters to prevent people
   * from capturing to /etc/passwd, for example....
   */  
  for (i=0; i<=strlen(help); i++){
    switch (help[i]) {
      case ' ':
      case '%':
      case '!':
      case '"':
      case '§':
      case '$':
      case '&':
      case '?':
      case '*':
      case '~':
      case '/':
      case '\\':
        help[i] = '_';
	break;
      default:
    }
  }
  
  sprintf(out, "%s", help);

  return out;
}

/*
 * end of defining HTML- and JavaScript functions.
 */

int
main(int argc, char *argv[])
{
  int                   i;
  gboolean             arg_error = FALSE;
#ifdef HAVE_LIBPCAP
#ifdef WIN32
  char pcap_version[] = "0.4a6";
#else
  extern char          pcap_version[];
#endif
#endif

#ifdef WIN32
  WSADATA		wsaData;
#endif

  char                *gpf_path, *pf_path;
  int                  gpf_open_errno, pf_open_errno;
  int                  err;
#ifdef HAVE_LIBPCAP
  gboolean             capture_filter_specified = FALSE;
  int                  packet_count = 0;
  GList               *if_list;
  gchar                err_str[PCAP_ERRBUF_SIZE];
#else
  gboolean             capture_option_specified = FALSE;
#endif
  int                 out_file_type = WTAP_FILE_PCAP;
  gchar               *cf_name = NULL, *rfilter = NULL;
  char                cf_dummy[256];
  dfilter             *rfcode = NULL;
  e_prefs             *prefs;
  
  gboolean	      success;
  
  llist               cgi_entries;
  int                 cgi_paramnum;
  char                *cgi_status;
  
  /* Set global var SELFNAME to argv[0] for FORM-calls */
  strcpy(SELFNAME, argv[0]);
  
  /* Init global var LINKNR to 0 */
  LINKNR = 0;
  
  /* Set some properties of struct html_cfg */
  html_cfg.background	= "";			/* Background image for ALL frames */
  html_cfg.bgcolor	= "#eeeeee";		/* Background color */
  html_cfg.text		= "#000000";		/* Text color */
  html_cfg.link		= "#000000";		/* Link color, should be same as text */
  html_cfg.alink	= "#ff0000";		/* Active link color, displayed while clicking on link */
  html_cfg.vlink	= "#006600";		/* Visited link color */
  html_cfg.highlight	= "#ff0000";		/* Highlight color: for HEX/ASCII highlighting */

  html_cfg.base_path	= "/hethereal";		/* Path to images and .html files, relative to DocumentRoot. */
  html_cfg.help_page	= "hethereal_help.html";/* Help for hethereal */
  html_cfg.blank_page	= "blank.html";		/* Dummy-page to show on empty frames. Adjust colors there. */
  html_cfg.font		= "courier";		/* Use a FIXED font here! */
  html_cfg.font_size	= 9;			/* I won't comment this... */
  html_cfg.method	= "GET";		/* Do you prefer POST or GET for Form-values? */
  
  html_cfg.root_img	= "root.gif";		/* Image for root-tree entry */
  html_cfg.root_name	= "ethereal";		/* Text to display */
  html_cfg.root_link	= "http://www.ethereal.com/";;
  html_cfg.pre_title	= "Hethereal";		/* Prepend for html_cfg.title value, used in Control-Panel */
  sprintf(html_cfg.title, "GNU h%s %s", PACKAGE, VERSION);

  html_cfg.img.BlackOnWhite	= 0;			/* 0=White on Black, 1=BlackOnWhite */
  html_cfg.img.dummy		= "leer.gif";		/* should be transparent */
  html_cfg.img.box_close	= "box_zu.gif";		/* Image for closed nodes */
  html_cfg.img.box_open		= "box_auf.gif";	/* Image for open nodes */
  html_cfg.img.active		= "mark.gif";		/* Image for chosen packets */
  html_cfg.img.follow		= "follow.gif";		/* Image for follow TCP stream */
  html_cfg.img.help		= "help.gif";		/* Image for link to hethereal-help */

  html_cfg.cf_path		= "/tmp";		/* Directory for capture files */  
  html_cfg.cf_default		= "dump";		/* Default capture-file (for read and write) */
  
  html_cfg.target_read		= "dataWindow";		/* Browser's Window-Name for capture analyze */
  html_cfg.target_capt		= "captWindow";		/* Browser's Window-Name for capture output */
  html_cfg.target_help		= "helpWindow";		/* Browser's Window-Name for help file */
  
  html_cfg.enable_capture	= TRUE;			/* You can explicity turn Capturing OFF here */
  

  /* Generally enable Line-buffered standard output */
  setvbuf(stdout, NULL, _IOLBF, 0); 


  /* Register all dissectors; we must do this before checking for the
     "-G" flag, as the "-G" flag dumps a list of fields registered
     by the dissectors, and we must do it before we read the preferences,
     in case any dissectors register preferences. */
  epan_init(PLUGIN_DIR);

  /* Now register the preferences for any non-dissector modules.
     We must do that before we read the preferences as well. */
  prefs_register_modules();

  /* If invoked with the "-G" flag, we dump out a glossary of
     display filter symbols.

     We do this here to mirror what happens in the GTK+ version, although
     it's not necessary here. */
  if (argc >= 2 && strcmp(argv[1], "-G") == 0) {
    proto_registrar_dump();
    exit(0);
  }

  /* Set the C-language locale to the native environment. */
  setlocale(LC_ALL, "");

  prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path);
  if (gpf_path != NULL) {
    sprintf(ERR_MSG, "Can't open global preferences file \\\"%s\\\": %s.\n", pf_path,
        strerror(gpf_open_errno));
    HAVE_ERR = TRUE;
    fprintf(stderr, "%s", ERR_MSG);
  }
  if (pf_path != NULL) {
    sprintf(ERR_MSG, "Can't open your preferences file \\\"%s\\\": %s.\n", pf_path,
        strerror(pf_open_errno));
    HAVE_ERR = TRUE;
    fprintf(stderr, "%s", ERR_MSG);
  }
    
  /* Initialize the capture file struct */
  cfile.plist		= NULL;
  cfile.plist_end	= NULL;
  cfile.wth		= NULL;
  cfile.filename	= NULL;
  cfile.user_saved	= FALSE;
  cfile.is_tempfile	= FALSE;
  cfile.rfcode		= NULL;
  cfile.dfilter		= NULL;
  cfile.dfcode		= NULL;
#ifdef HAVE_LIBPCAP
  cfile.cfilter		= g_strdup("");
#endif
  cfile.iface		= NULL;
  cfile.save_file	= NULL;
  cfile.save_file_fd	= -1;
  cfile.snap		= WTAP_MAX_PACKET_SIZE;
  cfile.count		= 0;
  col_init(&cfile.cinfo, prefs->num_cols);

  /* Assemble the compile-time options */
  snprintf(comp_info_str, 256,
#ifdef GTK_MAJOR_VERSION
    "GTK+ %d.%d.%d, %s%s, %s%s, %s%s", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
    GTK_MICRO_VERSION,
#else
    "GTK+ (version unknown), %s%s, %s%s, %s%s",
#endif

#ifdef HAVE_LIBPCAP
   "with libpcap ", pcap_version,
#else
   "without libpcap", "",
#endif

#ifdef HAVE_LIBZ
#ifdef ZLIB_VERSION
   "with libz ", ZLIB_VERSION,
#else /* ZLIB_VERSION */
   "with libz ", "(version unknown)",
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
   "without libz", "",
#endif /* HAVE_LIBZ */

/* Oh, this is pretty */
#if defined(HAVE_UCD_SNMP_SNMP_H)
#ifdef HAVE_UCD_SNMP_VERSION_H
   "with UCD SNMP ", VersionInfo
#else /* HAVE_UCD_SNMP_VERSION_H */
   "with UCD SNMP ", "(version unknown)"
#endif /* HAVE_UCD_SNMP_VERSION_H */
#elif defined(HAVE_SNMP_SNMP_H)
#ifdef HAVE_SNMP_VERSION_H
   "with CMU SNMP ", snmp_Version()
#else /* HAVE_SNMP_VERSION_H */
   "with CMU SNMP ", "(version unknown)"
#endif /* HAVE_SNMP_VERSION_H */
#else /* no SNMP */
   "without SNMP", ""
#endif
   );

	
  /* Read CGI params. */
  cgi_paramnum = read_cgi_input(&cgi_entries);
  
  /* Test for value of status first */
  if ((cgi_status=cgi_val(cgi_entries, "status")) == NULL) {
    print_control_panel();
    exit(0);
  }
  else
    cgi_status = cgi_val(cgi_entries, "status");

        
  /* Do we have any arguments? */
  if (cgi_paramnum == 0) {
    print_control_panel();
    exit(0);
  }

  /* Flag "c" - Capture xxx packets (0 = infinite) */
  if (is_field_empty(cgi_entries, "c") != 1)
  {
#ifdef HAVE_LIBPCAP
    packet_count = (int)string_to_guint32(cgi_val(cgi_entries, "c"), &success);
    if (string_to_guint32(cgi_val(cgi_entries, "c"), &success) >= G_MAXINT)
      packet_count = (int)G_MAXINT;
    if (packet_count < 0) packet_count = 0;
#else
    capture_option_specified = TRUE;
    arg_error = TRUE;
#endif
  }

  /* Flag "f" - Capture file filter */
  if (is_field_empty(cgi_entries, "f") != 1)
  {
#ifdef HAVE_LIBPCAP
        capture_filter_specified = TRUE;
	cfile.cfilter = g_strdup(cgi_val(cgi_entries, "f"));
#else
        capture_option_specified = TRUE;
        arg_error = TRUE;
#endif
  }

  /* Flag "w" - Capture to file xxx */
  if (is_field_empty(cgi_entries, "w") != 1)
  {
    /* cfile.save_file = get_filename(cgi_val(cgi_entries, "w")); */
    /* Add PATH to cfile.save_file for capture-files */
    sprintf(cf_dummy, "%s/%s", html_cfg.cf_path, get_filename(cgi_val(cgi_entries, "w")));
    cfile.save_file = cf_dummy;
  }

  /* Flag "i" - Capture from interface xxx */
  if (is_field_empty(cgi_entries, "i") != 1)
  {
#ifdef HAVE_LIBPCAP
        cfile.iface = g_strdup(cgi_val(cgi_entries, "i"));
#else
        capture_option_specified = TRUE;
        arg_error = TRUE;
#endif
  }
  
  /* Flag "r" - Read capture file xxx */
  if (is_field_empty(cgi_entries, "r") != 1)
  {
    cf_name = get_filename(cgi_val(cgi_entries, "r"));
    /* copy raw cf_name (without path) to CFNAME. This must be done cause
     * CFNAME will be used as CGI-param to hethereal which means that this
     * value will be the next raw cf_name. */
    strcpy(CFNAME, cf_name);
    /* Now add PATH to internal var cf_name */
    sprintf(cf_dummy, "%s/%s", html_cfg.cf_path, cf_name);
    cf_name = cf_dummy;
  }
  else
  {
    /* no input-file given -> check, if we stay in control-panel mode */
    if (is_field_empty(cgi_entries, "mode") != 1) {
      if (strcmp(cgi_val(cgi_entries, "mode"), "read") == 0) {
        /* stay in control-panel -> do nothing */
        sprintf(ERR_MSG, "You must specify a valid filename to read from.\n");
	HAVE_ERR = TRUE;
        fprintf(stderr, "%s", ERR_MSG);
	print_dummy_page();
	exit(0);
      }
      /* See if we jump to capture mode */
      if (strcmp(cgi_val(cgi_entries, "mode"), "capt") == 0) {
	/* check if we have turned of capturing capabilities */
	if (! html_cfg.enable_capture) {
	  print_capture_page();
	  sprintf(ERR_MSG, "Capturing was disabled in Source-Code.<BR>\nCheck var \"html_cfg.enable_capture\".\n");
	  HAVE_ERR = TRUE;
	  print_capture_footer();
	  exit(0);
	}
	/* Do we capture to a file? */
	if (cfile.save_file != NULL) print_capture_page();
	else {
	  /* LIVE CAPTURE - we only support "one shot mode" here */
	  packet_count = 1;
	  verbose = TRUE;
	  print_hex = TRUE;
	  sprintf(cf_dummy, "dataFrame");
	  cgi_status = cf_dummy;
	}
      }
    }
    else {
      print_dummy_page();
      exit(0);
    }
  }
  
  /* Flag "R" - Read file filter */
  if (is_field_empty(cgi_entries, "R") != 1)
    rfilter = cgi_val(cgi_entries, "R");
  else
    rfilter = "";
  strcpy(RFILTER, rfilter);
  
  /* Flag "x" - Print packet data in hex (and ASCII) */
  if (is_field_empty(cgi_entries, "x") != 1)
    if (strcmp(cgi_val(cgi_entries, "x"), "on") == 0)
      print_hex = TRUE;
    
  /* Flag "V" - Verbose */
  if (is_field_empty(cgi_entries, "V") != 1)
    if (strcmp(cgi_val(cgi_entries, "V"), "on") == 0)
      verbose = TRUE;

  /* Extra Flag "sort" */
  if (is_field_empty(cgi_entries, "sort") != 1)
  {
    sprintf(RFILTER, "frame.number==%s", cgi_val(cgi_entries, "sort"));
    rfilter = strdup(RFILTER);
  }

  /* Now start appropriate print_html-function according to value of var "cgi_status" */
  if (strcmp(cgi_status, "dataWindow") == 0) print_html_menu_header();
  else if (strcmp(cgi_status, "dataFrame") == 0) print_html_data_header();


#ifdef WIN32
  /* Start windows sockets */
  WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
#endif

  /* Notify all registered modules that have had any of their preferences
     changed either from one of the preferences file or from the command
     line that its preferences have changed. */
  prefs_apply_all();

#ifndef HAVE_LIBPCAP
  if (capture_option_specified)
    sprintf(ERR_MSG, "This version of Hethereal was not built with support for capturing packets.\n");
    HAVE_ERR = TRUE;
    fprintf(stderr, "%s", ERR_MSG);
#endif
  if (arg_error) {
    print_dummy_page();
    exit(0);
  }


  /* Build the column format array */  
  for (i = 0; i < cfile.cinfo.num_cols; i++) {
    cfile.cinfo.col_fmt[i] = get_column_format(i);
    cfile.cinfo.col_title[i] = g_strdup(get_column_title(i));
    cfile.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
      NUM_COL_FMTS);
    get_column_format_matches(cfile.cinfo.fmt_matx[i], cfile.cinfo.col_fmt[i]);
    cfile.cinfo.col_data[i] = NULL;
    if (cfile.cinfo.col_fmt[i] == COL_INFO)
      cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
    else
      cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
  }

  if (cfile.snap < 1)
    cfile.snap = WTAP_MAX_PACKET_SIZE;
  else if (cfile.snap < MIN_PACKET_SIZE)
    cfile.snap = MIN_PACKET_SIZE;
  
  if (rfilter != NULL) {
    if (dfilter_compile(rfilter, &rfcode) != 0) {
      sprintf(ERR_MSG, "hethereal: %s\n", dfilter_error_msg);
      HAVE_ERR = TRUE;
      fprintf(stderr, "%s", ERR_MSG);

      /* print the appropriate footer before exiting */
      if (strcmp(cgi_status, "dataWindow") == 0) print_html_menu_footer();
      else if (strcmp(cgi_status, "dataFrame") == 0) print_html_data_footer();
           else html_end();

      epan_cleanup();
      exit(2);
    }
  }
  cfile.rfcode = rfcode;
  if (cf_name) {
    err = open_cap_file(cf_name, FALSE, &cfile);
    if (err != 0) {
      epan_cleanup();
      print_html_menu_footer();
      exit(0);
    }
    err = load_cap_file(&cfile, out_file_type);
    if (err != 0) {
      epan_cleanup();
      exit(2);
    }
    cf_name[0] = '\0';
  } else {
    /* No capture file specified, so we're supposed to do a live capture;
       do we have support for live captures? */
#ifdef HAVE_LIBPCAP
    /* Yes; did the user specify an interface to use? */
    if (cfile.iface == NULL) {
        /* No - pick the first one from the list of interfaces. */
        if_list = get_interface_list(&err, err_str);
        if (if_list == NULL) {
            switch (err) {

            case CANT_GET_INTERFACE_LIST:
                sprintf(ERR_MSG, "hethereal: Can't get list of interfaces: %s\n",
			err_str);
		HAVE_ERR = TRUE;
		fprintf(stderr, "%s", ERR_MSG);
                break;

            case NO_INTERFACES_FOUND:
                sprintf(ERR_MSG, "hethereal: There are no interfaces on which a capture can be done\n");
		HAVE_ERR = TRUE;
		fprintf(stderr, "%s", ERR_MSG);
                break;
            }
            exit(2);
        }
        cfile.iface = g_strdup(if_list->data);	/* first interface */
        free_interface_list(if_list);
    }
    capture(packet_count, out_file_type);
#else
    /* No - complain. */
    sprintf(ERR_MSG, "This version of Hethereal was not built with support for capturing packets.\n");
    HAVE_ERR = TRUE;
    fprintf(stderr, "%s", ERR_MSG);
    exit(2);
#endif
  }

  epan_cleanup();


  /* Print HTML footer. Do this only ONCE and only HERE! */
  
  if (strcmp(cgi_status, "dataWindow") == 0) print_html_menu_footer();
  else if (strcmp(cgi_status, "dataFrame") == 0) print_html_data_footer();
       else if (strcmp(cgi_status, "captWindow") == 0) print_capture_footer();
            else html_end();

  exit(0);
}

#ifdef HAVE_LIBPCAP
/* Do the low-level work of a capture.
   Returns TRUE if it succeeds, FALSE otherwise. */
static int
capture(int packet_count, int out_file_type)
{
  gchar       err_str[PCAP_ERRBUF_SIZE];
  bpf_u_int32 netnum, netmask;
  void        (*oldhandler)(int);
  int         err, inpkts;
  char        errmsg[1024+1];
#ifndef _WIN32
  static const char ppamsg[] = "can't find PPA for ";
  char       *libpcap_warn;
#endif

  /* Initialize the table of conversations. */
  epan_conversation_init();

  /* Initialize protocol-specific variables */
  init_all_protocols();

  ld.linktype       = WTAP_ENCAP_UNKNOWN;
  ld.pdh            = NULL;

  /* Open the network interface to capture from it. */
  ld.pch = pcap_open_live(cfile.iface, cfile.snap, promisc_mode, 1000, err_str);

  if (ld.pch == NULL) {
    /* Well, we couldn't start the capture. */
#ifdef _WIN32
    /* On Win32 OSes, the capture devices are probably available to all
       users; don't warn about permissions problems.

       Do, however, warn that Token Ring and PPP devices aren't supported. */
    snprintf(errmsg, sizeof errmsg,
	"The capture session could not be initiated (%s).\n"
	"Please check that you have the proper interface specified.\n"
	"\n"
	"Note that the driver Hethereal uses for packet capture on Windows\n"
	"doesn't support capturing on Token Ring interfaces, and doesn't\n"
	"support capturing on PPP/WAN interfaces in Windows NT/2000.\n",
	err_str);
#else
      /* If we got a "can't find PPA for XXX" message, warn the user (who
         is running Ethereal on HP-UX) that they don't have a version
	 of libpcap patched to properly handle HP-UX (the patched version
	 says "can't find /dev/dlpi PPA for XXX" rather than "can't find
	 PPA for XXX"). */
      if (strncmp(err_str, ppamsg, sizeof ppamsg - 1) == 0)
	libpcap_warn =
	  "\n\n"
	  "You are running hethereal with a version of the libpcap library\n"
	  "that doesn't handle HP-UX network devices well; this means that\n"
	  "Hethereal may not be able to capture packets.\n"
	  "\n"
	  "To fix this, you will need to download the source to Hethereal\n"
	  "from www.ethereal.com if you have not already done so, read\n"
	  "the instructions in the \\\"README.hpux\\\" file in the source\n"
	  "distribution, download the source to libpcap if you have not\n"
	  "already done so, patch libpcap as per the instructions, rebuild\n"
	  "and install libpcap, and then build Hethereal (if you have already\n"
	  "built Hethereal from source, do a \\\"make distclean\\\" and re-run\n"
	  "configure before building).";
      else
	libpcap_warn = "";
    snprintf(errmsg, sizeof errmsg,
      "The capture session could not be initiated (%s).\n"
      "Please check to make sure you have sufficient permissions, and that\n"
      "you have the proper interface specified.%s", err_str, libpcap_warn);
#endif
    goto error;
  }

  if (cfile.cfilter) {
    /* A capture filter was specified; set it up. */
    if (pcap_lookupnet (cfile.iface, &netnum, &netmask, err_str) < 0) {
      /*
       * Well, we can't get the netmask for this interface; it's used
       * only for filters that check for broadcast IP addresses, so
       * we just warn the user, and punt and use 0.
       */
      sprintf(ERR_MSG, 
        "Warning:  Couldn't obtain netmask info (%s)\n.", err_str);
      HAVE_ERR = TRUE;
      fprintf(stderr, "%s", ERR_MSG);
      netmask = 0;
    }
    if (pcap_compile(ld.pch, &cfile.fcode, cfile.cfilter, 1, netmask) < 0) {
      snprintf(errmsg, sizeof errmsg, "Unable to parse filter string (%s).",
	pcap_geterr(ld.pch));
      goto error;
    }
    if (pcap_setfilter(ld.pch, &cfile.fcode) < 0) {
      snprintf(errmsg, sizeof errmsg, "Can't install filter (%s).",
	pcap_geterr(ld.pch));
      goto error;
    }
  }

  ld.linktype = wtap_pcap_encap_to_wtap_encap(pcap_datalink(ld.pch));
  if (cfile.save_file != NULL) {
    /* Set up to write to the capture file. */
    if (ld.linktype == WTAP_ENCAP_UNKNOWN) {
      strcpy(errmsg, "The network you're capturing from is of a type"
               " that Hethereal doesn't support.");
      goto error;
    }
    ld.pdh = wtap_dump_open(cfile.save_file, out_file_type,
		ld.linktype, pcap_snapshot(ld.pch), &err);

    if (ld.pdh == NULL) {
      snprintf(errmsg, sizeof errmsg, file_open_error_message(errno, TRUE),
		cfile.save_file);
      goto error;
    }
  }

  /* Catch SIGINT and SIGTERM and, if we get either of them, clean up
     and exit.
     XXX - deal with signal semantics on various platforms.  Or just
     use "sigaction()" and be done with it? */
  signal(SIGTERM, capture_cleanup);
  signal(SIGINT, capture_cleanup);
#if !defined(WIN32)
  if ((oldhandler = signal(SIGHUP, capture_cleanup)) != SIG_DFL)
    signal(SIGHUP, oldhandler);
#endif

  /*
   * Do only generate output here if we capture to a file.
   * Otherwise we are in one-shot-mode and output the full
   * package-tree to the capture-control window.
   *
   * XXX - unfortunately we loose the packet-summary here.
   */
  if (cfile.save_file != NULL) {

    /* Let the user know how man packets we capture and what interface was chosen. */
    if (packet_count == G_MAXINT)
      printf("Capturing max. possible packets due to integer limitations (G_MAXINT = %d) \n", G_MAXINT);
    else
      if (packet_count >= 1)
        printf("Capturing <FONT color=\"%s\">%u</FONT> packets \n", html_cfg.highlight, packet_count);
      else
        printf("Capturing infinite amount of packets \n");

    printf("on <FONT color=\"%s\">%s</FONT><BR>\n", html_cfg.highlight, cfile.iface);
    printf("Use browser's <FONT color=\"%s\">STOP button</FONT> to abort<BR>\n",
    html_cfg.highlight);
    printf("Printing hash-mark (#) for each packet, 10 in a block, 50 in a row<BR>\n");
  }


  inpkts = pcap_loop(ld.pch, packet_count, capture_pcap_cb, (u_char *) &ld);
  pcap_close(ld.pch);

  /* Send a newline if we were printing packet counts to stdout */
  if (cfile.save_file != NULL) {
    printf("\n");
  }

  return TRUE;

error:
  g_free(cfile.save_file);
  cfile.save_file = NULL;
  sprintf(ERR_MSG, "hethereal: %s\n", errmsg);
  HAVE_ERR = TRUE;
  fprintf(stderr, "%s", ERR_MSG);
  if (ld.pch != NULL)
    pcap_close(ld.pch);

  return FALSE;
}

static void
capture_pcap_cb(u_char *user, const struct pcap_pkthdr *phdr,
  const u_char *pd)
{
  struct wtap_pkthdr whdr;
  loop_data *ld = (loop_data *) user;
  cb_args_t args;

  whdr.ts.tv_sec = phdr->ts.tv_sec;
  whdr.ts.tv_usec = phdr->ts.tv_usec;
  whdr.caplen = phdr->caplen;
  whdr.len = phdr->len;
  whdr.pkt_encap = ld->linktype;

  args.cf = &cfile;
  args.pdh = ld->pdh;
  if (ld->pdh) {
    wtap_dispatch_cb_write((u_char *)&args, &whdr, 0, NULL, pd);
    /* Do some nice hash-output here */
    if ((cfile.count % 50) == 1) printf("<BR>\r%04u&nbsp;&nbsp;&nbsp;", cfile.count);
    else if ((cfile.count % 10) == 1) printf("\r&nbsp;");
    printf("#");
    fflush(stdout);
  } else {
    wtap_dispatch_cb_print((u_char *)&args, &whdr, 0, NULL, pd);
  }
}

static void
capture_cleanup(int signum)
{
  int err;

  printf("\n");
  pcap_close(ld.pch);
  if (ld.pdh != NULL)
    wtap_dump_close(ld.pdh, &err);
  /* XXX - complain if this fails */
  exit(0);
}
#endif /* HAVE_LIBPCAP */

static int
load_cap_file(capture_file *cf, int out_file_type)
{
  gint         linktype;
  wtap_dumper *pdh;
  int          err;
  int          success;
  cb_args_t    args;

  linktype = wtap_file_encap(cf->wth);
  if (cf->save_file != NULL) {
    /* Set up to write to the capture file. */
    pdh = wtap_dump_open(cf->save_file, out_file_type,
		linktype, wtap_snapshot_length(cf->wth), &err);

    if (pdh == NULL) {
      /* We couldn't set up to write to the capture file. */
      /* So we can set HAVE_ERR globaly here */
      HAVE_ERR = TRUE;
      
      switch (err) {

      case WTAP_ERR_UNSUPPORTED_FILE_TYPE:
        sprintf(ERR_MSG,
		"hethereal: Capture files can't be written in that format.\n");
	fprintf(stderr, "%s", ERR_MSG);
        break;

      case WTAP_ERR_UNSUPPORTED_ENCAP:
      case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
        sprintf(ERR_MSG,
"hethereal: The capture file being read cannot be written in that format.\n");
	fprintf(stderr, "%s", ERR_MSG);
        break;

      case WTAP_ERR_CANT_OPEN:
        sprintf(ERR_MSG,
"hethereal: The file \\\"%s\\\" couldn't be created for some unknown reason.\n",
                 cf->save_file);
	fprintf(stderr, "%s", ERR_MSG);
        break;

      case WTAP_ERR_SHORT_WRITE:
        sprintf(ERR_MSG,
"hethereal: A full header couldn't be written to the file \\\"%s\\\".\n",
		cf->save_file);
	fprintf(stderr, "%s", ERR_MSG);
        break;

      default:
        if (err < 0) {
          sprintf(ERR_MSG,
		"hethereal: The file \\\"%s\\\" could not be opened: Error %d.\n",
   		cf->save_file, err);
	  fprintf(stderr, "%s", ERR_MSG);
        } else {
          sprintf(ERR_MSG,
		"hethereal: The file \\\"%s\\\" could not be opened: %s\n.",
 		cf->save_file, strerror(err));
	  fprintf(stderr, "%s", ERR_MSG);
        }
        break;
      }
      goto out;
    }
    args.cf = cf;
    args.pdh = pdh;
    success = wtap_loop(cf->wth, 0, wtap_dispatch_cb_write, (u_char *) &args,
 			&err);
  } else {
    args.cf = cf;
    args.pdh = NULL;
    success = wtap_loop(cf->wth, 0, wtap_dispatch_cb_print, (u_char *) &args,
 			&err);
  }
  if (!success) {
    /* Print up a message box noting that the read failed somewhere along
       the line. */
       
    /* Set HAVE_ERR here */
    HAVE_ERR = TRUE;
    
    switch (err) {

    case WTAP_ERR_UNSUPPORTED_ENCAP:
      sprintf(ERR_MSG,
"hethereal: The capture file is for a network type that Hethereal doesn't support.\n");
      fprintf(stderr, "%s", ERR_MSG);
      break;

    case WTAP_ERR_CANT_READ:
      sprintf(ERR_MSG,
"hethereal: An attempt to read from the file failed for some unknown reason.\n");
      fprintf(stderr, "%s", ERR_MSG);
      break;

    case WTAP_ERR_SHORT_READ:
      sprintf(ERR_MSG,
"hethereal: The capture file appears to have been cut short in the middle of a packet.\n");
      fprintf(stderr, "%s", ERR_MSG);
      break;

    case WTAP_ERR_BAD_RECORD:
      sprintf(ERR_MSG,
"hethereal: The capture file appears to be damaged or corrupt.\n");
      fprintf(stderr, "%s", ERR_MSG);
      break;

    default:
      sprintf(ERR_MSG,
"hethereal: An error occurred while reading the capture file: %s.\n",
	wtap_strerror(err));
      fprintf(stderr, "%s", ERR_MSG);
      break;
    }
  }

out:
  wtap_close(cf->wth);
  cf->wth = NULL;

  return err;
}

static void
fill_in_fdata(frame_data *fdata, capture_file *cf,
	const struct wtap_pkthdr *phdr,
	const union wtap_pseudo_header *pseudo_header, int offset)
{
  int i;

  fdata->next = NULL;
  fdata->prev = NULL;
  fdata->pfd = NULL;
  fdata->num = cf->count;
  fdata->pkt_len = phdr->len;
  fdata->cap_len = phdr->caplen;
  fdata->file_off = offset;
  fdata->cinfo = NULL;
  fdata->lnk_t = phdr->pkt_encap;
  fdata->abs_secs  = phdr->ts.tv_sec;
  fdata->abs_usecs = phdr->ts.tv_usec;
  fdata->flags.passed_dfilter = 0;
  fdata->flags.encoding = CHAR_ASCII;
  fdata->flags.visited = 0;
  fdata->flags.marked = 0;

  /* If we don't have the time stamp of the first packet in the
     capture, it's because this is the first packet.  Save the time
     stamp of this packet as the time stamp of the first packet. */
  if (!firstsec && !firstusec) {
    firstsec  = fdata->abs_secs;
    firstusec = fdata->abs_usecs;
  }

  /* If we don't have the time stamp of the previous displayed packet,
     it's because this is the first displayed packet.  Save the time
     stamp of this packet as the time stamp of the previous displayed
     packet. */
  if (!prevsec && !prevusec) {
    prevsec  = fdata->abs_secs;
    prevusec = fdata->abs_usecs;
  }

  /* Get the time elapsed between the first packet and this packet. */
  compute_timestamp_diff(&fdata->rel_secs, &fdata->rel_usecs,
		fdata->abs_secs, fdata->abs_usecs, firstsec, firstusec);

  /* If it's greater than the current elapsed time, set the elapsed time
     to it (we check for "greater than" so as not to be confused by
     time moving backwards). */
  if (cf->esec < fdata->rel_secs
	|| (cf->esec == fdata->rel_secs && cf->eusec < fdata->rel_usecs)) {
    cf->esec = fdata->rel_secs;
    cf->eusec = fdata->rel_usecs;
  }
  
  /* Get the time elapsed between the previous displayed packet and
     this packet. */
  compute_timestamp_diff(&fdata->del_secs, &fdata->del_usecs,
		fdata->abs_secs, fdata->abs_usecs, prevsec, prevusec);
  prevsec = fdata->abs_secs;
  prevusec = fdata->abs_usecs;

  fdata->cinfo = &cf->cinfo;
  for (i = 0; i < fdata->cinfo->num_cols; i++) {
    fdata->cinfo->col_buf[i][0] = '\0';
    fdata->cinfo->col_data[i] = fdata->cinfo->col_buf[i];
  }
}

static void
wtap_dispatch_cb_write(u_char *user, const struct wtap_pkthdr *phdr, int offset,
  union wtap_pseudo_header *pseudo_header, const u_char *buf)
{
  cb_args_t    *args = (cb_args_t *) user;
  capture_file *cf = args->cf;
  wtap_dumper  *pdh = args->pdh;
  frame_data    fdata;
  proto_tree   *protocol_tree;
  int           err;
  gboolean      passed;
  epan_dissect_t *edt;

  cf->count++;
  if (cf->rfcode) {
    fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset);
    protocol_tree = proto_tree_create_root();
    edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree);
    passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len);
  } else {
    protocol_tree = NULL;
    passed = TRUE;
    edt = NULL;
  }
  if (passed) {
    /* XXX - do something if this fails */
    wtap_dump(pdh, phdr, pseudo_header, buf, &err);
  }
  if (protocol_tree != NULL)
    proto_tree_free(protocol_tree);
  if (edt != NULL)
    epan_dissect_free(edt);
}

static void
wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr,
  int offset, union wtap_pseudo_header *pseudo_header, const u_char *buf)
{
  cb_args_t    *args = (cb_args_t *) user;
  capture_file *cf = args->cf;
  frame_data    fdata;
  proto_tree   *protocol_tree;
  gboolean      passed;
  print_args_t  print_args;
  epan_dissect_t *edt;
  int           i;
/*  char java_active[256];
  strncpy(java_active, html_cfg.img.active, sizeof(html_cfg.img.active) - 4); */

  cf->count++;

  /* The protocol tree will be "visible", i.e., printed, only if we're
     not printing a summary. */
  proto_tree_is_visible = verbose;

  fill_in_fdata(&fdata, cf, phdr, pseudo_header, offset);

  passed = TRUE;
  if (cf->rfcode || verbose)
    protocol_tree = proto_tree_create_root();
  else
    protocol_tree = NULL;
  edt = epan_dissect_new(pseudo_header, buf, &fdata, protocol_tree);
  if (cf->rfcode)
    passed = dfilter_apply(cf->rfcode, protocol_tree, buf, fdata.cap_len);
  if (passed) {
    /* The packet passed the read filter. */
    if (verbose) {
      /* Print the information in the protocol tree. */
      /* JavaScript/HTML formatting is completely done through proto_tree_print */
      print_args.to_file = TRUE;
      print_args.format = PR_FMT_HTML;
      print_args.print_summary = FALSE;
      print_args.print_hex = print_hex;
      print_args.expand_all = TRUE;
      proto_tree_print(FALSE, &print_args, (GNode *)protocol_tree,
			buf, &fdata, stdout);
    } else {
      /* Just fill in the columns. */
      fill_in_columns(&fdata);

      /* 
       * print row header first
       *
       * here we have to reference each packet by cf->cinfo.col_data[0]
       * we also have to reference the target-frames here!
       * AND: we have to use JavaScript to reference a particular frame
       */
      printf("m.write(\"\\n<img src=\\\"%s/%s\\\" name=\\\"%s\\\"><a href=\\\"",
	html_cfg.base_path, html_cfg.img.dummy, cf->cinfo.col_data[0]);     
      printf("%s?r=%s&sort=%s&x=on&V=on&status=dataFrame&mode=read\\\" ", SELFNAME, CFNAME, cf->cinfo.col_data[0]); 
      printf("onClick=\\\"changeImage(%d,mark); return true\\\" target=\\\"dataFrame\\\">\")\n", LINKNR);
      printf("m.write(\"");
      
      /* Increase var LINKNR */
      LINKNR++;

      /* Now print them. */
      for (i = 0; i < cf->cinfo.num_cols; i++) {
        switch (cf->cinfo.col_fmt[i]) {
	case COL_NUMBER:
	  /*
	   * Don't print this if we're doing a live capture from a network
	   * interface - if we're doing a live capture, you won't be
	   * able to look at the capture in the future (it's not being
	   * saved anywhere), so the frame numbers are unlikely to be
	   * useful.
	   *
	   * (XXX - it might be nice to be able to save and print at
	   * the same time, sort of like an "Update list of packets
	   * in real time" capture in Ethereal.)
	   */
          if (cf->iface != NULL)
            continue;
      
          printf("%3s", cf->cinfo.col_data[i]);
          break;

        case COL_CLS_TIME:
        case COL_REL_TIME:
        case COL_ABS_TIME:
        case COL_ABS_DATE_TIME:	/* XXX - wider */
          printf("%10s", cf->cinfo.col_data[i]);
          break;

        case COL_DEF_SRC:
        case COL_RES_SRC:
        case COL_UNRES_SRC:
        case COL_DEF_DL_SRC:
        case COL_RES_DL_SRC:
        case COL_UNRES_DL_SRC:
        case COL_DEF_NET_SRC:
        case COL_RES_NET_SRC:
        case COL_UNRES_NET_SRC:
          printf("%12s", cf->cinfo.col_data[i]);
          break;

        case COL_DEF_DST:
        case COL_RES_DST:
        case COL_UNRES_DST:
        case COL_DEF_DL_DST:
        case COL_RES_DL_DST:
        case COL_UNRES_DL_DST:
        case COL_DEF_NET_DST:
        case COL_RES_NET_DST:
        case COL_UNRES_NET_DST:
          printf("%-12s", cf->cinfo.col_data[i]);
          break;

        default:
          printf("%s", cf->cinfo.col_data[i]);
          break;
        }
        if (i != cf->cinfo.num_cols - 1) {
          /*
	   * This isn't the last column, so we need to print a
	   * separator between this column and the next.
	   *
	   * If we printed a network source and are printing a
	   * network destination of the same type next, separate
	   * them with "->"; if we printed a network destination
	   * and are printing a network source of the same type
	   * next, separate them with "<-"; otherwise separate them
	   * with a space.
	   */
	  switch (cf->cinfo.col_fmt[i]) {

	  case COL_DEF_SRC:
	  case COL_RES_SRC:
	  case COL_UNRES_SRC:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_DST:
	    case COL_RES_DST:
	    case COL_UNRES_DST:
	      printf(" -> ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  case COL_DEF_DL_SRC:
	  case COL_RES_DL_SRC:
	  case COL_UNRES_DL_SRC:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_DL_DST:
	    case COL_RES_DL_DST:
	    case COL_UNRES_DL_DST:
	      printf(" -> ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  case COL_DEF_NET_SRC:
	  case COL_RES_NET_SRC:
	  case COL_UNRES_NET_SRC:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_NET_DST:
	    case COL_RES_NET_DST:
	    case COL_UNRES_NET_DST:
	      printf(" -> ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  case COL_DEF_DST:
	  case COL_RES_DST:
	  case COL_UNRES_DST:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_SRC:
	    case COL_RES_SRC:
	    case COL_UNRES_SRC:
	      printf(" <- ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  case COL_DEF_DL_DST:
	  case COL_RES_DL_DST:
	  case COL_UNRES_DL_DST:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_DL_SRC:
	    case COL_RES_DL_SRC:
	    case COL_UNRES_DL_SRC:
	      printf(" <- ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  case COL_DEF_NET_DST:
	  case COL_RES_NET_DST:
	  case COL_UNRES_NET_DST:
	    switch (cf->cinfo.col_fmt[i + 1]) {

	    case COL_DEF_NET_SRC:
	    case COL_RES_NET_SRC:
	    case COL_UNRES_NET_SRC:
	      printf(" <- ");
	      break;

	    default:
	      putchar(' ');
	      break;
	    }
	    break;

	  default:
	    putchar(' ');
	    break;
	  }
	}
      }
      /* putchar('\n'); */
      
      /* lets close the open href */
      printf("</a><br>\")\n");
      
    }
    if (print_hex) {
      print_hex_data(stdout, print_args.format, buf,
			fdata.cap_len, fdata.flags.encoding);
      putchar('\n');
    }
    fdata.cinfo = NULL;
  }
  if (protocol_tree != NULL)
    proto_tree_free(protocol_tree);

  epan_dissect_free(edt);

  proto_tree_is_visible = FALSE;
}

char *
file_open_error_message(int err, gboolean for_writing)
{
  char *errmsg;
  static char errmsg_errno[1024+1];

  switch (err) {

  case WTAP_ERR_NOT_REGULAR_FILE:
    errmsg = "The file \\\"%s\\\" is a \\\"special file\\\" or socket or other non-regular file.";
    break;

  case WTAP_ERR_FILE_UNKNOWN_FORMAT:
  case WTAP_ERR_UNSUPPORTED:
    /* Seen only when opening a capture file for reading. */
    errmsg = "The file \\\"%s\\\" is not a capture file in a format Hethereal understands.";
    break;

  case WTAP_ERR_UNSUPPORTED_FILE_TYPE:
    /* Seen only when opening a capture file for writing. */
    errmsg = "Hethereal does not support writing capture files in that format.";
    break;

  case WTAP_ERR_UNSUPPORTED_ENCAP:
  case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
    if (for_writing)
      errmsg = "Hethereal cannot save this capture in that format.";
    else
      errmsg = "The file \\\"%s\\\" is a capture for a network type that Hethereal doesn't support.";
    break;

  case WTAP_ERR_BAD_RECORD:
    errmsg = "The file \\\"%s\\\" appears to be damaged or corrupt.";
    break;

  case WTAP_ERR_CANT_OPEN:
    if (for_writing)
      errmsg = "The file \\\"%s\\\" could not be created for some unknown reason.";
    else
      errmsg = "The file \\\"%s\\\" could not be opened for some unknown reason.";
    break;

  case WTAP_ERR_SHORT_READ:
    errmsg = "The file \\\"%s\\\" appears to have been cut short"
             " in the middle of a packet.";
    break;

  case WTAP_ERR_SHORT_WRITE:
    errmsg = "A full header couldn't be written to the file \\\"%s\\\".";
    break;

  case ENOENT:
    if (for_writing)
      errmsg = "The path to the file \\\"%s\\\" does not exist.";
    else
      errmsg = "The file \\\"%s\\\" does not exist.";
    break;

  case EACCES:
    if (for_writing)
      errmsg = "You do not have permission to create or write to the file \\\"%s\\\".";
    else
      errmsg = "You do not have permission to read the file \\\"%s\\\".";
    break;

  case EISDIR:
    errmsg = "\\\"%s\\\" is a directory (folder), not a file.";
    break;

  default:
    snprintf(errmsg_errno, sizeof(errmsg_errno),
	     "The file \\\"%%s\\\" could not be opened: %s.",
	     wtap_strerror(err));
    errmsg = errmsg_errno;
    break;
  }
  return errmsg;
}

int
open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
{
  wtap       *wth;
  int         err;
  FILE_T      fh;
  int         fd;
  struct stat cf_stat;
  char        err_msg[2048+1];

  wth = wtap_open_offline(fname, &err, FALSE);
  if (wth == NULL)
    goto fail;

  /* Find the size of the file. */
  fh = wtap_file(wth);
  fd = wtap_fd(wth);
  if (fstat(fd, &cf_stat) < 0) {
    err = errno;
    wtap_close(wth);
    goto fail;
  }

  /* The open succeeded.  Fill in the information for this file. */

  /* Initialize the table of conversations. */
  epan_conversation_init();

  /* Initialize protocol-specific variables */
  init_all_protocols();

  cf->wth = wth;
  cf->filed = fd;
  cf->f_len = cf_stat.st_size;

  /* Set the file name because we need it to set the follow stream filter.
     XXX - is that still true?  We need it for other reasons, though,
     in any case. */
  cf->filename = g_strdup(fname);

  /* Indicate whether it's a permanent or temporary file. */
  cf->is_tempfile = is_tempfile;

  /* If it's a temporary capture buffer file, mark it as not saved. */
  cf->user_saved = !is_tempfile;

  cf->cd_t      = wtap_file_type(cf->wth);
  cf->count     = 0;
  cf->drops     = 0;
  cf->esec      = 0;
  cf->eusec     = 0;
  cf->snap      = wtap_snapshot_length(cf->wth);
  cf->progbar_quantum = 0;
  cf->progbar_nextstep = 0;
  firstsec = 0, firstusec = 0;
  prevsec = 0, prevusec = 0;
 
  return (0);

fail:
  /* HAVE_ERR should already be set here. We do it anyway (doesn't hurt) */
  HAVE_ERR = TRUE;
  
  snprintf(err_msg, sizeof err_msg, file_open_error_message(err, FALSE), fname);
  strcpy(ERR_MSG, err_msg);
  fprintf(stderr, "hethereal: %s\n", err_msg);
  return (err);
}
Index: print.c
===================================================================
RCS file: /cvsroot/ethereal/print.c,v
retrieving revision 1.29
diff -u -r1.29 print.c
--- print.c	2000/04/13 20:39:18	1.29
+++ print.c	2001/03/06 14:52:41
@@ -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,11 +209,80 @@
 	}
 }
 
+/* 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, register const u_char *cp,
 		register u_int length, char_enc encoding)
 {
+	/* HTML/JavaScript: PR_FMT_HTML must be defined in hethereal.c */
 	if (format == PR_FMT_PS)
 		print_hex_data_ps(fh, cp, length, encoding);
+	else if (format == PR_FMT_HTML)
+		print_hex_data_html(fh, cp, length, encoding);
 	else
 		print_hex_data_text(fh, cp, length, encoding);
 }
@@ -223,6 +324,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

Attachment: hethereal_addons.tgz
Description: GNU Zip compressed data