Remove file_dlg_win32.c and print_win32.c from the checkapi target.
[obnox/wireshark/wip.git] / gtk / sctp_graph_dlg.c
index 137df2e378ee274dab61c75c02a83ea7267bcdfa..0e250f6428756889c0c6634d4d9bd68e061cc7f2 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
+ * Copyright 2009, Varun Notibala <nbvarun [AT] gmail.com>
  *
  * $Id$
  *
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
-
-
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
-#include "globals.h"
+
+#include <gtk/gtk.h>
+
 #include "epan/filesystem.h"
+#include <epan/strutil.h>
+
+#include "../globals.h"
 #include "../color.h"
-#include "dlg_utils.h"
-#include "ui_util.h"
-#include "main.h"
-#include "compat_macros.h"
-#include "simple_dialog.h"
-#include "sctp_stat.h"
+#include "../ui_util.h"
+#include "../simple_dialog.h"
+
+#include "gtk/dlg_utils.h"
+#include "gtk/main.h"
+#include "gtk/sctp_stat.h"
+
 
 #define DEFAULT_PIXELS_PER_TICK 2
 #define MAX_PIXELS_PER_TICK 4
 #define SUB_32(a, b)   a-b
 #define POINT_SIZE     3
 
+static GtkWidget * sack_bt;
+
+/*
+ * Global variables that help in redrawing graph
+ * for SACK and NRSACK
+ */
+static guint8 gIsSackChunkPresent   = 0;
+static guint8 gIsNRSackChunkPresent = 0;
+
 struct chunk_header {
        guint8  type;
        guint8  flags;
@@ -106,56 +118,54 @@ struct sack_chunk_header {
        struct gaps gaps[1];
 };
 
+struct nr_sack_chunk_header {
+       guint8  type;
+       guint8  flags;
+       guint16 length;
+       guint32 cum_tsn_ack;
+       guint32 a_rwnd;
+       guint16 nr_of_gaps;
+       guint16 nr_of_nr_gaps;
+       guint16 nr_of_dups;
+       guint16 reserved;
+       struct gaps gaps[1];
+};
 
 static gboolean label_set = FALSE;
 static guint32 max_tsn=0, min_tsn=0;
 static void sctp_graph_set_title(struct sctp_udata *u_data);
 static void create_draw_area(GtkWidget *box, struct sctp_udata *u_data);
 static GtkWidget *zoomout_bt;
+#if defined(_WIN32) && !defined(__MINGW32__)
+static int rint (double );     /* compiler template for Windows */
+#endif
 
-static void draw_sack_graph(struct sctp_udata *u_data)
+static void
+draw_sack_graph(struct sctp_udata *u_data)
 {
        tsn_t   *sack;
        GList *list=NULL, *tlist;
-       guint16 gap_start=0, gap_end=0, i, j, nr;
+       guint16 gap_start=0, gap_end=0, i, j, nr, dup_nr;
        guint8 type;
-       guint32 tsnumber;
+       guint32 tsnumber, dup;
        gint xvalue, yvalue;
        GdkColor red_color = {0, 65535, 0, 0};
        GdkColor green_color = {0, 0, 65535, 0};
-       GdkGC *red_gc, *green_gc;
+       GdkColor cyan_color = {0, 0, 65535, 65535};
+       GdkGC *red_gc, *green_gc, *cyan_gc;
        struct sack_chunk_header *sack_header;
        struct gaps *gap;
        guint32 max_num, diff;
-#if GTK_MAJOR_VERSION < 2
-       GdkColormap *colormap;
-#endif
+       guint32 *dup_list;
 
        red_gc = gdk_gc_new(u_data->io->draw_area->window);
-#if GTK_MAJOR_VERSION < 2
-               colormap = gtk_widget_get_colormap (u_data->io->draw_area);
-               if (!gdk_color_alloc (colormap, &red_color))
-               {
-                       g_warning ("Couldn't allocate color");
-               }
-
-               gdk_gc_set_foreground(red_gc, &red_color);
-#else
-               gdk_gc_set_rgb_fg_color(red_gc, &red_color);
-#endif
+       gdk_gc_set_rgb_fg_color(red_gc, &red_color);
 
        green_gc = gdk_gc_new(u_data->io->draw_area->window);
-#if GTK_MAJOR_VERSION < 2
-               colormap = gtk_widget_get_colormap (u_data->io->draw_area);
-               if (!gdk_color_alloc (colormap, &green_color))
-               {
-                       g_warning ("Couldn't allocate color");
-               }
+       gdk_gc_set_rgb_fg_color(green_gc, &green_color);
 
-               gdk_gc_set_foreground(green_gc, &green_color);
-#else
-               gdk_gc_set_rgb_fg_color(green_gc, &green_color);
-#endif
+       cyan_gc = gdk_gc_new(u_data->io->draw_area->window);
+       gdk_gc_set_rgb_fg_color(cyan_gc, &cyan_color);
 
        if (u_data->dir==2)
        {
@@ -197,9 +207,11 @@ static void draw_sack_graph(struct sctp_udata *u_data)
 
                        if (type == SCTP_SACK_CHUNK_ID)
                        {
+                               gIsSackChunkPresent = 1;
                                sack_header =(struct sack_chunk_header *)tlist->data;
-                               nr=ntohs(sack_header->nr_of_gaps);
+                               nr=g_ntohs(sack_header->nr_of_gaps);
                                tsnumber = g_ntohl(sack_header->cum_tsn_ack);
+                               dup_nr=g_ntohs(sack_header->nr_of_dups);
 
                                if (sack->secs>=u_data->io->x1_tmp_sec)
                                {
@@ -208,8 +220,8 @@ static void draw_sack_graph(struct sctp_udata *u_data)
                                                gap = &sack_header->gaps[0];
                                                for(i=0;i<nr; i++)
                                                {
-                                                       gap_start=ntohs(gap->start);
-                                                       gap_end = ntohs(gap->end);
+                                                       gap_start=g_ntohs(gap->start);
+                                                       gap_end = g_ntohs(gap->end);
                                                        max_num=gap_end+tsnumber;
                                                        for (j=gap_start; j<=gap_end; j++)
                                                        {
@@ -221,12 +233,12 @@ static void draw_sack_graph(struct sctp_udata *u_data)
                                                                yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE-u_data->io->offset-((SUB_32(j+tsnumber,min_tsn))*u_data->io->y_interval));
                                                                if (xvalue >= LEFT_BORDER+u_data->io->offset &&
                                                                    xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
-                                                                   yvalue >= TOP_BORDER-u_data->io->offset &&
+                                                                   yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
                                                                    yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
                                                                        gdk_draw_arc(u_data->io->pixmap,green_gc,TRUE,
-                                                                                   xvalue,
-                                                                                   yvalue,
-                                                                                   POINT_SIZE, POINT_SIZE,0, (64*360) );
+                                                                                    xvalue,
+                                                                                    yvalue,
+                                                                                    POINT_SIZE, POINT_SIZE,0, (64*360) );
                                                        }
                                                        if (i < nr-1)
                                                                gap++;
@@ -242,29 +254,225 @@ static void draw_sack_graph(struct sctp_udata *u_data)
                                                        diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
                                                xvalue = (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff);
                                                yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE -u_data->io->offset-((SUB_32(tsnumber,min_tsn))*u_data->io->y_interval));
-                                               if (xvalue >= LEFT_BORDER+u_data->io->offset && 
+                                               if (xvalue >= LEFT_BORDER+u_data->io->offset &&
                                                    xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
-                                                   yvalue >= TOP_BORDER-u_data->io->offset &&
+                                                   yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
                                                    yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
+                                                   {
                                                        gdk_draw_arc(u_data->io->pixmap,red_gc,TRUE,
                                                                     xvalue,
                                                                     yvalue,
                                                                     POINT_SIZE, POINT_SIZE,0, (64*360) );
+                                                       }
+                                       }
+                                       if (dup_nr > 0)
+                                       {
+                                               dup_list = (guint32 *)(((char *)&sack_header->nr_of_dups)+sizeof(guint16)+(nr*sizeof(struct gaps)));
+                                               for (i = 0; i < dup_nr; i++)
+                                               {
+                                                       dup = g_ntohl(dup_list[i]);
+                                                       if (dup >= min_tsn)
+                                                       {
+                                                               if (u_data->io->uoff)
+                                                                       diff = sack->secs - u_data->io->min_x;
+                                                               else
+                                                                       diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
+                                                               xvalue = (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff);
+                                                               yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE -u_data->io->offset-((SUB_32(dup,min_tsn))*u_data->io->y_interval));
+                                                               if (xvalue >= LEFT_BORDER+u_data->io->offset &&
+                                                                   xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
+                                                                   yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
+                                                                   yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
+                                                                       gdk_draw_arc(u_data->io->pixmap,cyan_gc,TRUE,
+                                                                                    xvalue,
+                                                                                    yvalue,
+                                                                                    POINT_SIZE, POINT_SIZE,0, (64*360) );
+                                                       }
+                                               }
                                        }
                                }
-                       tlist = g_list_next(tlist);
                        }
+                       tlist = g_list_next(tlist);
                }
                list = g_list_previous(list);
        }
-#if GTK_MAJOR_VERSION >= 2
-               g_object_unref(G_OBJECT(red_gc));
-               g_object_unref(G_OBJECT(green_gc));
-#endif
+       g_object_unref(G_OBJECT(red_gc));
+       g_object_unref(G_OBJECT(green_gc));
 }
 
