Squelch a compiler warning.
[metze/wireshark/wip.git] / wiretap / README.developer
1 This is a very quick and very dirty guide to adding support for new
2 capture file formats.  If you see any errors or have any improvements,
3 submit patches - free software is a community effort....
4
5 To add the ability to read a new capture file format, you have to:
6
7         add a new WTAP_FILE_ value for the file type to
8         "wiretap/wtap.h";
9
10         write an "open" routine that can read the beginning of the
11         capture file and figure out if it's in that format or not,
12         either by looking at a magic number at the beginning or by using
13         some form of heuristic to determine if it's a file of that type
14         (if the file format has a magic number, that's what should be
15         used);
16
17         write a "read" routine that can read a packet from the file and
18         supply the packet length, captured data length, time stamp, and
19         packet pseudo-header (if any) and data, and have the "open"
20         routine set the "subtype_read" member of the "wtap" structure
21         supplied to it to point to that routine;
22
23         write a "seek and read" routine that can seek to a specified
24         location in the file for a packet and supply the packet
25         pseudo-header (if any) and data, and have the "open" routine set
26         the "subtype_seek_read" member of the "wtap" structure to point
27         to that routine;
28
29         write a "close" routine, if necessary (if, for example, the
30         "open" routine allocates any memory), and set the
31         "subtype_close" member of the "wtap" structure to point to it,
32         otherwise leave it set to NULL;
33
34         add a pointer to the "open" routine to the "open_routines_base[]"
35         table in "wiretap/file_access.c" - if it uses a magic number, put 
36         it in the first section of that list, and, if it uses a heuristic, 
37         put it in the second section, preferably putting the heuristic
38         routines for binary files before the heuristic routines for text
39         files;
40
41         add an entry for that file type in the "dump_open_table_base[]" in
42         "wiretap/file_access.c", giving a descriptive name, a short name 
43         that's convenient to type on a command line (no blanks or capital
44         letters, please), common file extensions to open and save, a flag 
45         if it can be compressed with gzip (currently unused) and pointers 
46         to the "can_write_encap" and "dump_open" routines if writing that 
47         file is supported (see below), otherwise just null pointers.
48
49 Wiretap applications typically first perform sequential reads through
50 the capture file and may later do "seek and read" for individual frames. 
51 The "read" routine should set the variable data_offset to the byte
52 offset within the capture file from which the "seek and read" routine
53 will read.  If the capture records consist of:
54
55         capture record header
56         pseudo-header (e.g., for ATM)
57         frame data
58
59 then data_offset should point to the pseudo-header.  The first
60 sequential read pass will process and store the capture record header
61 data, but it will not store the pseudo-header.  Note that the 
62 seek_and_read routine should work with the "random_fh" file handle
63 of the passed in wtap struct, instead of the "fh" file habndle used
64 in the normal read routine.
65
66 To add the ability to write a new capture file format, you have to:
67
68         add a "can_write_encap" routine that returns an indication of
69         whether a given packet encapsulation format is supported by the
70         new capture file format;
71
72         add a "dump_open" routine that starts writing a file (writing
73         headers, allocating data structures, etc.);
74
75         add a "dump" routine to write a packet to a file, and have the
76         "dump_open" routine set the "subtype_write" member of the
77         "wtap_dumper" structure passed to it to point to it;
78
79         add a "dump_close" routine, if necessary (if, for example, the
80         "dump_open" routine allocates any memory, or if some of the file
81         header can be written only after all the packets have been
82         written), and have the "dump_open" routine set the
83         "subtype_close" member of the "wtap_dumper" structure to point
84         to it;
85
86         put pointers to the "can_write_encap" and "dump_open" routines
87         in the "dump_open_table_base[]" entry for that file type.
88
89 In the wiretap directory, add your source file to CMakelists.txt and
90 your source and header file to Makefile.am.