Created a new protocol tree implementation and a new display filter
[obnox/wireshark/wip.git] / wiretap / file.c
1 /* file.c
2  *
3  * $Id: file.c,v 1.10 1999/07/07 22:52:54 gram Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include "wtap.h"
28 #include "buffer.h"
29 #include "lanalyzer.h"
30 #include "ngsniffer.h"
31 #include "libpcap.h"
32 #include "snoop.h"
33 #include "iptrace.h"
34 #include "netmon.h"
35 #include "netxray.h"
36
37 /* The open_file_* routines should return the WTAP_FILE_* type
38  * that they are checking for if the file is successfully recognized
39  * as such. If the file is not of that type, the routine should return
40  * WTAP_FILE_UNKNOWN */
41
42 /* Opens a file and prepares a wtap struct */
43 wtap* wtap_open_offline(char *filename)
44 {
45         wtap    *wth;
46
47         wth = (wtap*)malloc(sizeof(wtap));
48
49         /* Open the file */
50         if (!(wth->fh = fopen(filename, "rb"))) {
51                 return NULL;
52         }
53
54         /* initialization */
55         wth->file_encap = WTAP_ENCAP_NONE;
56
57         /* Try all file types */
58
59         /* WTAP_FILE_PCAP */
60         if ((wth->file_type = libpcap_open(wth)) != WTAP_FILE_UNKNOWN) {
61                 goto success;
62         }
63         /* WTAP_FILE_NGSNIFFER */
64         if ((wth->file_type = ngsniffer_open(wth)) != WTAP_FILE_UNKNOWN) {
65                 goto success;
66         }
67         /* WTAP_FILE_LANALYZER */
68         if ((wth->file_type = lanalyzer_open(wth)) != WTAP_FILE_UNKNOWN) {
69                 goto success;
70         }
71         /* WTAP_FILE_SNOOP */
72         if ((wth->file_type = snoop_open(wth)) != WTAP_FILE_UNKNOWN) {
73                 goto success;
74         }
75         /* WTAP_FILE_IPTRACE */
76         if ((wth->file_type = iptrace_open(wth)) != WTAP_FILE_UNKNOWN) {
77                 goto success;
78         }
79         /* WTAP_FILE_NETMON */
80         if ((wth->file_type = netmon_open(wth)) != WTAP_FILE_UNKNOWN) {
81                 goto success;
82         }
83         /* WTAP_FILE_NETXRAY */
84         if ((wth->file_type = netxray_open(wth)) != WTAP_FILE_UNKNOWN) {
85                 goto success;
86         }
87
88
89 /* failure: */
90         fclose(wth->fh);
91         free(wth);
92         wth = NULL;
93         return wth;
94
95 success:
96         wth->frame_buffer = g_malloc(sizeof(struct Buffer));
97         buffer_init(wth->frame_buffer, 1500);
98         return wth;
99 }