+/*
+ * This function plots the NR_SACK gap ack and
+ * nr gap acks.
+ * Red dot - Cumulative TSN ack
+ * Green dot - Gap ack
+ * Blue circle - NR Gap ack
+ */
+static void
+draw_nr_sack_graph(struct sctp_udata *u_data)
+{
+       tsn_t *sack;
+       GList *list=NULL, *tlist;
+       guint16 gap_start=0, gap_end=0, i, numberOf_gaps, numberOf_nr_gaps;
+       guint8 type;
+       guint32 tsnumber, j;
+       gint xvalue, yvalue;
+       GdkColor red_color = {0, 65535, 0, 0};
+       GdkColor blue_color = {0, 0, 0, 65535};
+       GdkColor green_color = {0, 0, 65535, 0};
+       GdkGC *red_gc, *blue_gc, *green_gc;
+       struct nr_sack_chunk_header *nr_sack_header;
+       struct gaps *nr_gap;
+       guint32 max_num, diff;
+       /* This holds the sum of gap acks and nr gap acks */
+       guint16 total_gaps = 0;
+
+       red_gc = gdk_gc_new(u_data->io->draw_area->window);
+       gdk_gc_set_rgb_fg_color(red_gc, &red_color);
+       blue_gc = gdk_gc_new(u_data->io->draw_area->window);
+       gdk_gc_set_rgb_fg_color(blue_gc, &blue_color);
+       green_gc = gdk_gc_new(u_data->io->draw_area->window);
+       gdk_gc_set_rgb_fg_color(green_gc, &green_color);
+
+
+       if (u_data->dir==2)
+       {
+               list = g_list_last(u_data->assoc->sack2);
+               if (u_data->io->tmp==FALSE)
+               {
+                       min_tsn=u_data->assoc->min_tsn2;
+                       max_tsn=u_data->assoc->max_tsn2;
+               }
+               else
+               {
+                       min_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_min_tsn2;
+                       max_tsn=u_data->assoc->min_tsn2+u_data->io->tmp_max_tsn2;
+               }
+       }
+       else if (u_data->dir==1)
+       {
+               list = g_list_last(u_data->assoc->sack1);
+               if (u_data->io->tmp==FALSE)
+               {
+                       min_tsn=u_data->assoc->min_tsn1;
+                       max_tsn=u_data->assoc->max_tsn1;
+               }
+               else
+               {
+                       min_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_min_tsn1;
+                       max_tsn=u_data->assoc->min_tsn1+u_data->io->tmp_max_tsn1;
+               }
+       }
+       while (list)
+       {
+               sack = (tsn_t*) (list->data);
+               tlist = g_list_first(sack->tsns);
+               while (tlist)
+               {
+                       type = ((struct chunk_header *)tlist->data)->type;
+                       /*
+                        * The tlist->data is memcpy ied to the appropriate structure
+                        * They entire raw tvb bytes are copied on to one of the *_chunk_header
+                        * structures in sctp_stat.c
+                        */
+                       if (type == SCTP_NR_SACK_CHUNK_ID)
+                       {
+                               gIsNRSackChunkPresent = 1;
+                               nr_sack_header =(struct nr_sack_chunk_header *)tlist->data;
+                               numberOf_nr_gaps=g_ntohs(nr_sack_header->nr_of_nr_gaps);
+                               numberOf_gaps=g_ntohs(nr_sack_header->nr_of_gaps);
+                               tsnumber = g_ntohl(nr_sack_header->cum_tsn_ack);
+                               total_gaps = numberOf_gaps + numberOf_nr_gaps;
+                               if (sack->secs>=u_data->io->x1_tmp_sec)
+                               {
+                                       /* If the number of nr_gaps is greater than 0 */
+                                       if ( total_gaps > 0 )
+                                       {
+                                               nr_gap = &nr_sack_header->gaps[0];
+                                               for ( i=0; i < total_gaps; i++ )
+                                               {
+                                                       gap_start=g_ntohs(nr_gap->start);
+                                                       gap_end = g_ntohs(nr_gap->end);
+                                                       max_num= gap_end + tsnumber;
+                                                       for ( j = gap_start; j <= gap_end; j++)
+                                                       {
+                                                               if (u_data->io->uoff)
+                                                                       diff = sack->secs - u_data->io->min_x;
+                                                               else
+                                                                       diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
+                                                               xvalue = (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff);
+                                                               yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE-u_data->io->offset-((SUB_32(j+tsnumber,min_tsn))*u_data->io->y_interval));
+                                                               if (xvalue >= LEFT_BORDER+u_data->io->offset &&
+                                                                   xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
+                                                                   yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
+                                                                   yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
+                                                               {
+                                                                       /* Check if this is an GAP ACK or NR GAP ACK */
+                                                                       if ( i >= numberOf_gaps)
+                                                                       {
+                                                                               /* This is a nr gap ack */
+                                                                               gdk_draw_arc(u_data->io->pixmap,blue_gc,FALSE,
+                                                                                            xvalue,
+                                                                                            yvalue,
+                                                                                            POINT_SIZE , POINT_SIZE,0, (64*360) );
+
+                                                                               /* All NR GAP Acks are also gap acks, so plot these as
+                                                                                * gap acks - green dot.
+                                                                                * These will be shown as points with a green dot - GAP ACK
+                                                                                * surrounded by a blue circle - NR GAP ack
+                                                                                */
+                                                                               gdk_draw_arc(u_data->io->pixmap, green_gc, TRUE,
+                                                                                            xvalue,
+                                                                                            yvalue,
+                                                                                            POINT_SIZE , POINT_SIZE,0, (64*360) );
+
+                                                                       }
+                                                                       else
+                                                                       {
+                                                                               /* This is just a gap ack */
+                                                                               gdk_draw_arc(u_data->io->pixmap, green_gc, TRUE,
+                                                                                            xvalue,
+                                                                                            yvalue,
+                                                                                            POINT_SIZE , POINT_SIZE,0, (64*360) );
+                                                                       }
+                                                               }
+                                                       }
+                                                       if (i < total_gaps-1)
+                                                               nr_gap++;
+                                               }
+                                       }
+                                       else
+                                               max_num=tsnumber;
+
+                                       if (tsnumber>=min_tsn)
+                                       {
+                                               if (u_data->io->uoff)
+                                                       diff = sack->secs - u_data->io->min_x;
+                                               else
+                                                       diff=sack->secs*1000000+sack->usecs-u_data->io->min_x;
+                                               xvalue = (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff);
+                                               yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE -u_data->io->offset-((SUB_32(tsnumber,min_tsn))*u_data->io->y_interval));
+                                               if (xvalue >= LEFT_BORDER+u_data->io->offset &&
+                                                   xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
+                                                   yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
+                                                   yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
+                                                       gdk_draw_arc(u_data->io->pixmap,red_gc,TRUE,
+                                                                    xvalue,
+                                                                    yvalue,
+                                                                    POINT_SIZE, POINT_SIZE,0, (64*360) );
+                                       }
+                               }
+                       }
+                       tlist = g_list_next(tlist);
+               }
+               list = g_list_previous(list);
+       }
+       g_object_unref(G_OBJECT(red_gc));
+       g_object_unref(G_OBJECT(blue_gc));
+       g_object_unref(G_OBJECT(green_gc));
+}
 
