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
This commit is contained in:
Gilbert Ramirez 1999-01-21 05:03:56 +00:00
parent 43a8b4b5a5
commit 10c23c3cd2
3 changed files with 31 additions and 75 deletions

4
file.c
View File

@ -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 <gerald@zing.org>
@ -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

View File

@ -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 <gram@verdict.uthscsa.edu>
@ -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;

View File

@ -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 <gram@verdict.uthscsa.edu>
@ -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);