From 10c23c3cd254a80c095eea6a4afebcf5cfe6c353 Mon Sep 17 00:00:00 2001 From: Gilbert Ramirez Date: Thu, 21 Jan 1999 05:03:56 +0000 Subject: [PATCH] I changed the wtap_open_offline() function so that it takes only the filename as the parameter. So far all the filetypes that wiretap can read can be inferred from the first few bytes of the file, so we never have to give wiretap a hint as to the file type. svn path=/trunk/; revision=173 --- file.c | 4 +-- wiretap/file.c | 98 ++++++++++++++------------------------------------ wiretap/wtap.h | 4 +-- 3 files changed, 31 insertions(+), 75 deletions(-) diff --git a/file.c b/file.c index 36bc5b7b80..f240333ce7 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.18 1999/01/07 16:15:34 gram Exp $ + * $Id: file.c,v 1.19 1999/01/21 05:03:55 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -140,7 +140,7 @@ open_cap_file(char *fname, capture_file *cf) { cf->pfh = pcap_open_offline(fname, err_str); if (cf->pfh == NULL) { #else - cf->wth = wtap_open_offline(fname, WTAP_FILE_UNKNOWN); + cf->wth = wtap_open_offline(fname); if (cf->wth == NULL) { #endif diff --git a/wiretap/file.c b/wiretap/file.c index 28f1adf076..041a5c7a46 100644 --- a/wiretap/file.c +++ b/wiretap/file.c @@ -1,6 +1,6 @@ /* file.c * - * $Id: file.c,v 1.6 1999/01/17 09:33:15 guy Exp $ + * $Id: file.c,v 1.7 1999/01/21 05:03:56 gram Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -38,7 +38,7 @@ * WTAP_FILE_UNKNOWN */ /* Opens a file and prepares a wtap struct */ -wtap* wtap_open_offline(char *filename, int filetype) +wtap* wtap_open_offline(char *filename) { wtap *wth; @@ -49,79 +49,35 @@ wtap* wtap_open_offline(char *filename, int filetype) return NULL; } - /* If the filetype is unknown, try all my file types */ - if (filetype == WTAP_FILE_UNKNOWN) { - /* WTAP_FILE_PCAP */ - if ((wth->file_type = libpcap_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - /* WTAP_FILE_NGSNIFFER */ - if ((wth->file_type = ngsniffer_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - /* WTAP_FILE_LANALYZER */ - if ((wth->file_type = lanalyzer_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - /* WTAP_FILE_SNOOP */ - if ((wth->file_type = snoop_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - /* WTAP_FILE_IPTRACE */ - if ((wth->file_type = iptrace_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - /* WTAP_FILE_NETMON */ - if ((wth->file_type = netmon_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } + /* Try all my file types */ - printf("failed\n"); - /* WTAP_FILE_UNKNOWN */ - goto failure; + /* WTAP_FILE_PCAP */ + if ((wth->file_type = libpcap_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; + } + /* WTAP_FILE_NGSNIFFER */ + if ((wth->file_type = ngsniffer_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; + } + /* WTAP_FILE_LANALYZER */ + if ((wth->file_type = lanalyzer_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; + } + /* WTAP_FILE_SNOOP */ + if ((wth->file_type = snoop_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; + } + /* WTAP_FILE_IPTRACE */ + if ((wth->file_type = iptrace_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; + } + /* WTAP_FILE_NETMON */ + if ((wth->file_type = netmon_open(wth)) != WTAP_FILE_UNKNOWN) { + goto success; } - /* If the user tells us what the file is supposed to be, check it */ - switch (filetype) { - case WTAP_FILE_PCAP: - if ((wth->file_type = libpcap_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - case WTAP_FILE_NGSNIFFER: - if ((wth->file_type = ngsniffer_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - case WTAP_FILE_LANALYZER: - if ((wth->file_type = lanalyzer_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - case WTAP_FILE_SNOOP: - if ((wth->file_type = snoop_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - case WTAP_FILE_IPTRACE: - if ((wth->file_type = iptrace_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - case WTAP_FILE_NETMON: - if ((wth->file_type = netmon_open(wth)) != WTAP_FILE_UNKNOWN) { - goto success; - } - break; - default: - goto failure; - } - /* If we made it through the switch() statement w/o going to "success", - * then we failed. */ - goto failure; - -failure: +/* failure: */ fclose(wth->fh); free(wth); wth = NULL; diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 45afc04ac9..9a0613268e 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1,6 +1,6 @@ /* wtap.h * - * $Id: wtap.h,v 1.11 1999/01/17 09:33:15 guy Exp $ + * $Id: wtap.h,v 1.12 1999/01/21 05:03:56 gram Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -110,7 +110,7 @@ typedef struct wtap { } wtap; -wtap* wtap_open_offline(char *filename, int filetype); +wtap* wtap_open_offline(char *filename); void wtap_loop(wtap *wth, int, wtap_handler, u_char*); FILE* wtap_file(wtap *wth);