-static void draw_tsn_graph(struct sctp_udata *u_data)
+static void
+draw_tsn_graph(struct sctp_udata *u_data)
 {
        tsn_t *tsn;
        GList *list=NULL, *tlist;
@@ -319,9 +527,9 @@ static void draw_tsn_graph(struct sctp_udata *u_data)
                                                diff=tsn->secs*1000000+tsn->usecs-u_data->io->min_x;
                                        xvalue = (guint32)(LEFT_BORDER+u_data->io->offset+u_data->io->x_interval*diff);
                                        yvalue = (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-POINT_SIZE-u_data->io->offset-((SUB_32(tsnumber,min_tsn))*u_data->io->y_interval));
-                                       if (xvalue >= LEFT_BORDER+u_data->io->offset && 
+                                       if (xvalue >= LEFT_BORDER+u_data->io->offset &&
                                            xvalue <= u_data->io->pixmap_width-RIGHT_BORDER+u_data->io->offset &&
-                                           yvalue >= TOP_BORDER-u_data->io->offset &&
+                                           yvalue >= TOP_BORDER-u_data->io->offset-POINT_SIZE &&
                                            yvalue <= u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
                                                gdk_draw_arc(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,TRUE,
                                                             xvalue,
@@ -335,7 +543,8 @@ static void draw_tsn_graph(struct sctp_udata *u_data)
 }
 
 
-static void sctp_graph_draw(struct sctp_udata *u_data)
+static void
+sctp_graph_draw(struct sctp_udata *u_data)
 {
        int length, lwidth;
        guint32  distance=5, i, e, sec, w, start, a, b, j;
@@ -343,12 +552,7 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
        char label_string[15];
        gfloat dis;
        gboolean write_label = FALSE;
-
-#if GTK_MAJOR_VERSION < 2
-       GdkFont *font;
-#else
        PangoLayout  *layout;
-#endif
 
        if (u_data->io->x1_tmp_sec==0 && u_data->io->x1_tmp_usec==0)
                u_data->io->offset=0;
@@ -363,8 +567,8 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
        }
        else
        {
-               u_data->io->min_x=((guint32)(u_data->io->x1_tmp_sec*1000000.0))+u_data->io->x1_tmp_usec;
-               u_data->io->max_x=((guint32)(u_data->io->x2_tmp_sec*1000000.0))+u_data->io->x2_tmp_usec;                
+               u_data->io->min_x=(guint32)(u_data->io->x1_tmp_sec*1000000.0+u_data->io->x1_tmp_usec);
+               u_data->io->max_x=(guint32)(u_data->io->x2_tmp_sec*1000000.0+u_data->io->x2_tmp_usec);
                u_data->io->uoff = FALSE;
        }
 
@@ -440,21 +644,11 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
        else
                distance=5;
 
-#if GTK_MAJOR_VERSION < 2
-       font = u_data->io->draw_area->style->font;
-#endif
-
-#if GTK_MAJOR_VERSION < 2
-       label_width=gdk_string_width(font, label_string);
-       label_height=gdk_string_height(font, label_string);
-#else
-       g_snprintf(label_string, 15, "%d", 0);
-       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
+       g_snprintf(label_string, sizeof(label_string), "%d", 0);
+       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
        layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string);
        pango_layout_get_pixel_size(layout, &label_width, &label_height);
 
-#endif
-
        if (u_data->io->x1_tmp_usec==0)
                sec=u_data->io->x1_tmp_sec;
        else
@@ -463,16 +657,9 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
 
        if (u_data->io->offset!=0)
        {
-               g_snprintf(label_string, 15, "%u", u_data->io->x1_tmp_sec);
+               g_snprintf(label_string, sizeof(label_string), "%u", u_data->io->x1_tmp_sec);
 
-#if GTK_MAJOR_VERSION < 2
-               lwidth=gdk_string_width(font, label_string);
-               gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
-                               LEFT_BORDER-25,
-                               u_data->io->pixmap_height-BOTTOM_BORDER+20,
-                               label_string);
-#else
-               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
+               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
                pango_layout_set_text(layout, label_string, -1);
                pango_layout_get_pixel_size(layout, &lwidth, NULL);
 
@@ -480,14 +667,13 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                                LEFT_BORDER-25,
                                u_data->io->pixmap_height-BOTTOM_BORDER+20,
                                layout);
-#endif
        }
 
        w=(guint32)(500/(guint32)(distance*u_data->io->x_interval)); /*there will be a label for every w_th tic*/
 
        if (w==0)
                w=1;
