Wireshark  4.3.0
The Wireshark network protocol analyzer
packet-giop.h
1 /* packet-giop.h
2  * Declaration of routines for GIOP/IIOP (CDR) dissection
3  * Copyright 2000, Frank Singleton <frank.singleton@ericsson.com>
4  *
5  * Based on CORBAv2.4.2 Chapter 15 GIOP Description.
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  */
13 
14 #ifndef PACKET_GIOP_H
15 #define PACKET_GIOP_H
16 
17 #include "ws_symbol_export.h"
18 
19 /*
20  * Useful visible data/structs
21  */
22 
23 #define GIOP_HEADER_SIZE 12
24 #define GIOP_MAGIC_NUMBER 0x47494F50 /* "GIOP" */
25 
26 typedef struct Version {
27  guint8 major;
28  guint8 minor;
29 } Version;
30 
31 
32 /*
33  * Useful data collected from message header. Note, this
34  * struct encapsulates useful data from GIOP header, as well
35  * as request_id and reply_status for use by sub dissectors.
36  */
37 
38 typedef struct MessageHeader {
39 
40  /* Common Data */
41 
42  guint8 magic[4];
43  Version GIOP_version;
44  guint8 flags; /* byte_order in 1.0 */
45  guint8 message_type;
46  guint32 message_size;
47 
48  /* MSG dependent data */
49 
50  guint32 req_id; /* request id in MSG */
51  guint32 rep_status; /* reply status in MSG if available */
52  gchar *exception_id; /* exception string if a USER EXCEPTION occurs */
53 
55 
56 typedef enum MsgType {
57  Request = 0,
58  Reply,
59  CancelRequest,
60  LocateRequest,
61  LocateReply,
62  CloseConnection,
63  MessageError,
64  Fragment /* GIOP 1.1 only */
65 
66 } MsgType;
67 
68 
69 
70 /*
71  * Reply Status
72  *
73  */
74 
75 typedef enum ReplyStatusType {
76  NO_EXCEPTION = 0,
77  USER_EXCEPTION,
78  SYSTEM_EXCEPTION,
79  LOCATION_FORWARD,
80  LOCATION_FORWARD_PERM, /* new for GIOP 1.2 */
81  NEEDS_ADDRESSING_MODE /* new for GIOP 1.2 */
82 } ReplyStatusType;
83 
84 /*
85  * Prototype for sub dissector function calls.
86  */
87 
88 typedef gboolean (giop_sub_dissector_t)(tvbuff_t *, packet_info *, proto_tree *, int *,
89  MessageHeader *, const gchar * , gchar *);
90 
91 /*
92  * Generic Subdissector handle, wraps user info.
93  */
94 
95 typedef struct giop_sub_handle {
96  giop_sub_dissector_t *sub_fn; /* ptr to sub dissector function */
97  const gchar *sub_name; /* subdissector string name */
98  protocol_t *sub_proto; /* protocol_t for subprotocol */
100 
101 /* Main GIOP entry point */
102 
103 extern gboolean dissect_giop(tvbuff_t *, packet_info *, proto_tree *); /* new interface */
104 
105 /*
106  * GIOP Users register interest via this function.
107  * This is for heuristic dissection
108  */
109 
110 WS_DLL_PUBLIC void register_giop_user(giop_sub_dissector_t *sub, const gchar *name,
111  int sub_proto);
112 
113 /*
114  * GIOP Users remove interest via this function.
115  * This is for heuristic dissection
116  */
117 
118 extern void delete_giop_user(giop_sub_dissector_t *sub, gchar *name);
119 
120 
121 /*
122  * GIOP Users register their module and interface names via this function.
123  * This is for explicit dissection.
124  */
125 
126 WS_DLL_PUBLIC void register_giop_user_module(giop_sub_dissector_t *sub, const gchar *name,
127  const gchar *module, int sub_proto);
128 
129 /*
130  * GIOP Users remove their module and interface names via this function.
131  * This is for explicit dissection.
132  */
133 
134 extern void delete_giop_user_module(giop_sub_dissector_t *sub, gchar *name,
135  gchar *module);
136 
137 
138 /*
139  * General CDR accessors start here. They are listed in alphabetical
140  * order. They may however, belong to 1 of 3 distinct CDR data types.
141  *
142  * - Primitive
143  * - OMG IDL Constructed Types
144  * - Pseudo Object Types
145  *
146  *
147  * Altough some of these look redundant, I have separated them
148  * out for all CDR types, to assist in auto generation of
149  * IDL dissectors later, see idl2wrs -- FS
150  *
151  */
152 
153 
154 /*
155  * Gets data of type any. This is encoded as a TypeCode
156  * followed by the encoded value.
157  *
158  * Data is added to tree directly if present.
159  */
160 
161 WS_DLL_PUBLIC void get_CDR_any(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item,
162  gint *offset, gboolean stream_is_big_endian,
163  int boundary, MessageHeader * header);
164 
165 
166 /* Copy a 1 octet sequence from the tvbuff
167  * which represents a boolean value, and convert
168  * it to a boolean value.
169  * Offset is then incremented by 1, to indicate the 1 octet which
170  * has been processed.
171  */
172 
173 WS_DLL_PUBLIC gboolean get_CDR_boolean(tvbuff_t *tvb, int *offset);
174 
175 
176 /* Copy a 1 octet sequence from the tvbuff
177  * which represents a char, and convert
178  * it to an char value.
179  * offset is then incremented by 1, to indicate the 1 octet which
180  * has been processed.
181  */
182 
183 WS_DLL_PUBLIC guint8 get_CDR_char(tvbuff_t *tvb, int *offset);
184 
185 
186 
187 /*
188  * Floating Point Data Type double IEEE 754-1985
189  *
190  * Copy an 8 octet sequence from the tvbuff
191  * which represents a double value, and convert
192  * it to a double value, taking into account byte order.
193  * offset is first incremented so that it falls on a proper alignment
194  * boundary for double values.
195  * offset is then incremented by 8, to indicate the 8 octets which
196  * have been processed.
197  */
198 
199 WS_DLL_PUBLIC gdouble get_CDR_double(tvbuff_t *tvb, int *offset,
200  gboolean stream_is_big_endian, int boundary);
201 
202 
203 /* Copy a 4 octet sequence from the tvbuff
204  * which represents an enum value, and convert
205  * it to an enum value, taking into account byte order.
206  * offset is first incremented so that it falls on a proper alignment
207  * boundary for an enum (4)
208  * offset is then incremented by 4, to indicate the 4 octets which
209  * have been processed.
210  *
211  * Enum values are encoded as unsigned long.
212  */
213 
214 WS_DLL_PUBLIC guint32 get_CDR_enum(tvbuff_t *tvb, int *offset,
215  gboolean stream_is_big_endian, int boundary);
216 
217 
218 
219 /*
220  * Copy an octet sequence from the tvbuff
221  * which represents a Fixed point decimal type, and create a string representing
222  * a Fixed point decimal type. There are no alignment restrictions.
223  * Size and scale of fixed decimal type is determined by IDL.
224  *
225  * digits - IDL specified number of "digits" for this fixed type
226  * scale - IDL specified "scale" for this fixed type
227  *
228  *
229  * eg: typedef fixed <5,2> fixed_t;
230  * could represent numbers like 123.45, 789.12,
231  *
232  *
233  * As the fixed type could be any size, I will not try to fit it into our
234  * simple types like gdouble or glong etc. I will just create a string buffer holding
235  * a representation (after scale is applied), and with a decimal point or zero padding
236  * inserted at the right place if necessary. The string is null terminated
237  *
238  * so string may look like
239  *
240  *
241  * "+1.234" or "-3456.78" or "1234567309475760377365465897891" or "-2789000000" etc
242  *
243  * According to spec, digits <= 31
244  * and scale is positive (except for constants eg: 1000 has digit=1 and implied scale = -3)
245  * or <4,0> ?
246  *
247  */
248 
249 WS_DLL_PUBLIC void get_CDR_fixed(tvbuff_t *tvb, packet_info *pinfo, proto_item *item,
250  gchar **seq, gint *offset, guint32 digits, gint32 scale);
251 
252 
253 /*
254  * Floating Point Data Type float IEEE 754-1985
255  *
256  * Copy a 4 octet sequence from the tvbuff
257  * which represents a float value, and convert
258  * it to a float value, taking into account byte order.
259  * offset is first incremented so that it falls on a proper alignment
260  * boundary for float values.
261  * offset is then incremented by 4, to indicate the 4 octets which
262  * have been processed.
263  */
264 
265 WS_DLL_PUBLIC gfloat get_CDR_float(tvbuff_t *tvb, int *offset,
266  gboolean stream_is_big_endian, int boundary);
267 
268 
269 /*
270  * Decode an Interface type, and display it on the tree.
271  */
272 
273 WS_DLL_PUBLIC void get_CDR_interface(tvbuff_t *tvb, packet_info *pinfo,
274  proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
275 
276 
277 /* Copy a 4 octet sequence from the tvbuff
278  * which represents a signed long value, and convert
279  * it to an signed long vaule, taking into account byte order.
280  * offset is first incremented so that it falls on a proper alignment
281  * boundary for long values.
282  * offset is then incremented by 4, to indicate the 4 octets which
283  * have been processed.
284  */
285 
286 WS_DLL_PUBLIC gint32 get_CDR_long(tvbuff_t *tvb, int *offset,
287  gboolean stream_is_big_endian, int boundary);
288 
289 
290 
291 /* Copy a 16 octet sequence from the tvbuff
292  * which represents a long double value, and convert
293  * it to a long double value, taking into account byte order.
294  * offset is first incremented so that it falls on a proper alignment
295  * boundary for long double values.
296  * offset is then incremented by 16, to indicate the 16 octets which
297  * have been processed.
298  */
299 
300 #ifdef G_HAVE_GLONG_DOUBLE
301 
302 WS_DLL_PUBLIC glong_double get_CDR_long_double(tvbuff_t *tvb, int *offset,
303  gboolean stream_is_big_endian, int boundary);
304 #else
305 
306 /* FIX -- Cast long double to gdouble until I figure this out -- FS*/
307 
308 WS_DLL_PUBLIC gdouble get_CDR_long_double(tvbuff_t *tvb, int *offset,
309  gboolean stream_is_big_endian, int boundary);
310 
311 #endif
312 
313 
314 /* Copy an 8 octet sequence from the tvbuff
315  * which represents a signed long long value, and convert
316  * it to a signed long long value, taking into account byte order.
317  * offset is first incremented so that it falls on a proper alignment
318  * boundary for long long values.
319  * offset is then incremented by 8, to indicate the 8 octets which
320  * have been processed.
321  */
322 
323 WS_DLL_PUBLIC gint64 get_CDR_long_long(tvbuff_t *tvb, int *offset,
324  gboolean stream_is_big_endian, int boundary);
325 
326 /*
327  * Decode an Object type, and display it on the tree.
328  */
329 
330 WS_DLL_PUBLIC void get_CDR_object(tvbuff_t *tvb, packet_info *pinfo,
331  proto_tree *tree, int *offset, gboolean stream_is_big_endian, int boundary);
332 
333 
334 /* Copy a 1 octet sequence from the tvbuff
335  * which represents a octet, and convert
336  * it to an octet value.
337  * offset is then incremented by 1, to indicate the 1 octet which
338  * has been processed.
339  */
340 
341 WS_DLL_PUBLIC guint8 get_CDR_octet(tvbuff_t *tvb, int *offset);
342 
343 
344 /* Copy a sequence of octets from the tvbuff.
345  * This function also increments offset by len.
346  */
347 
348 WS_DLL_PUBLIC void get_CDR_octet_seq(wmem_allocator_t *scope, tvbuff_t *tvb, const guint8 **seq, int *offset, guint32 len);
349 
350 /* Copy a 2 octet sequence from the tvbuff
351  * which represents a signed short value, and convert
352  * it to a signed short value, taking into account byte order.
353  * offset is first incremented so that it falls on a proper alignment
354  * boundary for short values.
355  * offset is then incremented by 2, to indicate the 2 octets which
356  * have been processed.
357  */
358 
359 WS_DLL_PUBLIC gint16 get_CDR_short(tvbuff_t *tvb, int *offset,
360  gboolean stream_is_big_endian, int boundary);
361 
362 
363 WS_DLL_PUBLIC void giop_add_CDR_string(proto_tree *tree, tvbuff_t *tvb, int *offset,
364  gboolean stream_is_big_endian, int boundary,
365  int hf);
366 
367 /* Copy an octet sequence from the tvbuff
368  * which represents a string, and convert
369  * it to an string value, taking into account byte order.
370  * offset is first incremented so that it falls on a proper alignment
371  * boundary for string values. (begins with an unsigned long LI)
372  *
373  * String sequence is copied to a buffer "seq".
374  * Memory is allocated in packet pool and will be
375  * automatically freed once the packet dissection is finished.
376  * offset is then incremented , to indicate the octets which
377  * have been processed.
378  *
379  * returns number of octets in the sequence
380  *
381  * Note: This function only supports single byte encoding at the
382  * moment until I get a handle on multibyte encoding etc.
383  *
384  */
385 
386 WS_DLL_PUBLIC guint32 get_CDR_string(tvbuff_t *tvb, const gchar **seq, int *offset,
387  gboolean stream_is_big_endian, int boundary);
388 
389 
390 /* Process a sequence of octets that represent the
391  * Pseudo Object Type "TypeCode". Typecodes are used for example,
392  * by "Any values".
393  * This function also increments offset to the correct position.
394  *
395  * It will parse the TypeCode and output data to the "tree" provided
396  * by the user
397  *
398  * It returns a guint32 representing a TCKind value.
399  */
400 
401 WS_DLL_PUBLIC guint32 get_CDR_typeCode(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, gint *offset,
402  gboolean stream_is_big_endian, int boundary, MessageHeader * header );
403 
404 
405 /* Copy a 4 octet sequence from the tvbuff
406  * which represents an unsigned long value, and convert
407  * it to an unsigned long value, taking into account byte order.
408  * offset is first incremented so that it falls on a proper alignment
409  * boundary for unsigned long values.
410  * offset is then incremented by 4, to indicate the 4 octets which
411  * have been processed.
412  */
413 
414 WS_DLL_PUBLIC guint32 get_CDR_ulong(tvbuff_t *tvb, int *offset,
415  gboolean stream_is_big_endian, int boundary);
416 
417 
418 /* Copy an 8 octet sequence from the tvbuff
419  * which represents an unsigned long long value, and convert
420  * it to an unsigned long long value, taking into account byte order.
421  * offset is first incremented so that it falls on a proper alignment
422  * boundary for unsigned long long values.
423  * offset is then incremented by 8, to indicate the 8 octets which
424  * have been processed.
425  */
426 
427 WS_DLL_PUBLIC guint64 get_CDR_ulong_long(tvbuff_t *tvb, int *offset,
428  gboolean stream_is_big_endian, int boundary);
429 
430 /* Copy a 2 octet sequence from the tvbuff
431  * which represents an unsigned short value, and convert
432  * it to an unsigned short value, taking into account byte order.
433  * offset is first incremented so that it falls on a proper alignment
434  * boundary for unsigned short values.
435  * offset is then incremented by 2, to indicate the 2 octets which
436  * have been processed.
437  */
438 
439 WS_DLL_PUBLIC guint16 get_CDR_ushort(tvbuff_t *tvb, int *offset,
440  gboolean stream_is_big_endian, int boundary);
441 
442 
443 /* Copy a wchar from the tvbuff.
444  * This function also increments offset according to
445  * the wchar size.
446  *
447  * For GIOP 1.1 read 2 octets and return size -2. The
448  * negation means there is no size element in the packet
449  * and therefore no size to add to the tree.
450  *
451  * For GIOP 1.2 read size of wchar and the size
452  * octets. size is returned as a gint8.
453  *
454  * For both GIOP versions the wchar is returned
455  * as a printable string.
456  *
457  */
458 
459 /* NOTE: This is very primitive in that it just reads
460  * the wchar as a series of octets and returns them
461  * to the user. No translation is attempted based on
462  * byte orientation, nor on code set. I.e it only
463  * really reads past the wchar and increments the offset
464  * by the length of the octet sequence.
465  */
466 
467 /* The "decoding" is done according to CORBA chapter 15.
468  * Wchar is not supported for GIOP 1.0.
469  */
470 
471 WS_DLL_PUBLIC gint get_CDR_wchar(wmem_allocator_t *scope, tvbuff_t *tvb,
472  const gchar **seq, int *offset, MessageHeader * header);
473 
474 
475 /* Copy a wstring from the tvbuff.
476  * This function also increments offset, according to
477  * wstring length. length is returned as guint32
478  */
479 
480 /* NOTE: This is very primitive in that it just reads
481  * the wstring as a series of octets and returns them
482  * to the user. No translation is attempted based on
483  * byte orientation, nor on code set. I.e it only
484  * really reads past the wstring and increments the offset
485  * by the length of the octet sequence.
486  */
487 
488 /* The "decoding" is done according to CORBA chapter 15.
489  * Wstring is not supported for GIOP 1.0.
490  */
491 
492 WS_DLL_PUBLIC guint32 get_CDR_wstring(wmem_allocator_t *scope, tvbuff_t *tvb,
493  const gchar **seq, int *offset, gboolean stream_is_big_endian, int boundary,
494  MessageHeader * header);
495 
496 
497 
498 /*
499  *
500  * End of get_CDR_xxx accessors.
501  *
502  */
503 
504 
505 
506 /* Determine the byte order from the GIOP MessageHeader */
507 
508 WS_DLL_PUBLIC gboolean is_big_endian (MessageHeader * header);
509 
510 /*
511  * get_encap_info() for any encapsulation (eg:sequences)
512  * we come across. updates the new boundary and endianess
513  * and *offset, and returns the sequence length.
514  */
515 
516 WS_DLL_PUBLIC guint32 get_CDR_encap_info(tvbuff_t *tvb, proto_tree *tree, gint *offset,
517  gboolean old_stream_is_big_endian, guint32 old_boundary,
518  gboolean *new_stream_is_big_endian_ptr, guint32 *new_boundary_ptr );
519 
520 /* Take in an array of guint8 and create a new ephemeral string.
521  * Replace non-printable characters with periods.
522  *
523  * The array may contain \0's so don't use strdup
524  * The string is \0 terminated, and thus longer than
525  * the initial sequence.
526  */
527 
528 WS_DLL_PUBLIC gchar * make_printable_string (wmem_allocator_t *scope, const guint8 *in, guint32 len);
529 
530 /*
531  * Enums for TCkind
532  */
533 
534 enum TCKind {
535  tk_null = 0,
536  tk_void,
537  tk_short,
538  tk_long,
539  tk_ushort,
540  tk_ulong,
541  tk_float,
542  tk_double,
543  tk_boolean,
544  tk_char,
545  tk_octet,
546  tk_any,
547  tk_TypeCode,
548  tk_Principal,
549  tk_objref,
550  tk_struct,
551  tk_union,
552  tk_enum,
553  tk_string,
554  tk_sequence,
555  tk_array,
556  tk_alias,
557  tk_except,
558  tk_longlong,
559  tk_ulonglong,
560  tk_longdouble,
561  tk_wchar,
562  tk_wstring,
563  tk_fixed,
564  tk_value,
565  tk_value_box,
566  tk_native,
567  tk_abstract_interface
568 
569  /* - none - 0xffffffff TODO */
570 };
571 
572 #define tk_none 0xffffffff
573 
574 typedef enum TCKind TCKind_t;
575 
576 
577 /*
578  * ServiceId's for ServiceContextList
579  *
580  * Chapter 13 Corba 2.4.2
581  */
582 
583 #define IOP_ServiceId_TransactionService 0
584 #define IOP_ServiceId_CodeSets 1
585 #define IOP_ServiceId_ChainBypassCheck 2
586 #define IOP_ServiceId_ChainBypassInfo 3
587 #define IOP_ServiceId_LogicalThreadId 4
588 #define IOP_ServiceId_BI_DIR_IIOP 5
589 #define IOP_ServiceId_SendingContextRunTime 6
590 #define IOP_ServiceId_INVOCATION_POLICIES 7
591 #define IOP_ServiceId_FORWARD_IDENTITY 8
592 #define IOP_ServiceId_UnknownExceptionInfo 9
593 
594 /* Used for GIOP statistics */
595 typedef struct _giop_info_value_t {
596  guint32 framenum;
597  address *server_addr;
598  const gchar *client_host;
599  const gchar *service_host;
600  const gchar *giop_op;
601  const gchar *giop_resp;
602  time_t time_ticks;
603  guint time_ms;
604  gboolean first_pass;
606 
607 
608 #define GIOP_TAP_NAME "giop"
609 
610 #endif /* PACKET_GIOP_H */
Definition: address.h:55
Definition: packet-giop.h:595
Definition: packet_info.h:44
Definition: proto.h:897
Definition: proto.c:361
Definition: wmem_allocator.h:27
Definition: packet-giop.h:38
Definition: packet-giop.h:26
Definition: packet-giop.h:95
Definition: tvbuff-int.h:35