01: package tools.sniffer;
02:
03: import java.io.*;
04: import java.util.*;
05: import tools.tracesviewer.*;
06:
07: /**
08: * Code to convert Ethereal frames to the XML format that the trace viewer
09: * application likes.
10: * @author Tim Bardzil <bardzil@colorado.edu>.
11: *
12: * Acknowledgement:
13: * This code was contributed by Tim Bardzil <bardzil@colorado.edu>.
14: * This code was completed as part of a class project in TLEN 5843
15: * Singaling Protocols, taught by Professor Douglas C. Sicker, Ph.D. at
16: * the University of Colorado, Boulder.
17: * Minor modifications to the code were made by M. Ranganathan .
18: *
19: */
20: public class SniffFileParser {
21: SniffSessionList sniffSessionList;
22:
23: public SniffFileParser(String messageFile) {
24: String buffer = new String();
25: ArrayList sniffMsgList;
26: sniffSessionList = new SniffSessionList();
27:
28: try {
29: BufferedReader in = new BufferedReader(new FileReader(
30: messageFile));
31: buffer = in.readLine();
32: while (buffer != null) { //read until EOF
33: sniffMsgList = new ArrayList();
34: while (buffer != null && buffer.length() > 0) { //read one frame
35: sniffMsgList.add(buffer.trim());
36: buffer = in.readLine();
37: }
38: SniffMessage sniffMsg = new SniffMessage(sniffMsgList);
39: sniffSessionList.add(sniffMsg);
40: buffer = in.readLine();
41: }
42: } catch (Exception e) {
43: e.printStackTrace();
44: }
45: }
46:
47: public SniffSessionList getSniffSessionList() {
48: return sniffSessionList;
49: }
50:
51: /**
52: * The main entry point.
53: *
54: *@param args is the argument file. args[0] is the Ethereral packet
55: * sniffer output to convert to the format that the trace viewer
56: * likes.
57: */
58: public static void main(String args[]) {
59: String fileName = args[0];
60: SniffMessageList.fileName = fileName;
61: if (args[0] == null) {
62: System.out.println("Please specify sniffer file");
63: System.out.println("Bailing Out!");
64: System.exit(0);
65: }
66: SniffFileParser sfp = new SniffFileParser(args[0]);
67: SniffSessionList sniffSessions = sfp.getSniffSessionList();
68: //String[] sessionNames = sniffSessions.getCallIds();
69: LogFileParser parser = new LogFileParser();
70: Hashtable traces = parser.parseLogsFromString(sniffSessions
71: .toXML());
72: new TracesViewer(traces, fileName, "Ethereal Sniffer Trace",
73: null).show();
74:
75: }
76: }
|