-       
+
        if (w==4 || w==3 || w==2)
        {
                w=5;
@@ -499,9 +685,9 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                a=distance/5;
                b=0;
        }
-       
 
-       if (!u_data->io->uoff)  
+
+       if (!u_data->io->uoff)
        {
                if (a>=1000000)
                {
@@ -524,7 +710,7 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                if (start%2!=0)
                        start--;
                b = 0;
-               
+
        }
 
        for (i=start, j=b; i<=u_data->io->max_x; i+=a, j++)
@@ -533,26 +719,17 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                if (i>=u_data->io->min_x && i%1000000!=0)
                {
                        length=5;
-                       g_snprintf(label_string, 15, "%d", i%1000000);
+                       g_snprintf(label_string, sizeof(label_string), "%d", i%1000000);
                        if (j%w==0)
                        {
                                length=10;
-
-                               #if GTK_MAJOR_VERSION < 2
-                                       lwidth=gdk_string_width(font, label_string);
-                                       gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
-                                               (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-lwidth/2),
-                                               u_data->io->pixmap_height-BOTTOM_BORDER+10,
-                                               label_string);
-                               #else
-                                       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
-                                       pango_layout_set_text(layout, label_string, -1);
-                                       pango_layout_get_pixel_size(layout, &lwidth, NULL);
-                                       gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
-                                               (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-lwidth/2),
-                                               u_data->io->pixmap_height-BOTTOM_BORDER+10,
-                                               layout);
-                               #endif
+                               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
+                               pango_layout_set_text(layout, label_string, -1);
+                               pango_layout_get_pixel_size(layout, &lwidth, NULL);
+                               gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
+                                       (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-lwidth/2),
+                                       u_data->io->pixmap_height-BOTTOM_BORDER+10,
+                                       layout);
                        }
                        gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
                                (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
@@ -580,45 +757,28 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                if (write_label)
                {
                        gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
-                       (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
-                       u_data->io->pixmap_height-BOTTOM_BORDER,
-                       (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
-                       u_data->io->pixmap_height-BOTTOM_BORDER+10);
-
-                       g_snprintf(label_string, 15, "%d", sec);
-                       #if GTK_MAJOR_VERSION < 2
-                               lwidth=gdk_string_width(font, label_string);
-                               gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
-                                       (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-10),
-                                       u_data->io->pixmap_height-BOTTOM_BORDER+20,
-                                       label_string);
-                       #else
-                               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
-                               pango_layout_set_text(layout, label_string, -1);
-                               pango_layout_get_pixel_size(layout, &lwidth, NULL);
+                                     (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
+                                     u_data->io->pixmap_height-BOTTOM_BORDER,
+                                     (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval),
+                                     u_data->io->pixmap_height-BOTTOM_BORDER+10);
 
-                               gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
-                               (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-10),
-                                       u_data->io->pixmap_height-BOTTOM_BORDER+20,
-                                       layout);
-                       #endif
+                       g_snprintf(label_string, sizeof(label_string), "%d", sec);
+                       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
+                       pango_layout_set_text(layout, label_string, -1);
+                       pango_layout_get_pixel_size(layout, &lwidth, NULL);
+
+                       gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
+                                       (guint32)(LEFT_BORDER+u_data->io->offset+(i-u_data->io->min_x)*u_data->io->x_interval-10),
+                                       u_data->io->pixmap_height-BOTTOM_BORDER+20,
+                                       layout);
                        write_label = FALSE;
                }
-               
+
        }
 
-       strcpy(label_string, "sec");
+       g_strlcpy(label_string, "sec", sizeof(label_string));
 
-#if GTK_MAJOR_VERSION < 2
-       lwidth=gdk_string_width(font, label_string);
-       gdk_draw_string(u_data->io->pixmap,
-                       font,
-                       u_data->io->draw_area->style->black_gc,
-                       u_data->io->pixmap_width-RIGHT_BORDER-10,
-                       u_data->io->pixmap_height-BOTTOM_BORDER+30,
-                       label_string);
-#else
-       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
+       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
        pango_layout_set_text(layout, label_string, -1);
        pango_layout_get_pixel_size(layout, &lwidth, NULL);
        gdk_draw_layout(u_data->io->pixmap,
@@ -626,7 +786,6 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                        u_data->io->pixmap_width-RIGHT_BORDER-10,
                        u_data->io->pixmap_height-BOTTOM_BORDER+30,
                        layout);
-#endif
 
        distance=5;
 
@@ -660,26 +819,18 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                        if (i>=u_data->io->min_y)
                        {
                                length=5;
-                               g_snprintf(label_string, 15, "%d", i);
+                               g_snprintf(label_string, sizeof(label_string), "%d", i);
                                if (i%distance==0 || (distance<=5 && u_data->io->y_interval>10))
                                {
                                        length=10;
 
-#if GTK_MAJOR_VERSION < 2
-                                               lwidth=gdk_string_width(font, label_string);
-                                               gdk_draw_string(u_data->io->pixmap,font,u_data->io->draw_area->style->black_gc,
-                                                               LEFT_BORDER-length-lwidth-5,
-                                                               (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval-POINT_SIZE),
-                                                               label_string);
-#else
-                                               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
-                                               pango_layout_set_text(layout, label_string, -1);
-                                               pango_layout_get_pixel_size(layout, &lwidth, NULL);
-                                               gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
-                                                               LEFT_BORDER-length-lwidth-5,
-                                                               (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval-POINT_SIZE),
-                                                               layout);
-#endif
+                                       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), sizeof(label_string));
+                                       pango_layout_set_text(layout, label_string, -1);
+                                       pango_layout_get_pixel_size(layout, &lwidth, NULL);
+                                       gdk_draw_layout(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,
+                                                       LEFT_BORDER-length-lwidth-5,
+                                                       (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval-POINT_SIZE),
+                                                       layout);
                                }
                                gdk_draw_line(u_data->io->pixmap,u_data->io->draw_area->style->black_gc,LEFT_BORDER-length,
                                              (guint32)(u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-(i-u_data->io->min_y)*u_data->io->y_interval),
@@ -692,8 +843,29 @@ static void sctp_graph_draw(struct sctp_udata *u_data)
                simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No Data Chunks sent");
 }
 
