Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] What is the use of pointer "cap_file_" in QtShark

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Wed, 22 May 2013 11:50:00 -0700
On May 22, 2013, at 10:21 AM, Richard Turner <turner@xxxxxxxxx> wrote:

> In Wireshark/ui/qt/main_window.h there is a private member variable defined as:
> 
> capture_file *cap_file_;
> 
> I think it's a pointer to the global variable "cfile"

Currently, yes.

We make no claim that Wireshark will, forever, have only one main window and only one capture file open, so it should not be treated as if it is, inherently, just a pointer to cfile.

> (defined in tshark.c).

Yes, it's defined there, but tshark.c, as the name suggests, is not linked into Wireshark, it's linked into TShark; the cfile in QtShark is defined in ui/qt/main.cpp (and in GTKShark is defined in ui/gtk/main.c).

> Is it true that we keep this pointer only to verify the validity of cfile (we set cap_file_ to NULL when the capture file is closed)?

No, we keep it around to make the code cleaner (and a tiny bit easier to make into something that behaves like a Real OS X Application, in which one process handles all open files and captures; "tiny bit" because that's about .001% of the work involved - the *big* work is to get rid of, for example, global variables in libwireshark and plugin dissectors).

"Global variables considered harmful".