Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

9.5. How to tap protocols

Adding a Tap interface to a protocol allows it to do some useful things. In particular you can produce protocol statistics from the tap interface.

A tap is basically a way of allowing other items to see whats happening as a protocol is dissected. A tap is registered with the main program, and then called on each dissection. Some arbitrary protocol specific data is provided with the routine that can be used.

To create a tap, you first need to register a tap. A tap is registered with an integer handle, and registered with the routine register_tap. This takes a string name with which to find it again.

Example 9.19. Initialising a tap

#include <epan/tap.h>

static int foo_tap = -1;

struct FooTap {
	gint packet_type;
	gint priority;
	...
};
...
	foo_tap = register_tap("foo");
   

Whilst you can program a tap without protocol specific data, it is generally not very useful. Therefore it's a good idea to declare a structure that can be passed through the tap. This needs to be a static structure as it will be used after the dissection routine has returned. Its generally best to pick out some generic parts of the protocol you are dissecting into the tap data. A packet type, a priority, a status code maybe. The structure really needs to be included in a header file so that it can be included by other components that want to listen in to the tap.

Once you have these defined, it's simply a case of populating the protocol specific structure and then calling tap_queue_packet probably as the last part of the dissector.

Example 9.20. Calling a protocol tap


	static struct FooTap pinfo;

	pinfo.packet_type = tvb_get_guint8(tvb, 0);
	pinfo.priority = tvb_get_ntohs(tvb, 8);
	   ...
	tap_queue_packet(foo_tap, pinfo, &pinfo);

   

This now enables those interested parties to listen in on the details of this protocol conversation.


 
 
  Published under the terms fo the GNU General Public License Design by Interspire