+/* This function is used to change the title
+ * in the graph dialogue to NR_SACK or SACK based on the
+ * association
+ * If an association has both SAKC and NR_SACK PDU's
+ * a warning is popped
+ */
+static void
+updateLabels(void)
+{
+       if (gIsSackChunkPresent && gIsNRSackChunkPresent)
+       {
+               simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "This data set contains both SACK and NR SACK PDUs.");
+               gtk_button_set_label( (GtkButton*) sack_bt, "Show both Sack and NR Sack");
+       }
+       else if (gIsSackChunkPresent)
+               gtk_button_set_label( (GtkButton*) sack_bt, "Show Only Sack");
+       else
+               /* gIsNRSackChunkPresent will be true here */
+               gtk_button_set_label( (GtkButton*) sack_bt, "Show Only NR Sack");
+}
 
-static void sctp_graph_redraw(struct sctp_udata *u_data)
+static void
+sctp_graph_redraw(struct sctp_udata *u_data)
 {
 sctp_graph_t *ios;
 
@@ -703,18 +875,36 @@ sctp_graph_t *ios;
        switch (u_data->io->graph_type)
        {
                case 0:
+                       /* Show both TSN and SACK information
+                        * Reset the global sack variable
+                        * for sack and nr sack cases
+                        */
+                       gIsSackChunkPresent = 0;
+                       gIsNRSackChunkPresent = 0;
                        draw_sack_graph(u_data);
+                       draw_nr_sack_graph(u_data);
                        draw_tsn_graph(u_data);
                        break;
                case 1:
+                       /* Show only TSN */
                        draw_tsn_graph(u_data);
                        break;
                case 2:
+                       /* Show only SACK information
+                        * Reset the global sack variable
+                        * for sack and nr sack cases
+                        */
+                       gIsSackChunkPresent = 0;
+                       gIsNRSackChunkPresent = 0;
                        draw_sack_graph(u_data);
+                       draw_nr_sack_graph(u_data);
                        break;
        }
-       ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
 
+       /* Updates the sack / nr sack buttons */
+       updateLabels();
+
+       ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
        if(!ios){
                exit(10);
        }
@@ -730,7 +920,8 @@ sctp_graph_t *ios;
 }
 
 
-static void on_sack_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
+static void
+on_sack_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
 {
 
        u_data = (struct sctp_udata *) u_data;
@@ -738,14 +929,16 @@ static void on_sack_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
        sctp_graph_redraw(u_data);
 }
 
-static void on_tsn_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
+static void
+on_tsn_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
 {
 
        u_data->io->graph_type=1;
        sctp_graph_redraw(u_data);
 }
 
-static void on_both_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
+static void
+on_both_bt(GtkWidget *widget _U_, struct sctp_udata *u_data)
 {
 
        u_data->io->graph_type=0;
@@ -799,7 +992,7 @@ expose_event(GtkWidget *widget, GdkEventExpose *event)
 {
        sctp_graph_t *ios;
 
-       ios=(sctp_graph_t *)OBJECT_GET_DATA(widget, "sctp_graph_t");
+       ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(widget), "sctp_graph_t");
        if(!ios){
                exit(10);
        }
@@ -851,7 +1044,7 @@ on_zoomin_bt (GtkWidget *widget _U_, struct sctp_udata *u_data)
 }
 
 static void
-zoomin_bt (struct sctp_udata *u_data)
+zoomin_bt_fcn (struct sctp_udata *u_data)
 {
        sctp_min_max_t *tmp_minmax;
 
@@ -876,7 +1069,7 @@ zoomin_bt (struct sctp_udata *u_data)
        u_data->io->rectangle_present=FALSE;
        gtk_widget_set_sensitive(zoomout_bt, TRUE);
        sctp_graph_redraw(u_data);
-       
+
 }
 
 
@@ -950,7 +1143,7 @@ on_button_press (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_udata
                                   (gint)floor(MIN(u_data->io->y_old,u_data->io->y_new)),
                                   (gint)floor(abs((long)(u_data->io->x_new-u_data->io->x_old))),
                                   (gint)floor(abs((long)(u_data->io->y_new-u_data->io->y_old))));
-               ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
+               ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 
                if(!ios){
                        exit(10);
@@ -981,37 +1174,21 @@ static gint
 on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_udata *u_data)
 {
        sctp_graph_t *ios;
-       guint32 helpx, helpy, x1_tmp, x2_tmp,  y_value, frame, tmpnum=0, count=0, tsnumber=0;
+       guint32 helpx, helpy, x1_tmp, x2_tmp,  y_value, t_size=0, s_size=0, i, y_tolerance;
        gint label_width, label_height;
-       gdouble x_value, position, tfirst, s_diff, t_diff;
+       gdouble x_value, position, s_diff=0, t_diff=0, x_tolerance=0.0001;
        gint lwidth;
        char label_string[30];
        GdkGC *text_color;
-       GList *tsnlist=NULL, *tlist=NULL, *sacklist=NULL;
-       tsn_t *tsn, *tmptsn, *tmpsack, *sack;
-       guint8 type;
-       gboolean sack_type = FALSE;
-
-       #if GTK_MAJOR_VERSION < 2
-               GdkFont *font;
-#else
-               PangoLayout  *layout;
-#endif
-
-#if GTK_MAJOR_VERSION < 2
-               font = u_data->io->draw_area->style->font;
-#endif
-
-#if GTK_MAJOR_VERSION < 2
-               label_width=gdk_string_width(font, label_string);
-               label_height=gdk_string_height(font, label_string);
-#else
-               g_snprintf(label_string, 15, "%d", 0);
-               memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
-               layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string);
-               pango_layout_get_pixel_size(layout, &label_width, &label_height);
+       GPtrArray *tsnlist = NULL, *sacklist=NULL;
+       struct tsn_sort *tsn, *sack=NULL;
+       gboolean sack_found = FALSE;
+       PangoLayout  *layout;
 
