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
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/tvbuff.h>
33 struct _fragment_items;
35 /* A stream represents the concept of an arbitrary stream of data,
36 divided up into frames for transmission, where the frames have
37 little or no correspondence to the PDUs of the protocol being
38 streamed, and those PDUs are just delineated by a magic number.
40 For example, we stream H.223 over IAX2. IAX2 has no concept of
41 H.223 PDUs and just divides the H.223 stream into 160-byte
42 frames. H.223 PDUs are delineated by two-byte magic numbers (which
43 may, of course, straddle an IAX2 frame boundary).
45 Essentially we act as a wrapper to reassemble.h, by making up
46 PDU ids and keeping some additional data on fragments to allow the
47 PDUs to be defragmented again.
51 /* A stream_t represents a stream. There might be one or two streams
52 in a circuit, depending on whether that circuit is mono- or bi-directional.
54 typedef struct stream stream_t;
56 /* Fragments in a PDU are represented using a stream_pdu_fragment_t,
57 and placed in a linked-list with other fragments in the PDU.
59 (They're also placed in a hash so we can find them again later)
61 typedef struct stream_pdu_fragment stream_pdu_fragment_t;
68 /* initialise a new stream. Call this when you first identify a distinct
69 * stream. The circit pointer is just used as a key to look up the stream. */
70 extern stream_t *stream_new_circ ( const struct circuit *circuit, int p2p_dir );
71 extern stream_t *stream_new_conv ( const struct conversation *conv, int p2p_dir );
73 /* retrieve a previously-created stream.
75 * Returns null if no matching stream was found.
77 extern stream_t *find_stream_circ ( const struct circuit *circuit, int p2p_dir );
78 extern stream_t *find_stream_conv ( const struct conversation *conv, int p2p_dir );
82 /* see if we've seen this fragment before.
84 The framenum and offset are just hash keys, so can be any values unique
85 to this frame, but the idea is that you use the number of the frame being
86 disassembled, and the byte-offset within that frame.
88 extern stream_pdu_fragment_t *stream_find_frag( stream_t *stream, guint32 framenum, guint32 offset );
90 /* add a new fragment to the fragment tables for the stream. The framenum and
91 * offset are keys allowing future access with stream_find_frag(), tvb is the
92 * fragment to be added, and pinfo is the information for the frame containing
93 * this fragment. more_frags should be set if this is the final fragment in the
96 * * the fragment must be later in the stream than any previous fragment
97 * (ie, framenum.offset must be greater than those passed on the previous
100 * This essentially means that you can only add fragments on the first pass
101 * through the stream.
103 extern stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guint32 offset,
104 tvbuff_t *tvb, packet_info *pinfo, gboolean more_frags );
106 /* Get the length of a fragment previously found by stream_find_frag().
108 extern guint32 stream_get_frag_length( const stream_pdu_fragment_t *frag);
110 /* Get a handle on the top of the chain of fragment_datas underlying this PDU
111 * frag can be any fragment within a PDU, and it will always return the head of
114 * Returns NULL until the last fragment is added.
116 extern struct _fragment_data *stream_get_frag_data( const stream_pdu_fragment_t *frag);
119 * Process reassembled data; if this is the last fragment, put the fragment
120 * information into the protocol tree, and construct a tvbuff with the
121 * reassembled data, otherwise just put a "reassembled in" item into the
124 extern tvbuff_t *stream_process_reassembled(
125 tvbuff_t *tvb, int offset, packet_info *pinfo,
126 const char *name, const stream_pdu_fragment_t *frag,
127 const struct _fragment_items *fit,
128 gboolean *update_col_infop, proto_tree *tree);
130 /* Get the PDU number. PDUs are numbered from zero within a stream.
131 * frag can be any fragment within a PDU.
133 extern guint32 stream_get_pdu_no( const stream_pdu_fragment_t *frag);
135 /* initialise the stream routines */
136 void stream_init( void );
137 void stream_cleanup( void );
139 #endif /* STREAM_H */