file_read() can return -1; don't just blindly add it to a previous
[obnox/wireshark/wip.git] / wiretap / network_instruments.h
1 /*
2  * $Id$
3  */
4
5 /***************************************************************************
6                           network_instruments.h  -  description
7                              -------------------
8     begin                : Wed Oct 29 2003
9     copyright            : (C) 2003 by root
10     email                : scotte[AT}netinst.com
11  ***************************************************************************/
12
13 /***************************************************************************
14  *                                                                         *
15  *   This program is free software; you can redistribute it and/or modify  *
16  *   it under the terms of the GNU General Public License as published by  *
17  *   the Free Software Foundation; either version 2 of the License, or     *
18  *   (at your option) any later version.                                   *
19  *                                                                         *
20  ***************************************************************************/
21
22 #ifndef __NETWORK_INSTRUMENTS_H__
23 #define __NETWORK_INSTRUMENTS_H__
24
25 int network_instruments_open(wtap *wth, int *err, gchar **err_info);
26 int network_instruments_dump_can_write_encap(int encap);
27 gboolean network_instruments_dump_open(wtap_dumper *wdh, int *err);
28
29 /*
30  * In v15 the high_byte was added to allow a larger offset This was done by 
31  * reducing the size of observer_version by 1 byte.  Since version strings are
32  * only 30 characters the high_byte will always be 0 in previous versions.
33  */
34 typedef struct capture_file_header
35 {
36         char    observer_version[31];
37         guint8  offset_to_first_packet_high_byte; /* allows to extend the offset to the first packet to 256*0x10000 = 16 MB */
38         guint16 offset_to_first_packet;
39         char    probe_instance;
40         guint8  number_of_information_elements; /* number of TLVs in the header */
41 } capture_file_header;
42
43 #define CAPTURE_FILE_HEADER_FROM_LE_IN_PLACE(_capture_file_header) \
44     _capture_file_header.offset_to_first_packet = GUINT16_FROM_LE((_capture_file_header).offset_to_first_packet)
45
46 #define CAPTURE_FILE_HEADER_TO_LE_IN_PLACE(_capture_file_header) \
47     _capture_file_header.offset_to_first_packet = GUINT16_TO_LE((_capture_file_header).offset_to_first_packet)
48
49 typedef struct tlv_header
50 {
51         guint16 type;
52         guint16 length;         /* includes the length of the TLV header */
53 } tlv_header;
54
55 #define TLV_HEADER_FROM_LE_IN_PLACE(_tlv_header) \
56     (_tlv_header).type   = GUINT16_FROM_LE((_tlv_header).type); \
57     (_tlv_header).length = GUINT16_FROM_LE((_tlv_header).length)
58
59 #define TLV_HEADER_TO_LE_IN_PLACE(_tlv_header) \
60     (_tlv_header).type   = GUINT16_TO_LE((_tlv_header).type); \
61     (_tlv_header).length = GUINT16_TO_LE((_tlv_header).length)
62
63 typedef struct tlv_time_info {
64         guint16 type;
65         guint16 length;
66         guint32 time_format;
67 } tlv_time_info;
68
69 #define TLV_TIME_INFO_FROM_LE_IN_PLACE(_tlv_time_info) \
70     (_tlv_time_info).type   = GUINT16_FROM_LE((_tlv_time_info).type); \
71     (_tlv_time_info).length = GUINT16_FROM_LE((_tlv_time_info).length); \
72         (_tlv_time_info).time_format = GUINT32_FROM_LE((_tlv_time_info).time_format)
73
74 #define TLV_TIME_INFO_TO_LE_IN_PLACE(_tlv_time_info) \
75     (_tlv_time_info).type   = GUINT16_TO_LE((_tlv_time_info).type); \
76     (_tlv_time_info).length = GUINT16_TO_LE((_tlv_time_info).length); \
77         (_tlv_time_info).time_format = GUINT32_FROM_LE((_tlv_time_info).time_format)
78
79 /*
80  * TLV type values.
81  */
82 #define INFORMATION_TYPE_ALIAS_LIST             0x01
83 #define INFORMATION_TYPE_COMMENT                0x02    /* ASCII text */
84 #define INFORMATION_TYPE_TIME_INFO              0x04
85
86 /*
87  * TVL TIME_INFO values.
88  */
89 #define TIME_INFO_LOCAL 0
90 #define TIME_INFO_GMT   1
91
92 typedef struct packet_entry_header
93 {
94         guint32 packet_magic;
95         guint32 network_speed;
96         guint16 captured_size;
97         guint16 network_size;
98         guint16 offset_to_frame;
99         guint16 offset_to_next_packet;
100         guint8 network_type;
101         guint8 flags;
102         guint8 number_of_information_elements;  /* number of TLVs in the header */
103         guint8 packet_type;
104         guint16 errors;
105         guint16 reserved;
106         guint64 packet_number;
107         guint64 original_packet_number;
108         guint64 nano_seconds_since_2000;
109 } packet_entry_header;
110
111 #define PACKET_ENTRY_HEADER_FROM_LE_IN_PLACE(_packet_entry_header) \
112     (_packet_entry_header).packet_magic            = GUINT32_FROM_LE((_packet_entry_header).packet_magic); \
113     (_packet_entry_header).network_speed           = GUINT32_FROM_LE((_packet_entry_header).network_speed); \
114     (_packet_entry_header).captured_size           = GUINT16_FROM_LE((_packet_entry_header).captured_size); \
115     (_packet_entry_header).network_size            = GUINT16_FROM_LE((_packet_entry_header).network_size); \
116     (_packet_entry_header).offset_to_frame         = GUINT16_FROM_LE((_packet_entry_header).offset_to_frame); \
117     (_packet_entry_header).offset_to_next_packet   = GUINT16_FROM_LE((_packet_entry_header).offset_to_next_packet); \
118     (_packet_entry_header).errors                  = GUINT16_FROM_LE((_packet_entry_header).errors); \
119     (_packet_entry_header).reserved                = GUINT16_FROM_LE((_packet_entry_header).reserved); \
120     (_packet_entry_header).packet_number           = GUINT64_FROM_LE((_packet_entry_header).packet_number); \
121     (_packet_entry_header).original_packet_number  = GUINT64_FROM_LE((_packet_entry_header).original_packet_number); \
122     (_packet_entry_header).nano_seconds_since_2000 = GUINT64_FROM_LE((_packet_entry_header).nano_seconds_since_2000)
123
124 #define PACKET_ENTRY_HEADER_TO_LE_IN_PLACE(_packet_entry_header) \
125     (_packet_entry_header).packet_magic            = GUINT32_TO_LE((_packet_entry_header).packet_magic); \
126     (_packet_entry_header).network_speed           = GUINT32_TO_LE((_packet_entry_header).network_speed); \
127     (_packet_entry_header).captured_size           = GUINT16_TO_LE((_packet_entry_header).captured_size); \
128     (_packet_entry_header).network_size            = GUINT16_TO_LE((_packet_entry_header).network_size); \
129     (_packet_entry_header).offset_to_frame         = GUINT16_TO_LE((_packet_entry_header).offset_to_frame); \
130     (_packet_entry_header).offset_to_next_packet   = GUINT16_TO_LE((_packet_entry_header).offset_to_next_packet); \
131     (_packet_entry_header).errors                  = GUINT16_TO_LE((_packet_entry_header).errors); \
132     (_packet_entry_header).reserved                = GUINT16_TO_LE((_packet_entry_header).reserved); \
133     (_packet_entry_header).packet_number           = GUINT64_TO_LE((_packet_entry_header).packet_number); \
134     (_packet_entry_header).original_packet_number  = GUINT64_TO_LE((_packet_entry_header).original_packet_number); \
135     (_packet_entry_header).nano_seconds_since_2000 = GUINT64_TO_LE((_packet_entry_header).nano_seconds_since_2000)
136
137 /*
138  * Network type values.
139  */
140 #define OBSERVER_UNDEFINED       0xFF
141 #define OBSERVER_ETHERNET        0x00
142 #define OBSERVER_TOKENRING       0x01
143 #define OBSERVER_FIBRE_CHANNEL   0x08
144
145 /*
146  * Packet type values.
147  */
148 #define PACKET_TYPE_DATA_PACKET                 0
149 #define PACKET_TYPE_EXPERT_INFORMATION_PACKET   1
150
151 /*
152  * The Observer document indicates that the types of expert information
153  * packets are:
154  *
155  *      Network Load (markers used by Expert Time Interval and What If
156  *      analysis modes)
157  *
158  *      Start/Stop Packet Capture marker frames (with time stamps when
159  *      captures start and stop)
160  *
161  *      Wireless Channel Change (markers showing what channel was being
162  *      currently listened to)
163  *
164  * That information appears to be contained in TLVs.
165  */
166
167 /*
168  * TLV type values.
169  */
170 #define INFORMATION_TYPE_NETWORK_LOAD           0x0100
171 #define INFORMATION_TYPE_CAPTURE_START_STOP     0x0104
172
173 /*
174  * Might some of these be broadcast and multicast packet counts?
175  */
176 typedef struct tlv_network_load
177 {
178         guint32 utilization;    /* network utilization, in .1% units */
179         guint32 unknown1;
180         guint32 unknown2;
181         guint32 packets_per_second;
182         guint32 unknown3;
183         guint32 bytes_per_second;
184         guint32 unknown4;
185 } tlv_network_load;
186
187 typedef struct tlv_capture_start_stop
188 {
189         guint32 start_stop;
190 } tlv_capture_start_stop;
191
192 #define START_STOP_TYPE_STOP    0
193 #define START_STOP_TYPE_START   1
194
195 #endif
196