-#endif
+       g_snprintf(label_string, 15, "%d", 0);
+       memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
+       layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string);
+       pango_layout_get_pixel_size(layout, &label_width, &label_height);
 
        if (event->y>u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)
                event->y = u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset;
@@ -1028,7 +1205,7 @@ on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_uda
                                   u_data->io->rect_x_min, u_data->io->rect_y_min,
                                   u_data->io->rect_x_max - u_data->io->rect_x_min,
                                   u_data->io->rect_y_max - u_data->io->rect_y_min);
-               ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
+               ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 
                if(!ios){
                        exit(10);
@@ -1052,14 +1229,14 @@ on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_uda
                }
                if (u_data->io->uoff)
                {
-                       if (x2_tmp - x1_tmp <= 1500)                    
+                       if (x2_tmp - x1_tmp <= 1500)
                                u_data->io->uoff = FALSE;
                        u_data->io->x1_tmp_sec=(guint32)x1_tmp;
                        u_data->io->x1_tmp_usec=0;
                        u_data->io->x2_tmp_sec=(guint32)x2_tmp;
                        u_data->io->x2_tmp_usec=0;
                }
-               else 
+               else
                {
                        u_data->io->x1_tmp_sec=(guint32)x1_tmp/1000000;
                        u_data->io->x1_tmp_usec=x1_tmp%1000000;
@@ -1086,9 +1263,9 @@ on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_uda
                if (u_data->io->rectangle_present==TRUE)
                {
                        u_data->io->rectangle_present=FALSE;
-                       if (event->x >= u_data->io->rect_x_min && event->x <= u_data->io->rect_x_max && 
+                       if (event->x >= u_data->io->rect_x_min && event->x <= u_data->io->rect_x_max &&
                             event->y >= u_data->io->rect_y_min && event->y <= u_data->io->rect_y_max)
-                               zoomin_bt(u_data);
+                               zoomin_bt_fcn(u_data);
                        else
                        {
                                u_data->io->x1_tmp_sec = u_data->io->x1_akt_sec;
@@ -1105,115 +1282,67 @@ on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_uda
                }
                else
                {
-                       x_value = ((event->x-LEFT_BORDER-u_data->io->offset) * ((u_data->io->x2_tmp_sec+u_data->io->x2_tmp_usec/1000000.0)-(u_data->io->x1_tmp_sec+u_data->io->x1_tmp_usec/1000000.0)) / (u_data->io->pixmap_width-LEFT_BORDER-u_data->io->offset))+u_data->io->x1_tmp_sec+u_data->io->x1_tmp_usec/1000000.0;
-                       y_value = (gint)floor((u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-event->y) * (max_tsn - min_tsn) / (u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)) + min_tsn;
+                       x_value = ((event->x-LEFT_BORDER-u_data->io->offset) * ((u_data->io->x2_tmp_sec+u_data->io->x2_tmp_usec/1000000.0)-(u_data->io->x1_tmp_sec+u_data->io->x1_tmp_usec/1000000.0)) / (u_data->io->pixmap_width-LEFT_BORDER-RIGHT_BORDER-u_data->io->offset))+u_data->io->x1_tmp_sec+u_data->io->x1_tmp_usec/1000000.0;
+                       y_value = (gint)rint((u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset-event->y) * (max_tsn - min_tsn) / (u_data->io->pixmap_height-BOTTOM_BORDER-u_data->io->offset)) + min_tsn;
                        text_color = u_data->io->draw_area->style->black_gc;
 
                        if (u_data->dir == 1)
                        {
-                               tsnlist = g_list_last(u_data->assoc->tsn1);
-                               sacklist = g_list_last(u_data->assoc->sack1);
+                               tsnlist = u_data->assoc->sort_tsn1;
+                               t_size = u_data->assoc->n_data_chunks_ep1;
+                               sacklist = u_data->assoc->sort_sack1;
+                               s_size = u_data->assoc->n_sack_chunks_ep1;
                        }
                        else
                        {
-                               tsnlist = g_list_last(u_data->assoc->tsn2);
-                               sacklist = g_list_last(u_data->assoc->sack2);
+                               tsnlist = u_data->assoc->sort_tsn2;
+                               t_size = u_data->assoc->n_data_chunks_ep2;
+                               sacklist = u_data->assoc->sort_sack2;
+                               s_size = u_data->assoc->n_sack_chunks_ep2;
                        }
-
-                       tsn = (tsn_t*) (tsnlist->data);
-                       tmptsn =(tsn_t*)(tsnlist->data);
-                       tfirst = tsn->secs + tsn->usecs/1000000.0;
-                       frame = tsn->frame_number;
-                       
-                       while (tsnlist)
+                       x_tolerance = (gdouble)((u_data->io->tmp_width / u_data->io->axis_width*1.0))*5/1000000.0;
+                       y_tolerance = (guint32)(((u_data->io->max_y - u_data->io->min_y) / (u_data->io->pixmap_height-TOP_BORDER-BOTTOM_BORDER-u_data->io->offset)) * 2.0);
+                       if (y_tolerance==0)
+                               y_tolerance = 2;
+                       else if (y_tolerance > 5)
+                               y_tolerance = 5;
+
+                       for (i=0; i<s_size; i++)
                        {
-                               tsnlist = g_list_previous(tsnlist);
-                               tsn = (tsn_t*) (tsnlist->data);
-                               if (tsn->secs+tsn->usecs/1000000.0<x_value)
-                               {
-                                       tfirst = tsn->secs+tsn->usecs/1000000.0;
-                                       tmptsn =tsn;
-                               }
-                               else
+                               sack = (struct tsn_sort*)(g_ptr_array_index(sacklist, i));
+                               if ((guint32)abs(sack->tsnumber - y_value)<y_tolerance)
                                {
-                                       if ((tfirst+tsn->secs+tsn->usecs/1000000.0)/2.0<x_value)
-                                       {
-                                               t_diff = tsn->secs+tsn->usecs/1000000.0 - x_value;
-                                               tmptsn = tsn;
-                                       }
-                                       else
-                                               t_diff = x_value - tmptsn->secs+tmptsn->usecs/1000000.0;
+                                       s_diff = fabs((sack->secs+sack->usecs/1000000.0)- x_value);
+                                       if (s_diff < x_tolerance)
+                                               sack_found = TRUE;
                                        break;
                                }
                        }
-                       sack = (tsn_t*) (sacklist->data);
-                       tmpsack =(tsn_t*)(sacklist->data);
-                       tfirst = sack->secs + sack->usecs/1000000.0;
-                       
-                       while (sacklist)
-                       {
-                               sacklist = g_list_previous(sacklist);
-                               sack = (tsn_t*) (sacklist->data);
-                               if (sack->secs+sack->usecs/1000000.0<x_value)
-                               {
-                                       tfirst = sack->secs+sack->usecs/1000000.0;
-                                       tmpsack =sack;
-                               }
-                               else
-                               {
-                                       if ((tfirst+sack->secs+sack->usecs/1000000.0)/2.0<x_value)
-                                       {
-                                               s_diff = sack->secs+sack->usecs/1000000.0 - x_value;
-                                               tmpsack = sack;
-                                       }
-                                       else
-                                               s_diff = x_value - tmpsack->secs+tmpsack->usecs/1000000.0;
-                                       break;
-                               }
-                       }
-                       if (s_diff < t_diff)
-                       {
-                               cf_goto_frame(&cfile, tmpsack->frame_number);
-                               x_value = tmpsack->secs+tmpsack->usecs/1000000.0;
-                               tlist = g_list_first(tmpsack->tsns);
-                               sack_type = TRUE;
-                       }
-                       else
-                       {
-                               cf_goto_frame(&cfile, tmptsn->frame_number);
-                               x_value = tmptsn->secs+tmptsn->usecs/1000000.0;
-                               tlist = g_list_first(tmptsn->tsns);
-                               sack_type = FALSE;
-                       }
-                       count++;
-                       while (tlist)
+
+                       for (i=0; i<t_size; i++)
                        {
-                               type = ((struct chunk_header *)tlist->data)->type;
-                               if (type == SCTP_DATA_CHUNK_ID && !sack_type)
-                                       tsnumber = g_ntohl(((struct data_chunk_header *)tlist->data)->tsn);
-                               else if (type == SCTP_SACK_CHUNK_ID && sack_type)
-                                       tsnumber = g_ntohl(((struct sack_chunk_header *)tlist->data)->cum_tsn_ack);
-                               if (tsnumber < y_value && g_list_length(tlist)-count>0)
-                               {
-                                       tmpnum = tsnumber;
-                               }
-                               else
+                               tsn = (struct tsn_sort*)(g_ptr_array_index(tsnlist, i));
+                               if ((guint32)abs(tsn->tsnumber - y_value)<y_tolerance)
                                {
-                                       if ((tmpnum+tsnumber)/2 < y_value)
+                                       t_diff = fabs((tsn->secs+tsn->usecs/1000000.0)- x_value);
+                                       if (sack_found && s_diff < t_diff)
                                        {
-                                               y_value = tsnumber;
-                                               tmpnum = tsnumber;
+                                               cf_goto_frame(&cfile, sack->framenumber);
+                                               x_value = sack->secs+sack->usecs/1000000.0;
+                                               y_value = sack->tsnumber;
                                        }
-                                       else
+                                       else if (t_diff < x_tolerance)
                                        {
-                                               y_value = tmpnum;
+                                               cf_goto_frame(&cfile, tsn->framenumber);
+                                               x_value = tsn->secs+tsn->usecs/1000000.0;
+                                               y_value = tsn->tsnumber;
                                        }
                                        break;
                                }
-                               tlist = g_list_next(tlist);
-                               count++;
                        }
-                       g_snprintf(label_string, 30, "(%.6lf, %u)", x_value, y_value);
+
+                       g_snprintf(label_string, sizeof(label_string), "(%.6lf, %u)", x_value, y_value);
+
                        label_set = TRUE;
 
                        gdk_draw_line(u_data->io->pixmap,text_color, (gint)(event->x-2), (gint)(event->y), (gint)(event->x+2), (gint)(event->y));
@@ -1224,55 +1353,44 @@ on_button_release (GtkWidget *widget _U_, GdkEventButton *event, struct sctp_uda
                                position = event->x + 5;
 
 
-#if GTK_MAJOR_VERSION < 2
-                       lwidth=gdk_string_width(font, label_string);
-                                           gdk_draw_string(u_data->io->pixmap,font,text_color,
-                                           (gint)position,
-                                           (gint)(event->y-10),
-                                           label_string);
-#else
                        memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
                        pango_layout_set_text(layout, label_string, -1);
                        pango_layout_get_pixel_size(layout, &lwidth, NULL);
 
                        gdk_draw_layout(u_data->io->pixmap,text_color,
-                                           (gint)position,
-                                           (gint)(event->y-10),
-                                           layout);
-       #endif
+                                       (gint)position,
+                                       (gint)(event->y-10),
+                                       layout);
 
-
-
-                       ios=(sctp_graph_t *)OBJECT_GET_DATA(u_data->io->draw_area, "sctp_graph_t");
+                       ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 
                        if(!ios){
                                exit(10);
                        }
                        gdk_draw_pixmap(u_data->io->draw_area->window,
-                                   u_data->io->draw_area->style->fg_gc[GTK_WIDGET_STATE(u_data->io->draw_area)],
-                                   ios->pixmap,
-                                   0, 0,
-                                   0, 0,
-                                   u_data->io->draw_area->allocation.width,
-                                   u_data->io->draw_area->allocation.height);
+                                       u_data->io->draw_area->style->fg_gc[GTK_WIDGET_STATE(u_data->io->draw_area)],
+                                       ios->pixmap,
+                                       0, 0,
+                                       0, 0,
+                                       u_data->io->draw_area->allocation.width,
+                                       u_data->io->draw_area->allocation.height);
                }
        }
        return TRUE;
 }
 
 
