Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
stream.h
1 /* stream.h
2  *
3  * Definititions for handling circuit-switched protocols
4  * which are handled as streams, and don't have lengths
5  * and IDs such as are required for reassemble.h
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 STREAM_H
15 #define STREAM_H
16 
17 #include <epan/tvbuff.h>
18 #include <epan/reassemble.h>
19 #include "ws_symbol_export.h"
20 
21 struct _fragment_items;
22 
23 /* A stream represents the concept of an arbitrary stream of data,
24  divided up into frames for transmission, where the frames have
25  little or no correspondence to the PDUs of the protocol being
26  streamed, and those PDUs are just delineated by a magic number.
27 
28  For example, we stream H.223 over IAX2. IAX2 has no concept of
29  H.223 PDUs and just divides the H.223 stream into 160-byte
30  frames. H.223 PDUs are delineated by two-byte magic numbers (which
31  may, of course, straddle an IAX2 frame boundary).
32 
33  Essentially we act as a wrapper to reassemble.h, by making up
34  PDU ids and keeping some additional data on fragments to allow the
35  PDUs to be defragmented again.
36 */
37 
38 
39 /* A stream_t represents a stream. There might be one or two streams
40  in a circuit, depending on whether that circuit is mono- or bi-directional.
41 */
42 typedef struct stream stream_t;
43 
44 /* Fragments in a PDU are represented using a stream_pdu_fragment_t,
45  and placed in a linked-list with other fragments in the PDU.
46 
47  (They're also placed in a hash so we can find them again later)
48 */
50 
51 
52 
53 struct circuit;
54 struct conversation;
55 
56 /* initialise a new stream. Call this when you first identify a distinct
57  * stream. The circit pointer is just used as a key to look up the stream. */
58 WS_DLL_PUBLIC stream_t *stream_new_circ ( const struct circuit *circuit, int p2p_dir );
59 extern stream_t *stream_new_conv ( const struct conversation *conv, int p2p_dir );
60 
61 /* retrieve a previously-created stream.
62  *
63  * Returns null if no matching stream was found.
64  */
65 WS_DLL_PUBLIC stream_t *find_stream_circ ( const struct circuit *circuit, int p2p_dir );
66 extern stream_t *find_stream_conv ( const struct conversation *conv, int p2p_dir );
67 
68 
69 
70 /* see if we've seen this fragment before.
71 
72  The framenum and offset are just hash keys, so can be any values unique
73  to this frame, but the idea is that you use the number of the frame being
74  disassembled, and the byte-offset within that frame.
75 */
76 WS_DLL_PUBLIC stream_pdu_fragment_t *stream_find_frag( stream_t *stream, guint32 framenum, guint32 offset );
77 
78 /* add a new fragment to the fragment tables for the stream. The framenum and
79  * offset are keys allowing future access with stream_find_frag(), tvb is the
80  * fragment to be added, and pinfo is the information for the frame containing
81  * this fragment. more_frags should be set if this is the final fragment in the
82  * PDU.
83  *
84  * * the fragment must be later in the stream than any previous fragment
85  * (ie, framenum.offset must be greater than those passed on the previous
86  * call)
87  *
88  * This essentially means that you can only add fragments on the first pass
89  * through the stream.
90  */
91 WS_DLL_PUBLIC stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guint32 offset,
92  tvbuff_t *tvb, packet_info *pinfo, gboolean more_frags );
93 
94 /* Get the length of a fragment previously found by stream_find_frag().
95  */
96 extern guint32 stream_get_frag_length( const stream_pdu_fragment_t *frag);
97 
98 /* Get a handle on the top of the chain of fragment_datas underlying this PDU
99  * frag can be any fragment within a PDU, and it will always return the head of
100  * the chain
101  *
102  * Returns NULL until the last fragment is added.
103  */
104 extern fragment_head *stream_get_frag_data( const stream_pdu_fragment_t *frag);
105 
106 /*
107  * Process reassembled data; if this is the last fragment, put the fragment
108  * information into the protocol tree, and construct a tvbuff with the
109  * reassembled data, otherwise just put a "reassembled in" item into the
110  * protocol tree.
111  */
112 WS_DLL_PUBLIC tvbuff_t *stream_process_reassembled(
113  tvbuff_t *tvb, int offset, packet_info *pinfo,
114  const char *name, const stream_pdu_fragment_t *frag,
115  const struct _fragment_items *fit,
116  gboolean *update_col_infop, proto_tree *tree);
117 
118 /* Get the PDU number. PDUs are numbered from zero within a stream.
119  * frag can be any fragment within a PDU.
120  */
121 extern guint32 stream_get_pdu_no( const stream_pdu_fragment_t *frag);
122 
123 /* initialise the stream routines */
124 void stream_init( void );
125 void stream_cleanup( void );
126 
127 #endif /* STREAM_H */
Definition: reassemble.h:421
Definition: packet_info.h:44
Definition: tvbuff-int.h:35
Definition: conversation.h:89
Definition: reassemble.h:52
Definition: stream.c:40
Definition: stream.c:33
Definition: proto.h:759