From Irene Ruengeler: Bugfixes and support of chunk statistics per end point.
[obnox/wireshark/wip.git] / gtk / sctp_graph_dlg.c
1 /* 
2  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * $Id$
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 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29
30 #include <gtk/gtk.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include <string.h>
35 #include "globals.h"
36 #include "epan/filesystem.h"
37 #include "../color.h"
38 #include "tap_menu.h"
39 #include "dlg_utils.h"
40 #include "ui_util.h"
41 #include "main.h"
42 #include "compat_macros.h"
43 #include "simple_dialog.h"
44 #include "sctp_stat.h"
45
46 #define DEFAULT_PIXELS_PER_TICK 2
47 #define MAX_PIXELS_PER_TICK 4
48 #define AUTO_MAX_YSCALE 0
49 #define MAX_TICK_VALUES 5
50 #define DEFAULT_TICK_VALUE 3
51 #define MAX_YSCALE 22
52 #define MAX_COUNT_TYPES 3
53
54 #define COUNT_TYPE_FRAMES   0
55 #define COUNT_TYPE_BYTES    1
56 #define COUNT_TYPE_ADVANCED 2
57
58 #define LEFT_BORDER 50
59 #define RIGHT_BORDER 10
60 #define TOP_BORDER 10
61 #define BOTTOM_BORDER 50
62
63 #define SUB_32(a, b)    a-b
64 #define MINI(a,b) (a<b)?a:b
65 #define MAXI(a,b) (a>b)?a:b
66
67 struct chunk_header {
68         guint8  type;
69         guint8  flags;
70         guint16 length;
71 };
72
73 struct data_chunk_header {
74         guint8  type;
75         guint8  flags;
76         guint16 length;
77         guint32 tsn;
78         guint16 sid;
79         guint16 ssn;
80         guint32 ppi;
81 };
82
83 struct init_chunk_header {
84         guint8  type;
85         guint8  flags;
86         guint16 length;
87         guint32 initiate_tag;
88         guint32 a_rwnd;
89         guint16 mos;
90         guint16 mis;
91         guint32 initial_tsn;
92 };
93
94 struct sack_chunk_header {
95         guint8  type;
96         guint8  flags;
97         guint16 length;
98         guint32 cum_tsn_ack;
99         guint32 a_rwnd;
100         guint16 nr_of_gaps;
101         guint16 nr_of_dups;
102         guint8  *tsns;
103 };
104
105 struct gaps {
106         guint16 start;
107         guint16 end;
108 };
109
110
111 static void sctp_graph_set_title(struct sctp_udata *u_data);
112 static void create_draw_area(GtkWidget *box, struct sctp_udata *u_data);
113
114
115 static void draw_sack_graph(struct sctp_udata *u_data)
116 {
117         tsn_t   *sack;
118         GList *list=NULL, *tlist;
119         guint16 gap_start=0, gap_end=0, i, j, nr;
120         guint8 type;
121         guint32 tsnumber, max_tsn=0, min_tsn=0;
122         GdkColor red_color = {0, 65535, 0, 0};
123         GdkColor green_color = {0, 0, 65535, 0};
124         GdkGC *red_gc, *green_gc;
125         struct sack_chunk_header *sack_header;
126         struct gaps *gap;
127         guint32 max_num, diff;
128 #if GTK_MAJOR_VERSION < 2
129         GdkColormap *colormap;
130 #endif
131
132         red_gc = gdk_gc_new(u_data->io->draw_area->window);
133 #if GTK_MAJOR_VERSION < 2
134                 colormap = gtk_widget_get_colormap (u_data->io->draw_area);
135                 if (!gdk_color_alloc (colormap, &red_color)){
136                         g_warning ("Couldn't allocate color");
137                 }
138
139                 gdk_gc_set_foreground(red_gc, &red_color);
140 #else
141                 gdk_gc_set_rgb_fg_color(red_gc, &red_color);
142 #endif
143
144         green_gc = gdk_gc_new(u_data->io->draw_area->window);
145 #if GTK_MAJOR_VERSION < 2
146                 colormap = gtk_widget_get_colormap (u_data->io->draw_area);
147                 if (!gdk_color_alloc (colormap, &green_color)){
148                         g_warning ("Couldn't allocate color");
149                 }
150
151                 gdk_gc_set_foreground(green_gc, &green_color);
152 #else
153                 gdk_gc_set_rgb_fg_color(green_gc, &green_color);
154 #endif
155
156         if (u_data->dir==2)
157         {
158
159                 list = g_list_last(u_data->assoc->sack2);
160                 if (u_data->io->tmp==FALSE)
161                 {
162                         min_tsn=u_data->assoc->min_tsn2;
163                         max_tsn=u_data->assoc->max_tsn2;
164                 }
165                 else
166                 {
167                         min_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_min_tsn2;
168                         max_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_max_tsn2;
169                 }
170         }
171         else if (u_data->dir==1)
172         {
173                 list = g_list_last(u_data->assoc->sack1);
174                 if (u_data->io->tmp==FALSE)
175                 {
176                         min_tsn=u_data->assoc->min_tsn1;
177                         max_tsn=u_data->assoc->max_tsn1;
178                 }
179                 else
180                 {
181                         min_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_min_tsn1;
182                         max_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_max_tsn1;
183                 }
184         }
185
186         while (list)
187         {
188                 sack = (tsn_t*) (list->data);
189                 tlist = g_list_first(sack->tsns);
190                 while (tlist)
191                 {
192                         type = ((struct chunk_header *)tlist->data)->type;
193
194                         if (type == SCTP_SACK_CHUNK_ID)
195                         {
196                                 sack_header =(struct sack_chunk_header *)tlist->data;
197                                 nr=ntohs(sack_header->nr_of_gaps);
198                                 tsnumber = ntohl(sack_header->cum_tsn_ack);
199                                 if (nr>0)
200                                 {
201                                         gap = (struct gaps *)(sack_header->tsns+(4*(nr-1)));
202                                         gap_start=ntohs(gap->start);
203                                         gap_end = ntohs(gap->end);
204                                         max_num=gap_end+tsnumber;
205                                 }
206                                 else
207                                         max_num=tsnumber;
208
209                                 if (sack->secs>=u_data->io->x1_tmp_sec)
210                                 {
211                                         if (nr>0)
212                                         {
213                                                 for(i=0;i<nr; i++)
214                                                 {
215                                                         for (j=gap_start; j<=gap_end; j++)
216                                                         {
217                                                                 diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
218                                                                 gdk_draw_arc(u_data->io->pixmap,green_gc,TRUE,
219                                                                              (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff),
220                                                                              (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(j+tsnumber,min_tsn))*u_data->io->y_interval)),
221                                                                              3, 3,0, (64*360) );
222                                                         }
223                                                 }
224                                         }
225                                         if (tsnumber>=min_tsn)
226                                         {
227                                                 diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
228                                                 gdk_draw_arc(u_data->io->pixmap,red_gc,TRUE,
229                                                              (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff),
230                                                              (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(tsnumber,min_tsn))*u_data->io->y_interval)),
231                                                              3, 3,0, (64*360) );
232                                         }
233                                 }
234                         tlist = g_list_next(tlist);
235                         }
236                 }
237                 list = g_list_previous(list);
238         }
239 #if GTK_MAJOR_VERSION >= 2
240                 g_object_unref(G_OBJECT(red_gc));
241                 g_object_unref(G_OBJECT(green_gc));
242 #endif
243 }
244
245
246 static void draw_tsn_graph(struct sctp_udata *u_data)
247 {
248         tsn_t *tsn;
249         GList *list=NULL, *tlist;
250         guint8 type;
251         guint32 tsnumber=0, min_tsn=0, max_tsn=0;
252         guint32 min_secs=0, diff;
253
254         if (u_data->dir==1)
255         {
256                 list = g_list_last(u_data->assoc->tsn1);
257                 if (u_data->io->tmp==FALSE)
258                 {
259                         min_tsn=u_data->assoc->min_tsn1;
260                         max_tsn=u_data->assoc->max_tsn1;
261                 }
262                 else
263                 {
264                         min_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_min_tsn1;
265                         max_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_max_tsn1;
266                 }
267         }
268         else if (u_data->dir==2)
269         {
270                 list = g_list_last(u_data->assoc->tsn2);
271                 if (u_data->io->tmp==FALSE)
272                 {
273                         min_tsn=u_data->assoc->min_tsn2;
274                         max_tsn=u_data->assoc->max_tsn2;
275                 }
276                 else
277                 {
278                         min_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_min_tsn2;
279                         max_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_max_tsn2;
280                 }
281         }
282
283         while (list)
284         {
285                 tsn = (tsn_t*) (list->data);
286                 tlist = g_list_first(tsn->tsns);
287                 while (tlist)
288                 {
289                         type = ((struct chunk_header *)tlist->data)->type;
290                         if (type == SCTP_DATA_CHUNK_ID)
291                                 tsnumber = ntohl(((struct data_chunk_header *)tlist->data)->tsn);
292
293                         if (tsnumber>=min_tsn && tsnumber<=max_tsn && tsn->secs>=min_secs)
294                         {
295                                         diff=tsn->secs*1000000+tsn->usecs-u_data->io->min_x;
296                                         gdk_draw_arc(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,TRUE,
297                                                      (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff),
298                                                      (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-((SUB_32(tsnumber,min_tsn))*u_data->io->y_interval)),
299                                                      3, 3, 0, (64*360));
300                         }
301                         tlist = g_list_next(tlist);
302                 }
303                 list = g_list_previous(list);
304         }
305
306 }
307
308
309 static void sctp_graph_draw(struct sctp_udata *u_data)
310 {
311         int length, lwidth, j, b;
312         guint32 label_width, label_height, distance=5, i, e, sec, w, start, a;
313         char label_string[15];
314         gfloat dis;
315
316 #if GTK_MAJOR_VERSION < 2
317                 GdkFont *font;
318 #else
319                         PangoLayout  *layout;
320 #endif
321
322         if (u_data->io->x1_tmp_sec==0 && u_data->io->x1_tmp_usec==0)
323                 u_data->io->offset=0;
324         else
325                 u_data->io->offset=5;
326
327         u_data->io->min_x=u_data->io->x1_tmp_sec*1000000+u_data->io->x1_tmp_usec;
328         u_data->io->max_x=u_data->io->x2_tmp_sec*1000000+u_data->io->x2_tmp_usec;
329         u_data->io->tmp_width=u_data->io->max_x-u_data->io->min_x;
330
331         if (u_data->dir==1)
332         {
333                 if (u_data->io->tmp==FALSE)
334                 {
335                         if (u_data->assoc->tsn1!=NULL || u_data->assoc->sack1!=NULL)
336                                 u_data->io->max_y=u_data->io->tmp_max_tsn1 - u_data->io->tmp_min_tsn1;
337                         else
338                                 u_data->io->max_y= 0;
339                         u_data->io->min_y = 0;
340                 }
341                 else
342                 {
343                         u_data->io->max_y = u_data->io->tmp_max_tsn1;
344                         u_data->io->min_y = u_data->io->tmp_min_tsn1;
345                 }
346         }
347         else if (u_data->dir==2)
348         {
349                 if (u_data->io->tmp==FALSE)
350                 {
351                         if (u_data->assoc->tsn2!=NULL || u_data->assoc->sack2!=NULL)
352                                         u_data->io->max_y=u_data->io->tmp_max_tsn2 -u_data->io->tmp_min_tsn2;
353                         else
354                                 u_data->io->max_y= 0;
355                         u_data->io->min_y = 0;
356                 }
357                 else
358                 {
359                         u_data->io->max_y = u_data->io->tmp_max_tsn2;
360                         u_data->io->min_y = u_data->io->tmp_min_tsn2;
361                 }
362         }
363
364         gdk_draw_rectangle(u_data->io->pixmap,
365                            u_data->io->draw_area->style->white_gc,
366                            TRUE,
367                            0, 0,
368                            u_data->io->draw_area->allocation.width,
369                            u_data->io->draw_area->allocation.height);
370
371         distance=5;
372         /* x_axis */
373         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER+u_data->io->offset,u_data->io->pixmap_height-BOTTOM_BORDER,u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset, u_data->io->pixmap_height-BOTTOM_BORDER);
374         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset, u_data->io->pixmap_height-BOTTOM_BORDER, u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset-5, u_data->io->pixmap_height-BOTTOM_BORDER-5);
375         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset, u_data->io->pixmap_height-BOTTOM_BORDER, u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset-5, u_data->io->pixmap_height-BOTTOM_BORDER+5);
376         u_data->io->axis_width=u_data->io->pixmap_width-LEFT_BORDER-RIGHT_BORDER-u_data->io->offset;
377
378         u_data->io->x_interval = (float)((u_data->io->axis_width*1.0)/u_data->io->tmp_width);
379
380         e=0;
381         if (u_data->io->x_interval<1)
382         {
383                 dis=1/u_data->io->x_interval;
384                 while (dis >1)
385                 {
386                         dis/=10;
387                         e++;
388                 }
389                 distance=1;
390                         for (i=0; i<=e+1; i++)
391                         distance*=10;
392         }
393         else
394                 distance=5;
395
396 #if GTK_MAJOR_VERSION < 2
397                 font = u_data->io->draw_area->style->font;
398 #endif
399
400 #if GTK_MAJOR_VERSION < 2
401                 label_width=gdk_string_width(font, label_string);
402                 label_height=gdk_string_height(font, label_string);
403 #else
404                 g_snprintf(label_string, 15, "%d", 0);
405                 memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
406                 layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string);
407                 pango_layout_get_pixel_size(layout, &label_width, &label_height);
408
409 #endif
410
411         if (u_data->io->x1_tmp_usec==0)
412                 sec=u_data->io->x1_tmp_sec;
413         else
414                 sec=u_data->io->x1_tmp_sec+1;
415
416
417         if (u_data->io->offset!=0)
418         {
419                 g_snprintf(label_string, 15, "%u", u_data->io->x1_tmp_sec);
420                 
421 #if GTK_MAJOR_VERSION < 2
422                 lwidth=gdk_string_width(font, label_string);
423                                         gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
424                                         LEFT_BORDER-10,
425                                         u_data->io->pixmap_height-BOTTOM_BORDER+20,
426                                         label_string);
427 #else
428                 memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
429                 pango_layout_set_text(layout, label_string, -1);
430                 pango_layout_get_pixel_size(layout, &lwidth, NULL);
431
432                 gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
433                                 LEFT_BORDER-10,
434                                 u_data->io->pixmap_height-BOTTOM_BORDER+20,
435                                 layout);
436 #endif
437 }
438
439         w=(guint32)(500/(guint32)(distance*u_data->io->x_interval));
440         if (w==0)
441                 w=1;
442         if (w==4)
443         {
444                 w=5;
445                 a=distance/10;
446                 b=10+(((u_data->io->min_x/100000)-1)%5);
447         }
448         else
449         {
450                 a=distance/5;
451                 b=0;
452         }
453
454         if (a>1000000)
455                 start=u_data->io->min_x/1000000*1000000;
456         else
457         {
458                 start=u_data->io->min_x/100000;
459                 if (start%2!=0)
460                         start--;
461                 start*=100000;
462         }
463
464
465         for (i=start, j=b; i<=u_data->io->max_x; i+=a, j++)
466         {
467                 if (i>=u_data->io->min_x && i%1000000!=0)
468                 {
469                         length=5;
470                         g_snprintf(label_string, 15, "%d", i%1000000);
471                         if (j%w==0)
472                         {
473                                 length=10;
474
475                                 #if GTK_MAJOR_VERSION < 2
476                                         lwidth=gdk_string_width(font, label_string);
477                                         gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
478                                                 (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-lwidth/2),
479                                                 u_data->io->pixmap_height-BOTTOM_BORDER+10,
480                                                 label_string);
481                                 #else
482                                         memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
483                                         pango_layout_set_text(layout, label_string, -1);
484                                         pango_layout_get_pixel_size(layout, &lwidth, NULL);
485                                         gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
486                                                 (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-lwidth/2),
487                                                 u_data->io->pixmap_height-BOTTOM_BORDER+10,
488                                                 layout);
489                                 #endif
490                         }
491                         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
492                                 (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
493                                 u_data->io->pixmap_height-BOTTOM_BORDER,
494                                 (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
495                                 u_data->io->pixmap_height-BOTTOM_BORDER+length);
496                 }
497
498                 if (i%1000000==0)
499                 {
500                         sec=i/1000000;
501                         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
502                         (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
503                         u_data->io->pixmap_height-BOTTOM_BORDER,
504                         (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
505                         u_data->io->pixmap_height-BOTTOM_BORDER+10);
506
507                         g_snprintf(label_string, 15, "%d", sec);
508                         #if GTK_MAJOR_VERSION < 2
509                                 lwidth=gdk_string_width(font, label_string);
510                                 gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
511                                         (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
512                                         u_data->io->pixmap_height-BOTTOM_BORDER+20,
513                                         label_string);
514                         #else
515                                 memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
516                                 pango_layout_set_text(layout, label_string, -1);
517                                 pango_layout_get_pixel_size(layout, &lwidth, NULL);
518
519                                 gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
520                                 (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
521                                         u_data->io->pixmap_height-BOTTOM_BORDER+20,
522                                         layout);
523                         #endif
524                 }
525         }
526
527         strcpy(label_string, "sec");
528
529 #if GTK_MAJOR_VERSION < 2
530         lwidth=gdk_string_width(font, label_string);
531         gdk_draw_string(u_data->io->pixmap,
532                         font,
533                         u_data->io->draw_area->style->black_gc,
534                         u_data->io->pixmap_width-RIGHT_BORDER-10,
535                         u_data->io->pixmap_height-BOTTOM_BORDER+20,
536                         label_string);
537 #else
538         memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
539         pango_layout_set_text(layout, label_string, -1);
540         pango_layout_get_pixel_size(layout, &lwidth, NULL);
541         gdk_draw_layout(u_data->io->pixmap,
542                         u_data->io->draw_area->style->black_gc,
543                         u_data->io->pixmap_width-RIGHT_BORDER-10,
544                         u_data->io->pixmap_height-BOTTOM_BORDER+25,
545                         layout);
546 #endif
547
548         distance=5;
549
550         /* y-axis */
551         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc, LEFT_BORDER,TOP_BORDER-u_data->io->offset,LEFT_BORDER,u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset);
552         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,LEFT_BORDER,TOP_BORDER-u_data->io->offset, LEFT_BORDER-5, TOP_BORDER-u_data->io->offset+5);
553         gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,LEFT_BORDER,TOP_BORDER-u_data->io->offset, LEFT_BORDER+5, TOP_BORDER-u_data->io->offset+5);
554
555         u_data->io->y_interval = (float)(((u_data->io->pixmap_height-TOP_BORDER-BOTTOM_BORDER)*1.0)/(u_data->io->max_y-u_data->io->min_y));
556
557         e=0;
558         if (u_data->io->y_interval<1)
559         {
560                 dis=1/u_data->io->y_interval;
561                 while (dis >1)
562                 {
563                         dis/=10;
564                         e++;
565                 }
566                 distance=1;
567                 for (i=0; i<=e; i++)
568                         distance=distance*10;
569         }
570
571         if (u_data->io->max_y>0)
572         {
573                 for (i=u_data->io->min_y/distance*distance; i<=u_data->io->max_y; i+=distance/5)
574                 {
575                         if (i>=u_data->io->min_y)
576                         {
577                                 length=5;
578                                 g_snprintf(label_string, 15, "%d", i);
579                                 if (i%distance==0 || (distance<=5 && u_data->io->y_interval>10))
580                                 {
581                                         length=10;
582
583 #if GTK_MAJOR_VERSION < 2
584                                                 lwidth=gdk_string_width(font, label_string);
585                                                 gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
586                                                                 LEFT_BORDER-length-lwidth-5,
587                                                                 (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval-3),
588                                                                 label_string);
589 #else
590                                                 memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
591                                                 pango_layout_set_text(layout, label_string, -1);
592                                                 pango_layout_get_pixel_size(layout, &lwidth, NULL);
593                                                 gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
594                                                                 LEFT_BORDER-length-lwidth-5,
595                                                                 (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval-3),
596                                                                 layout);
597 #endif
598                                 }
599                                 gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,LEFT_BORDER-length,
600                                               (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval),
601                                               LEFT_BORDER,
602                                               (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval));
603                         }
604                 }
605         }
606         else if ((u_data->dir==1 && u_data->assoc->n_array_tsn1==0) || (u_data->dir==2 && u_data->assoc->n_array_tsn2==0))
607                 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No Data Chunks sent");
608 }
609
610
611 static void sctp_graph_redraw(struct sctp_udata *u_data)
612 {
613 sctp_graph_t *ios;
614
615         u_data->io->needs_redraw=TRUE;
616
617         sctp_graph_draw(u_data);
618         switch (u_data->io->graph_type)
619         {
620                 case 0:
621                         draw_sack_graph(u_data);
622                         draw_tsn_graph(u_data);
623                         break;
624                 case 1: 
625                         draw_tsn_graph(u_data);
626                         break;
627                 case 2:
628                         draw_sack_graph(u_data);
629                         break;
630         }
631         ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
632
633         if(!ios){
634                 exit(10);
635         }
636
637
638         gdk_draw_pixmap(u_data->io->draw_area->window,
639                         u_data->io->draw_area->style->fg_gc[GTK_WIDGET_STATE(u_data->io->draw_area)],
640                         ios->pixmap,
641                         0,0,
642                         0, 0,
643                         u_data->io->draw_area->allocation.width,
644                         u_data->io->draw_area->allocation.height);
645 }
646
647
648 static void on_sack_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
649 {
650
651         u_data = (struct sctp_udata *) u_data;
652         u_data->io->graph_type=2;
653         sctp_graph_redraw(u_data);
654 }
655
656 static void on_tsn_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
657 {
658
659         u_data->io->graph_type=1;
660         sctp_graph_redraw(u_data);
661 }
662
663 static void on_both_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
664 {
665
666         u_data->io->graph_type=0;
667         sctp_graph_redraw(u_data);
668 }
669
670 static void
671 sctp_graph_close_cb(GtkWidget* widget _U_, gpointer u_data)
672 {
673         struct sctp_udata *udata;
674         int dir;
675
676         udata = (struct sctp_udata *)u_data;
677         dir=udata->dir-1;
678         gtk_grab_remove(GTK_WIDGET(udata->io->window));
679         gtk_widget_destroy(GTK_WIDGET(udata->io->window));
680
681 }
682
683 static gint
684 configure_event(GtkWidget *widget, GdkEventConfigure *event _U_, struct sctp_udata *u_data)
685 {
686         if(!u_data->io){
687                 exit(10);
688         }
689
690         if(u_data->io->pixmap){
691                 gdk_pixmap_unref(u_data->io->pixmap);
692                 u_data->io->pixmap=NULL;
693         }
694
695         u_data->io->pixmap=gdk_pixmap_new(widget->window,
696                         widget->allocation.width,
697                         widget->allocation.height,
698                         -1);
699         u_data->io->pixmap_width=widget->allocation.width;
700         u_data->io->pixmap_height=widget->allocation.height;
701
702         gdk_draw_rectangle(u_data->io->pixmap,
703                         widget->style->white_gc,
704                         TRUE,
705                         0, 0,
706                         widget->allocation.width,
707                         widget->allocation.height);
708         sctp_graph_redraw(u_data);
709         sctp_graph_redraw(u_data);
710         return TRUE;
711 }
712
713 static gint
714 expose_event(GtkWidget *widget, GdkEventExpose *event)
715 {
716         sctp_graph_t *ios;
717
718         ios=(sctp_graph_t *)OBJECT_GET_DATA(widget, "sctp_graph_t");
719         if(!ios){
720                 exit(10);
721         }
722
723         gdk_draw_pixmap(widget->window,
724                         widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
725                         ios->pixmap,
726                         event->area.x, event->area.y,
727                         event->area.x, event->area.y,
728                         event->area.width, event->area.height);
729
730         return FALSE;
731 }
732
733
734 static void
735 on_zoomin_bt (GtkWidget *widget _U_, struct sctp_udata *u_data)
736 {
737         sctp_min_max_t *tmp_minmax;
738
739         if (u_data->io->rectangle==TRUE)
740         {
741                 tmp_minmax = g_malloc(sizeof(sctp_min_max_t));
742
743                 u_data->io->tmp_min_tsn1=u_data->io->y1_tmp+u_data->io->min_y;
744                 u_data->io->tmp_max_tsn1=u_data->io->y2_tmp+1+u_data->io->min_y;
745                 u_data->io->tmp_min_tsn2=u_data->io->tmp_min_tsn1;
746                 u_data->io->tmp_max_tsn2=u_data->io->tmp_max_tsn1;
747                 tmp_minmax->tmp_min_secs=u_data->io->x1_tmp_sec;
748                 tmp_minmax->tmp_min_usecs=      u_data->io->x1_tmp_usec;
749                 tmp_minmax->tmp_max_secs=       u_data->io->x2_tmp_sec;
750                 tmp_minmax->tmp_max_usecs=      u_data->io->x2_tmp_usec;
751                 tmp_minmax->tmp_min_tsn1=u_data->io->tmp_min_tsn1;
752                 tmp_minmax->tmp_max_tsn1=u_data->io->tmp_max_tsn1;
753                 tmp_minmax->tmp_min_tsn2=u_data->io->tmp_min_tsn2;
754                 tmp_minmax->tmp_max_tsn2=u_data->io->tmp_max_tsn2;
755                 u_data->assoc->min_max = g_slist_prepend(u_data->assoc->min_max, tmp_minmax);
756                 u_data->io->length = g_slist_length(u_data->assoc->min_max);
757                 u_data->io->tmp=TRUE;
758                 u_data->io->rectangle=FALSE;
759                 sctp_graph_redraw(u_data);
760         }
761 }
762
763 static void
764 on_zoomout_bt (GtkWidget *widget _U_, struct sctp_udata *u_data)
765 {
766         sctp_min_max_t *tmp_minmax, *mm;
767         gint l;
768
769         l = g_slist_length(u_data->assoc->min_max);
770
771         if (u_data->assoc->min_max!=NULL)
772         {
773                 mm=(sctp_min_max_t *)((u_data->assoc->min_max)->data);
774                 u_data->assoc->min_max=g_slist_remove(u_data->assoc->min_max, mm);
775                 g_free(mm);
776                 if (l>2)
777                 {
778                         tmp_minmax = (sctp_min_max_t *)u_data->assoc->min_max->data;
779                         u_data->io->x1_tmp_sec=tmp_minmax->tmp_min_secs;
780                         u_data->io->x1_tmp_usec=tmp_minmax->tmp_min_usecs;
781                         u_data->io->x2_tmp_sec=tmp_minmax->tmp_max_secs;
782                         u_data->io->x2_tmp_usec=tmp_minmax->tmp_max_usecs;
783                         u_data->io->tmp_min_tsn1=tmp_minmax->tmp_min_tsn1;
784                         u_data->io->tmp_max_tsn1=tmp_minmax->tmp_max_tsn1;
785                         u_data->io->tmp_min_tsn2=tmp_minmax->tmp_min_tsn2;
786                         u_data->io->tmp_max_tsn2=tmp_minmax->tmp_max_tsn2;
787                         u_data->io->tmp=TRUE;
788                 }
789                 else
790                 {
791                         u_data->io->x1_tmp_sec=u_data->assoc->min_secs;
792                         u_data->io->x1_tmp_usec=u_data->assoc->min_usecs;
793                         u_data->io->x2_tmp_sec=u_data->assoc->max_secs;
794                         u_data->io->x2_tmp_usec=u_data->assoc->max_usecs;
795                         u_data->io->tmp_min_tsn1=u_data->assoc->min_tsn1;
796                         u_data->io->tmp_max_tsn1=u_data->assoc->max_tsn1;
797                         u_data->io->tmp_min_tsn2=u_data->assoc->min_tsn2;
798                         u_data->io->tmp_max_tsn2=u_data->assoc->max_tsn2;
799                         u_data->io->tmp=FALSE;
800                 }
801         }
802         else
803         {
804                 u_data->io->x1_tmp_sec=u_data->assoc->min_secs;
805                 u_data->io->x1_tmp_usec=u_data->assoc->min_usecs;
806                 u_data->io->x2_tmp_sec=u_data->assoc->max_secs;
807                 u_data->io->x2_tmp_usec=u_data->assoc->max_usecs;
808                 u_data->io->tmp_min_tsn1=u_data->assoc->min_tsn1;
809                 u_data->io->tmp_max_tsn1=u_data->assoc->max_tsn1;
810                 u_data->io->tmp_min_tsn2=u_data->assoc->min_tsn2;
811                 u_data->io->tmp_max_tsn2=u_data->assoc->max_tsn2;
812                 u_data->io->tmp=FALSE;
813         }
814
815         sctp_graph_redraw(u_data);
816 }
817
818
819 static gint
820 on_button_press (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_udata *u_data)
821 {
822         sctp_graph_t *ios;
823
824         if (u_data->io->rectangle==TRUE)
825         {
826                 gdk_draw_rectangle(u_data->io->pixmap,u_data->io->draw_area->style->white_gc,
827                                    FALSE,
828                                    (gint)floor(MINI(u_data->io->x_old,u_data->io->x_new)),
829                                    (gint)floor(MINI(u_data->io->y_old,u_data->io->y_new)),
830                                    (gint)floor(abs((long)(u_data->io->x_new-u_data->io->x_old))),
831                                    (gint)floor(abs((long)(u_data->io->y_new-u_data->io->y_old))));
832                 ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
833
834                 if(!ios){
835                         exit(10);
836                 }
837
838                 gdk_draw_pixmap(u_data->io->draw_area->window,
839                                 u_data->io->draw_area->style->fg_gc[GTK_WIDGET_STATE(u_data->io->draw_area)],
840                                 ios->pixmap,
841                                 0,0,
842                                 0, 0,
843                                 (gint)(abs((long)(u_data->io->x_new-u_data->io->x_old))),
844                                 (gint)(abs((long)(u_data->io->y_new-u_data->io->y_old))));
845                 sctp_graph_redraw(u_data);
846         }
847         u_data->io->x_old=event->x;
848         u_data->io->y_old=event->y;
849         if (u_data->io->y_old>u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
850                 u_data->io->y_old=u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset;
851         if (u_data->io->x_old<LEFT_BORDER+u_data->io->offset)
852                 u_data->io->x_old=LEFT_BORDER+u_data->io->offset;
853         u_data->io->rectangle=FALSE;
854
855         return TRUE;
856 }
857
858
859 static gint
860 on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_udata *u_data)
861 {
862         sctp_graph_t *ios;
863         guint32 helpx;
864         guint32 helpy, x1_tmp, x2_tmp;
865
866         if (event->y>u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
867                 event->y = u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset;
868         if (event->x < LEFT_BORDER+u_data->io->offset)
869                 event->x = LEFT_BORDER+u_data->io->offset;
870         if (abs((long)(event->x-u_data->io->x_old))>10 || abs((long)(event->y-u_data->io->y_old))>10)
871         {
872                 gdk_draw_rectangle(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
873                                    FALSE,
874                                    (gint)floor(MINI(u_data->io->x_old,event->x)), (gint)floor(MINI(u_data->io->y_old,event->y)),
875                                    (gint)abs((long)(event->x-u_data->io->x_old)),
876                                    (gint)abs((long)(event->y-u_data->io->y_old)));
877                 ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
878
879                 if(!ios){
880                         exit(10);
881                 }
882
883                 gdk_draw_pixmap(u_data->io->draw_area->window,
884                                 u_data->io->draw_area->style->fg_gc[GTK_WIDGET_STATE(u_data->io->draw_area)],
885                                 ios->pixmap,
886                                 0, 0,
887                                 0, 0,
888                                 u_data->io->draw_area->allocation.width,
889                                 u_data->io->draw_area->allocation.height);
890
891                 x1_tmp=(unsigned int)floor(u_data->io->min_x+((u_data->io->x_old-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
892                 x2_tmp=(unsigned int)floor(u_data->io->min_x+((event->x-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
893                 helpx=MINI(x1_tmp, x2_tmp);
894                 if (helpx==x2_tmp)
895                 {
896                         x2_tmp=x1_tmp;
897                         x1_tmp=helpx;
898                 }
899                 u_data->io->x1_tmp_sec=(guint32)x1_tmp/1000000;
900                 u_data->io->x1_tmp_usec=x1_tmp%1000000;
901                 u_data->io->x2_tmp_sec=(guint32)x2_tmp/1000000;
902                 u_data->io->x2_tmp_usec=x2_tmp%1000000;
903                 u_data->io->y1_tmp=(guint32)((u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->y_old)/u_data->io->y_interval);
904                 u_data->io->y2_tmp=(guint32)((u_data->io->pixmap_height-BOTTOM_BORDER-event->y)/u_data->io->y_interval);
905                 helpy = MINI(u_data->io->y1_tmp, u_data->io->y2_tmp);
906                 u_data->io->y2_tmp = MAXI(u_data->io->y1_tmp, u_data->io->y2_tmp);
907                 u_data->io->y1_tmp = helpy;
908                 u_data->io->x_new=event->x;
909                 u_data->io->y_new=event->y;
910                 u_data->io->rectangle=TRUE;
911         }
912
913         return TRUE;
914 }
915
916
917 static void init_sctp_graph_window(struct sctp_udata *u_data)
918 {
919         GtkWidget *vbox;
920         GtkWidget *hbox;
921         GtkWidget *bt_close, *sack_bt, *tsn_bt, *both_bt, *zoomin_bt, *zoomout_bt;
922         GtkTooltips *tooltip_in, *tooltip_out;
923
924         /* create the main window */
925
926         u_data->io->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
927
928         gtk_widget_set_name(u_data->io->window, "SCTP Graphics");
929
930         vbox=gtk_vbox_new(FALSE, 0);
931         gtk_container_add(GTK_CONTAINER(u_data->io->window), vbox);
932         gtk_widget_show(vbox);
933
934         create_draw_area(vbox, u_data);
935
936         sctp_graph_set_title(u_data);
937
938         hbox = gtk_hbutton_box_new();
939         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
940         gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
941         gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
942         gtk_button_box_set_spacing(GTK_BUTTON_BOX (hbox), 0);
943         gtk_box_set_child_packing(GTK_BOX(vbox), hbox, FALSE, FALSE, 0, GTK_PACK_START);
944         gtk_widget_show(hbox);
945
946         sack_bt = gtk_button_new_with_label ("Show Sacks");
947         gtk_box_pack_start(GTK_BOX(hbox), sack_bt, FALSE, FALSE, 0);
948         gtk_widget_show(sack_bt);
949
950         gtk_signal_connect(GTK_OBJECT(sack_bt), "clicked", (GtkSignalFunc)on_sack_bt, u_data);
951
952         tsn_bt = gtk_button_new_with_label ("Show TSNs");
953         gtk_box_pack_start(GTK_BOX(hbox), tsn_bt, FALSE, FALSE, 0);
954         gtk_widget_show(tsn_bt);
955         SIGNAL_CONNECT(tsn_bt, "clicked", on_tsn_bt, u_data);
956
957         both_bt = gtk_button_new_with_label ("Show both");
958         gtk_box_pack_start(GTK_BOX(hbox), both_bt, FALSE, FALSE, 0);
959         gtk_widget_show(both_bt);
960         SIGNAL_CONNECT(both_bt, "clicked", on_both_bt, u_data);
961
962         zoomin_bt = gtk_button_new_with_label ("Zoom in");
963         gtk_box_pack_start(GTK_BOX(hbox), zoomin_bt, FALSE, FALSE, 0);
964         gtk_widget_show(zoomin_bt);
965         SIGNAL_CONNECT(zoomin_bt, "clicked", on_zoomin_bt, u_data);
966         tooltip_in = gtk_tooltips_new();
967         gtk_tooltips_set_tip(tooltip_in, zoomin_bt, "Draw a rectangle around the area you want to zoom in", NULL);
968
969         zoomout_bt = gtk_button_new_with_label ("Zoom out");
970         gtk_box_pack_start(GTK_BOX(hbox), zoomout_bt, FALSE, FALSE, 0);
971         gtk_widget_show(zoomout_bt);
972         SIGNAL_CONNECT(zoomout_bt, "clicked", on_zoomout_bt, u_data);
973         tooltip_out = gtk_tooltips_new();
974         gtk_tooltips_set_tip(tooltip_out, zoomout_bt, "Zoom out one step", NULL);
975
976
977         bt_close = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
978         gtk_box_pack_start(GTK_BOX(hbox), bt_close, FALSE, FALSE, 0);
979         gtk_widget_show(bt_close);
980         SIGNAL_CONNECT(bt_close, "clicked", sctp_graph_close_cb, u_data);
981
982         gtk_signal_connect(GTK_OBJECT(u_data->io->draw_area),"button_press_event",(GtkSignalFunc)on_button_press, u_data);
983         gtk_signal_connect(GTK_OBJECT(u_data->io->draw_area),"button_release_event",(GtkSignalFunc)on_button_release, u_data);
984         gtk_widget_set_events(u_data->io->draw_area, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXPOSURE_MASK);
985         /* dlg_set_cancel(u_data->io->window, bt_close); */
986         
987         gtk_widget_show(u_data->io->window);
988 }
989
990 static void sctp_graph_set_title(struct sctp_udata *u_data)
991 {
992         char *title;
993
994         if(!u_data->io->window)
995         {
996                 return;
997         }
998         title = g_strdup_printf("SCTP TSNs and Sacks over Time: %s Port1 %u Port2 %u Endpoint %u",
999                                 cf_get_display_name(&cfile), u_data->parent->assoc->port1, u_data->parent->assoc->port2, u_data->dir);
1000         gtk_window_set_title(GTK_WINDOW(u_data->io->window), title);
1001         g_free(title);
1002 }
1003
1004 static void
1005 gtk_sctpgraph_init(struct sctp_udata *u_data)
1006 {
1007         sctp_graph_t *io;
1008         gint dir;
1009         sctp_min_max_t* tmp_minmax;
1010
1011         io=g_malloc(sizeof(sctp_graph_t));
1012         io->needs_redraw=TRUE;
1013         io->x_interval=1000;
1014         io->window=NULL;
1015         io->draw_area=NULL;
1016         io->pixmap=NULL;
1017         io->pixmap_width=800;
1018         io->pixmap_height=600;
1019         io->graph_type=0;
1020         dir=u_data->dir-1;
1021
1022         u_data->io=io;
1023         u_data->io->x1_tmp_sec=u_data->assoc->min_secs;
1024         u_data->io->x1_tmp_usec=u_data->assoc->min_usecs;
1025         u_data->io->x2_tmp_sec=u_data->assoc->max_secs;
1026         u_data->io->x2_tmp_usec=u_data->assoc->max_usecs;
1027         u_data->io->tmp_min_tsn1=u_data->assoc->min_tsn1;
1028         u_data->io->tmp_max_tsn1=u_data->assoc->max_tsn1;
1029         u_data->io->tmp_min_tsn2=u_data->assoc->min_tsn2;
1030         u_data->io->tmp_max_tsn2=u_data->assoc->max_tsn2;
1031         u_data->io->tmp=FALSE;
1032
1033         tmp_minmax = g_malloc(sizeof(sctp_min_max_t));
1034         tmp_minmax->tmp_min_secs = u_data->assoc->min_secs;
1035         tmp_minmax->tmp_min_usecs=u_data->assoc->min_usecs;
1036         tmp_minmax->tmp_max_secs=u_data->assoc->max_secs;
1037         tmp_minmax->tmp_max_usecs=u_data->assoc->max_usecs;
1038         tmp_minmax->tmp_min_tsn2=u_data->assoc->min_tsn2;
1039         tmp_minmax->tmp_min_tsn1=u_data->assoc->min_tsn1;
1040         tmp_minmax->tmp_max_tsn1=u_data->assoc->max_tsn1;
1041         tmp_minmax->tmp_max_tsn2=u_data->assoc->max_tsn2;
1042         u_data->assoc->min_max = g_slist_prepend(u_data->assoc->min_max, tmp_minmax);
1043
1044         /* build the GUI */
1045         init_sctp_graph_window(u_data);
1046         sctp_graph_redraw(u_data);
1047
1048 }
1049
1050
1051 static gint
1052 quit(GtkObject *object _U_, gpointer user_data)
1053 {
1054         struct sctp_udata *u_data=(struct sctp_udata*)user_data;
1055
1056         decrease_childcount(u_data->parent);
1057         remove_child(u_data, u_data->parent);
1058
1059         g_free(u_data->io);
1060
1061         u_data->assoc->min_max = NULL;
1062         g_free(u_data);
1063         return TRUE;
1064 }
1065
1066
1067 static void create_draw_area(GtkWidget *box, struct sctp_udata *u_data)
1068 {
1069
1070         u_data->io->draw_area=gtk_drawing_area_new();
1071         SIGNAL_CONNECT(u_data->io->draw_area, "destroy", quit, u_data);
1072         OBJECT_SET_DATA(u_data->io->draw_area, "sctp_graph_t", u_data->io);
1073
1074         WIDGET_SET_SIZE(u_data->io->draw_area, u_data->io->pixmap_width, u_data->io->pixmap_height);
1075
1076         /* signals needed to handle backing pixmap */
1077         SIGNAL_CONNECT(u_data->io->draw_area, "expose_event", expose_event, NULL);
1078         SIGNAL_CONNECT(u_data->io->draw_area, "configure_event", configure_event, u_data);
1079
1080         gtk_widget_show(u_data->io->draw_area);
1081         gtk_box_pack_start(GTK_BOX(box), u_data->io->draw_area, TRUE, TRUE, 0);
1082 }
1083
1084
1085
1086 void create_graph(guint16 dir, struct sctp_analyse* userdata)
1087 {
1088         struct sctp_udata *u_data;
1089
1090         u_data=g_malloc(sizeof(struct sctp_udata));
1091         u_data->assoc=g_malloc(sizeof(sctp_assoc_info_t));
1092         u_data->assoc=userdata->assoc;
1093         u_data->io=NULL;
1094         u_data->dir = dir;
1095         u_data->parent = userdata;
1096         if ((u_data->dir==1 && u_data->assoc->n_array_tsn1==0)|| (u_data->dir==2 && u_data->assoc->n_array_tsn2==0))
1097                 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No Data Chunks sent");
1098         else
1099         {
1100                 set_child(u_data, u_data->parent);
1101                 increase_childcount(u_data->parent);
1102                 gtk_sctpgraph_init(u_data);
1103         }
1104 }