-static void init_sctp_graph_window(struct sctp_udata *u_data)
+static void
+init_sctp_graph_window(struct sctp_udata *u_data)
 {
        GtkWidget *vbox;
        GtkWidget *hbox;
-       GtkWidget *bt_close, *sack_bt, *tsn_bt, *both_bt, *zoomin_bt;
+       GtkWidget *bt_close, *tsn_bt, *both_bt, *zoomin_bt;
        GtkTooltips *tooltip_in, *tooltip_out;
 
        /* create the main window */
-
-       u_data->io->window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
-       gtk_widget_set_name(u_data->io->window, "SCTP Graphics");
+       u_data->io->window= dlg_window_new("WSCTP Graphics");  /* transient_for top_level */
+       gtk_window_set_destroy_with_parent (GTK_WINDOW(u_data->io->window), TRUE);
 
        vbox=gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(u_data->io->window), vbox);
@@ -1286,54 +1404,53 @@ static void init_sctp_graph_window(struct sctp_udata *u_data)
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
        gtk_button_box_set_layout(GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
-       gtk_button_box_set_spacing(GTK_BUTTON_BOX (hbox), 0);
+       gtk_box_set_spacing(GTK_BOX (hbox), 0);
        gtk_box_set_child_packing(GTK_BOX(vbox), hbox, FALSE, FALSE, 0, GTK_PACK_START);
        gtk_widget_show(hbox);
-
-       sack_bt = gtk_button_new_with_label ("Show Sacks");
+       sack_bt = gtk_button_new_with_label ("Show Only Sacks");
        gtk_box_pack_start(GTK_BOX(hbox), sack_bt, FALSE, FALSE, 0);
        gtk_widget_show(sack_bt);
 
-       gtk_signal_connect(GTK_OBJECT(sack_bt), "clicked", (GtkSignalFunc)on_sack_bt, u_data);
-
-       tsn_bt = gtk_button_new_with_label ("Show TSNs");
+       g_signal_connect(sack_bt, "clicked", G_CALLBACK(on_sack_bt), u_data);
+       tsn_bt = gtk_button_new_with_label ("Show Only TSNs");
        gtk_box_pack_start(GTK_BOX(hbox), tsn_bt, FALSE, FALSE, 0);
        gtk_widget_show(tsn_bt);
-       SIGNAL_CONNECT(tsn_bt, "clicked", on_tsn_bt, u_data);
+       g_signal_connect(tsn_bt, "clicked", G_CALLBACK(on_tsn_bt), u_data);
 
        both_bt = gtk_button_new_with_label ("Show both");
        gtk_box_pack_start(GTK_BOX(hbox), both_bt, FALSE, FALSE, 0);
        gtk_widget_show(both_bt);
-       SIGNAL_CONNECT(both_bt, "clicked", on_both_bt, u_data);
+       g_signal_connect(both_bt, "clicked", G_CALLBACK(on_both_bt), u_data);
 
        zoomin_bt = gtk_button_new_with_label ("Zoom in");
        gtk_box_pack_start(GTK_BOX(hbox), zoomin_bt, FALSE, FALSE, 0);
        gtk_widget_show(zoomin_bt);
-       SIGNAL_CONNECT(zoomin_bt, "clicked", on_zoomin_bt, u_data);
+       g_signal_connect(zoomin_bt, "clicked", G_CALLBACK(on_zoomin_bt), u_data);
        tooltip_in = gtk_tooltips_new();
        gtk_tooltips_set_tip(tooltip_in, zoomin_bt, "Zoom in the area you have selected", NULL);
 
        zoomout_bt = gtk_button_new_with_label ("Zoom out");
        gtk_box_pack_start(GTK_BOX(hbox), zoomout_bt, FALSE, FALSE, 0);
        gtk_widget_show(zoomout_bt);
-       SIGNAL_CONNECT(zoomout_bt, "clicked", on_zoomout_bt, u_data);
+       g_signal_connect(zoomout_bt, "clicked", G_CALLBACK(on_zoomout_bt), u_data);
        tooltip_out = gtk_tooltips_new();
        gtk_tooltips_set_tip(tooltip_out, zoomout_bt, "Zoom out one step", NULL);
        gtk_widget_set_sensitive(zoomout_bt, FALSE);
 
-       bt_close = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
+       bt_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
        gtk_box_pack_start(GTK_BOX(hbox), bt_close, FALSE, FALSE, 0);
        gtk_widget_show(bt_close);
-       SIGNAL_CONNECT(bt_close, "clicked", sctp_graph_close_cb, u_data);
+       g_signal_connect(bt_close, "clicked", G_CALLBACK(sctp_graph_close_cb), u_data);
 
-       gtk_signal_connect(GTK_OBJECT(u_data->io->draw_area),"button_press_event",(GtkSignalFunc)on_button_press, u_data);
-       gtk_signal_connect(GTK_OBJECT(u_data->io->draw_area),"button_release_event",(GtkSignalFunc)on_button_release, u_data);
+       g_signal_connect(u_data->io->draw_area,"button_press_event",G_CALLBACK(on_button_press), u_data);
+       g_signal_connect(u_data->io->draw_area,"button_release_event",G_CALLBACK(on_button_release), u_data);
        gtk_widget_set_events(u_data->io->draw_area, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXPOSURE_MASK);
 
        gtk_widget_show(u_data->io->window);
 }
 
