This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

What does #define __TFS_H__ do in tfs.h?

0

Hi all, due to some problems I've had with compiling a plugin I stumbled upon __TFS_H__ in tfs.h while tracing the error. What does it do and what happens if I do something like this TFS(&tfs_set_notset) somewhere else in the code?

Thanks. Mike

asked 14 Apr '16, 01:05

mikethebo's gravatar image

mikethebo
21447
accept rate: 0%

edited 14 Apr '16, 01:06


One Answer:

1

What does it do

It makes sure that, if a Wireshark source file includes both tfs.h and some other header file that includes tfs.h, the header file's contents are processed only once, so you don't, for example, get warnings or errors from redefinitions or redeclaration.

This is a VERY common technique in C header files; you'll probably find at least one header file for the OS or compiler you're using that has a "header guard" of that type.

what happens if I do something like this TFS(&tfs_set_notset) somewhere else in the code?

It works, if you do that in the right place (a definition of a named packet field) and if you've included either tfs.h or some header file that includes tfs.h before you use TFS(&tfs_set_notset).

answered 14 Apr '16, 01:54

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%

Although as noted elsewhere, on Windows, there appear to be issues including pre-defined tfs values from libwireshark in a plugin.

(14 Apr '16, 02:12) grahamb ♦
1

From proto.h

/** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
#define TFS(x)  (const struct true_false_string*)(x)

The declarations in tfs.h are just handy, pre-canned true_false strings, which, on Windows, can't unfortunately be use in plugins. You can just define those strings yourself (as in tfs.c) if you need any of them.

(14 Apr '16, 03:11) grahamb ♦