tshark: handle option -c when ENABLE_PCAP=OFF
[metze/wireshark/wip.git] / doc / README.capture
1 This document is an attempt, to bring some light to the things done, when
2 packet capturing is performed. There might be things missing, and others
3 maybe wrong :-( The following will concentrate a bit on the Windows
4 port of Wireshark.
5
6
7 XXX: when ongoing file reorganization will be completed, the following
8 two lists maybe won't be needed any longer!
9
10 libpcap related source files:
11 -----------------------------
12 capture-pcap-util.c
13 capture-pcap-util.h
14 capture-pcap-util-int.h
15 capture-pcap-util-unix.c
16 capture-wpcap.c
17 capture-wpcap.h
18 capture_wpcap_packet.c
19 capture_wpcap_packet.h
20
21 Capture related source files:
22 -----------------------------
23 capture.c
24 capture.h
25 capture_loop.c
26 capture_loop.h
27 capture_opts.c
28 capture_sync.c
29 capture_ui_utils.c
30 capture_ui_utils.h
31
32
33 Capture driver
34 --------------
35 Wireshark doesn't have direct access to the capture hardware. Instead of this,
36 it uses the Libpcap/Winpcap library to capture data from network cards.
37
38 On Win32, in capture-wpcap.c the function ws_module_open("wpcap.dll") is called
39 to load the wpcap.dll. This dll includes all functions needed for
40 packet capturing.
41
42
43
44 Capture File
45 ------------
46 There are some kinds of targets to put the capture data into:
47
48 -temporary file
49 -user specified "single" capture file
50 -user specified "ringbuffer" capture file
51
52 Which kind of file is used depends on the user settings. In principle there
53 is no difference in handling these files, so if not otherwise notified,
54 it will be called the capture file.
55
56 The capture file is stored, using the wiretap library.
57
58
59 Overview
60 --------
61 Capturing is done using a two task model: the currently running (parent)
62 process will spawn a child process to do the real capture work, namely
63 controlling libpcap. This two task model is used because it's necessary
64 to split the capturing process (which should avoid packet drop) from the parent
65 process which might need significant time to display the data.
66
67 When a capture is started, the parent builds a "command line" and creates a
68 new child process with it. A pipe from the child to the parent is created
69 which is used to transfer control messages.
70
71 The child will init libpcap and send the parent a "new capture file is used"
72 control message through the pipe.
73
74 The child cyclically takes the packet data from libpcap and saves it to disk.
75 From time to time it will send the parent a "new packets" control message.
76
77 If the parent process receives this "new packets" message and the option
78 "Update list of packets in real time" is used, it will read the packet data
79 from the file, dissect and display it.
80
81
82 If the user wants to stop the capture, this can be done in two ways: by
83 menu/toolbar of the parent process or the Stop button of the child processes
84 dialog box (which obviously cannot be used it this dialog is hidden).
85
86 The Stop button will stop the capture itself, close the control pipe and then
87 closes itself. The parent will detect this and stop its part of the capture.
88
89 If the menu/toolbar is used, the parent will send a break signal to the child
90 which will lead to the same sequence as described above.
91
92 Win32 only: as the windows implementation of signals simply doesn't work,
93 another pipe from the parent to the child is used to send a "close capture"
94 message instead of a signal.
95
96
97 Start capture
98 -------------
99 A capture is started, by specifying to start the capture at the command line,
100 trigger the OK button in the "Capture Options" dialog box and some more. The
101 capture start is actually done by calling the capture_start() function in
102 capture.c.
103
104
105 Capture child (Loop)
106 --------------------
107 The capture child will open the target capture file, prepare pcap things,
108 init stop conditions, init the capture statistic dialog (if not hidden) and
109 start a loop which is running until the flag ld.go is FALSE.
110
111 Inside this loop,
112
113 -Qt main things are updated
114 -pcap_dispatch(capture_pcap_cb) is called
115 -the capture stop conditions are checked (ld.go is set to FALSE to finish)
116 -update the capture statistic dialog (if not hidden)
117
118 While this loop is running, the pcap_dispatch() will call capture_pcap_cb()
119 for every packet captured. Inside this, the packet data is converted into
120 wtap (wiretap) format and saved to file. Beside saving, it is trying to
121 do some basic dissecting (for the statistic window), by calling the
122 appropriate capture_xxx function.
123
124 When the user triggered a capture stop or one of the capture stop conditions
125 matched, the ld.go flag is set to FALSE, and the loop will stop shortly after.
126
127
128 Capture parent
129 --------------
130 In the capture parent the cap_pipe_input_cb() function is called "cyclically"
131 (unix:waiting for pipe, win32:timer,1000ms) to read data from the pipe and show
132 it on the main screen. While the capture is in progress, no other capture file
133 can be opened.
134
135
136 Updating
137 --------
138 The actual packet capturing inside the libpcap is done using its own task.
139 Catching and processing the packet data from the libpcap is done using the
140 pcap_dispatch() function.