Assorted changes from Ronnie Sahlberg:
[obnox/wireshark/wip.git] / reassemble.h
1 /* reassemble.h
2  * Declarations of outines for {fragment,segment} reassembly
3  *
4  * $Id: reassemble.h,v 1.2 2001/11/24 09:36:40 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  * 
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 /* make sure that all flags that are set in a fragment entry is also set for
26  * the flags field of fd_head !!!
27  */
28
29 /* only in fd_head: packet is defragmented */
30 #define FD_DEFRAGMENTED         0x0001
31
32 /* there are overlapping fragments */
33 #define FD_OVERLAP              0x0002
34
35 /* overlapping fragments contain different data */ 
36 #define FD_OVERLAPCONFLICT      0x0004  
37
38 /* more than one fragment which indicates end-of data */
39 #define FD_MULTIPLETAILS        0x0008
40
41 /* fragment contains data past the end of the datagram */
42 #define FD_TOOLONGFRAGMENT      0x0010
43
44 typedef struct _fragment_data {
45         struct _fragment_data *next;
46         guint32 frame;
47         guint32 offset;
48         guint32 len;
49         guint32 datalen; /*Only valid in first item of list */
50         guint32 flags;
51         unsigned char *data;
52 } fragment_data;
53
54 /*
55  * Initialize a fragment table.
56  */
57 void fragment_table_init(GHashTable **fragment_table);
58
59 /*
60  * Free up all space allocated for fragment keys and data.
61  */
62 void reassemble_init(void);
63
64 /*
65  * This function adds a new fragment to the fragment hash table.
66  * If this is the first fragment seen for this datagram, a new entry
67  * is created in the hash table, otherwise this fragment is just added
68  * to the linked list of fragments for this packet.
69  * The list of fragments for a specific datagram is kept sorted for
70  * easier handling.
71  *
72  * Returns a pointer to the head of the fragment data list if we have all the
73  * fragments, NULL otherwise.
74  */
75 fragment_data *fragment_add(tvbuff_t *tvb, int offset, packet_info *pinfo,
76     guint32 id, GHashTable *fragment_table, guint32 frag_offset,
77     guint32 frag_data_len, gboolean more_frags);
78
79 /* to specify how much to reassemble, for fragmentation where last fragment can not be 
80  * identified by flags or such.
81  */
82 void
83 fragment_set_tot_len(packet_info *pinfo, guint32 id, GHashTable *fragment_table, 
84                      guint32 tot_len);
85
86 /* This function is used to check if there is partial or completed reassembly state
87  * matching this packet. I.e. Are there reassembly going on or not for this packet?
88  */
89 fragment_data *
90 fragment_get(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
91
92 /* This will free up all resources and delete reassembly state for this PDU.
93  * Except if the PDU is completely reassembled, then it would NOT deallocate the
94  * buffer holding the reassembled data but instead return the pointer to that
95  * buffer.
96  * 
97  * So, if you call fragment_delete and it returns non-NULL, YOU are responsible to 
98  * g_free() that buffer.
99  */
100 unsigned char *
101 fragment_delete(packet_info *pinfo, guint32 id, GHashTable *fragment_table);
102
103