-static void sctp_graph_set_title(struct sctp_udata *u_data)
+static void
+sctp_graph_set_title(struct sctp_udata *u_data)
 {
        char *title;
 
@@ -1409,18 +1526,19 @@ quit(GtkObject *object _U_, gpointer user_data)
 }
 
 
-static void create_draw_area(GtkWidget *box, struct sctp_udata *u_data)
+static void
+create_draw_area(GtkWidget *box, struct sctp_udata *u_data)
 {
 
        u_data->io->draw_area=gtk_drawing_area_new();
-       SIGNAL_CONNECT(u_data->io->draw_area, "destroy", quit, u_data);
-       OBJECT_SET_DATA(u_data->io->draw_area, "sctp_graph_t", u_data->io);
+       g_signal_connect(u_data->io->draw_area, "destroy", G_CALLBACK(quit), u_data);
+       g_object_set_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t", u_data->io);
 
-       WIDGET_SET_SIZE(u_data->io->draw_area, u_data->io->pixmap_width, u_data->io->pixmap_height);
+       gtk_widget_set_size_request(u_data->io->draw_area, u_data->io->pixmap_width, u_data->io->pixmap_height);
 
        /* signals needed to handle backing pixmap */
-       SIGNAL_CONNECT(u_data->io->draw_area, "expose_event", expose_event, NULL);
-       SIGNAL_CONNECT(u_data->io->draw_area, "configure_event", configure_event, u_data);
+       g_signal_connect(u_data->io->draw_area, "expose_event", G_CALLBACK(expose_event), NULL);
+       g_signal_connect(u_data->io->draw_area, "configure_event", G_CALLBACK(configure_event), u_data);
 
        gtk_widget_show(u_data->io->draw_area);
        gtk_box_pack_start(GTK_BOX(box), u_data->io->draw_area, TRUE, TRUE, 0);
@@ -1428,7 +1546,8 @@ static void create_draw_area(GtkWidget *box, struct sctp_udata *u_data)
 
 
 
-void create_graph(guint16 dir, struct sctp_analyse* userdata)
+void
+create_graph(guint16 dir, struct sctp_analyse* userdata)
 {
        struct sctp_udata *u_data;
 
@@ -1447,3 +1566,20 @@ void create_graph(guint16 dir, struct sctp_analyse* userdata)
                gtk_sctpgraph_init(u_data);
        }
 }
+
+#if defined(_WIN32) && !defined(__MINGW32__)
+/* replacement of Unix rint() for Windows */
+static int
+rint (double x)
+{
+       char *buf;
+       int i,dec,sig;
+
+       buf = _fcvt(x, 0, &dec, &sig);
+       i = atoi(buf);
+       if(sig == 1) {
+               i = i * -1;
+       }
+       return(i);
+}
+#endif