2 * TCP graph drawing code
3 * By Pavel Mores <pvl@uh.cz>
4 * Win32 port: rwh@unifiedtech.com
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <gdk/gdkkeysyms.h>
33 #include <math.h> /* rint() */
36 #include <epan/ipproto.h>
37 #include "globals.h" /* cfile */
38 #include <epan/packet.h> /* frame_data */
39 #include "gtkglobals.h" /* packet_list */
40 #include "simple_dialog.h"
41 #include "gui_utils.h"
43 #include "compat_macros.h"
44 #include <epan/etypes.h>
45 #include <epan/ppptypes.h>
46 #include "dlg_utils.h"
47 #include <epan/epan_dissect.h>
48 #include "../stat_menu.h"
49 #include "gui_stat_menu.h"
50 #include <epan/dissectors/packet-tcp.h>
51 #include <epan/address.h>
61 #define TCP_SYN(flags) ( flags & TH_SYN )
62 #define TCP_ACK(flags) ( flags & TH_ACK )
65 #define TXT_HEIGHT 550
67 /* for compare_headers() */
68 /* segment went the same direction as the currently selected one */
69 #define COMPARE_CURR_DIR 0
70 #define COMPARE_ANY_DIR 1
72 /* initalize_axis() */
73 #define AXIS_HORIZONTAL 0
74 #define AXIS_VERTICAL 1
88 guint32 th_win; /* make it 32 bits so we can handle some scaling */
97 double x, y, width, height;
101 double x1, y1, x2, y2;
105 int x, y, width, height;
137 struct segment *parent;
139 struct arc_params arc;
140 struct rect_params rect;
141 struct line_params line;
145 struct element_list {
146 struct element_list *next;
147 struct element *elements;
151 struct graph *g; /* which graph we belong to */
152 GtkWidget *drawing_area;
153 GdkPixmap *pixmap[2];
155 #define AXIS_ORIENTATION 1 << 0
157 /* dim and orig (relative to origin of window) of axis' pixmap */
159 /* dim and orig (relative to origin of axis' pixmap) of scale itself */
162 gdouble major, minor; /* major and minor ticks */
166 #define HAXIS_INIT_HEIGHT 70
167 #define VAXIS_INIT_WIDTH 100
168 #define TITLEBAR_HEIGHT 50
169 #define RMARGIN_WIDTH 30
171 struct style_tseq_tcptrace {
177 struct style_tseq_stevens {
195 #define SEQ_ORIGIN 0x1
196 /* show absolute sequence numbers (not differences from isn) */
197 #define SEQ_ORIGIN_ZERO 0x1
198 #define SEQ_ORIGIN_ISN 0x0
199 #define TIME_ORIGIN 0x10
200 /* show time from beginning of capture as opposed to time from beginning
201 * of the connection */
202 #define TIME_ORIGIN_CAP 0x10
203 #define TIME_ORIGIN_CONN 0x0
205 /* this is used by rtt module only */
214 int draw; /* indicates whether we should draw cross at all */
216 GtkToggleButton *on_toggle;
217 GtkToggleButton *off_toggle;
221 double x0, y0, width, height;
230 double step_x, step_y;
232 #define ZOOM_OUT (1 << 0)
233 #define ZOOM_HLOCK (1 << 1)
234 #define ZOOM_VLOCK (1 << 2)
235 #define ZOOM_STEPS_SAME (1 << 3)
236 #define ZOOM_STEPS_KEEP_RATIO (1 << 4)
238 /* unfortunately, we need them both because gtk_toggle_button_set_active ()
239 * with second argument FALSE doesn't do anything, somehow */
241 GtkToggleButton *in_toggle;
242 GtkToggleButton *out_toggle;
245 GtkSpinButton *h_step;
246 GtkSpinButton *v_step;
258 struct ipoint offset;
262 #define MAGZOOMS_SAME (1 << 0)
263 #define MAGZOOMS_SAME_RATIO (1 << 1)
264 #define MAGZOOMS_IGNORE (1 << 31)
267 GtkSpinButton *h_zoom, *v_zoom;
273 #define GRAPH_TSEQ_STEVENS 0
274 #define GRAPH_TSEQ_TCPTRACE 1
275 #define GRAPH_THROUGHPUT 2
278 #define GRAPH_DESTROYED (1 << 0)
279 #define GRAPH_INIT_ON_TYPE_CHANGE (1 << 1)
281 GtkWidget *toplevel; /* keypress handler needs this */
282 GtkWidget *drawing_area;
283 GtkWidget *text; /* text widget for seg list - probably
285 FONT_TYPE *font; /* font used for annotations etc. */
288 GdkPixmap *title_pixmap;
289 GdkPixmap *pixmap[2];
290 int displayed; /* which of both pixmaps is on screen right now */
292 GtkWidget *control_panel;
293 /* this belongs to style structs of graph types that make use of it */
294 GtkToggleButton *time_orig_conn, *seq_orig_isn;
297 /* Next 4 attribs describe the graph in natural units, before any scaling.
298 * For example, if we want to display graph of TCP conversation that
299 * started 112.309845 s after beginning of the capture and ran until
300 * 479.093582 s, 237019 B went through the connection (in one direction)
301 * starting with isn 31934022, then (bounds.x0, bounds.y0)=(112.309845,
302 * 31934022) and (bounds.width, bounds.height)=(366.783737, 237019). */
303 struct bounds bounds;
304 /* dimensions and position of the graph, both expressed already in pixels.
305 * x and y give the position of upper left corner of the graph relative
306 * to origin of the graph window, size is basically bounds*zoom */
308 /* viewport (=graph window area which is reserved for graph itself), its
309 * size and position relative to origin of the graph window */
312 /* If we need to display 237019 sequence numbers (=bytes) onto say 500
313 * pixels, we have to scale the graph down by factor of 0.002109. This
314 * number would be zoom.y. Obviously, both directions have separate zooms.*/
317 struct magnify magnify;
318 struct axis *x_axis, *y_axis;
319 struct segment *segments;
320 struct segment *current;
321 struct element_list *elists; /* element lists */
323 struct style_tseq_stevens tseq_stevens;
324 struct style_tseq_tcptrace tseq_tcptrace;
325 struct style_tput tput;
326 struct style_rtt rtt;
330 static struct graph *graphs = NULL;
331 static GdkGC *xor_gc = NULL;
334 #define debug(section) if (debugging & section)
335 /* print function entry points */
336 #define DBS_FENTRY (1 << 0)
337 #define DBS_AXES_TICKS (1 << 1)
338 #define DBS_AXES_DRAWING (1 << 2)
339 #define DBS_GRAPH_DRAWING (1 << 3)
340 #define DBS_TPUT_ELMTS (1 << 4)
341 /*int debugging = DBS_FENTRY;*/
343 /*int debugging = DBS_AXES_TICKS;*/
344 /*int debugging = DBS_AXES_DRAWING;*/
345 /*int debugging = DBS_GRAPH_DRAWING;*/
346 /*int debugging = DBS_TPUT_ELMTS;*/
348 static void create_gui (struct graph * );
350 static void create_text_widget (struct graph * );
351 static void display_text (struct graph * );
353 static void create_drawing_area (struct graph * );
354 static void control_panel_create (struct graph * );
355 static GtkWidget *control_panel_create_zoom_group (struct graph * );
356 static GtkWidget *control_panel_create_magnify_group (struct graph * );
357 static GtkWidget *control_panel_create_cross_group (struct graph * );
358 static GtkWidget *control_panel_create_zoomlock_group (struct graph * );
359 static GtkWidget *control_panel_create_graph_type_group (struct graph * );
360 static void control_panel_add_zoom_page (struct graph * , GtkWidget * );
361 static void control_panel_add_magnify_page (struct graph * , GtkWidget * );
362 static void control_panel_add_origin_page (struct graph * , GtkWidget * );
363 static void control_panel_add_cross_page (struct graph * , GtkWidget * );
364 static void control_panel_add_graph_type_page (struct graph * , GtkWidget * );
365 static void callback_toplevel_destroy (GtkWidget * , gpointer );
366 static gboolean callback_delete_event(GtkWidget * , GdkEvent * , gpointer);
367 static void callback_close (GtkWidget * , gpointer );
368 static void callback_time_origin (GtkWidget * , gpointer );
369 static void callback_seq_origin (GtkWidget * , gpointer );
370 static void callback_zoomlock_h (GtkWidget * , gpointer );
371 static void callback_zoomlock_v (GtkWidget * , gpointer );
372 static void callback_zoom_inout (GtkWidget * , gpointer );
373 static void callback_zoom_step (GtkWidget * , gpointer );
374 static void callback_zoom_flags (GtkWidget * , gpointer );
375 static void callback_cross_on_off (GtkWidget * , gpointer );
376 static void callback_mag_width (GtkWidget * , gpointer );
377 static void callback_mag_height (GtkWidget * , gpointer );
378 static void callback_mag_x (GtkWidget * , gpointer );
379 static void callback_mag_y (GtkWidget * , gpointer );
380 static void callback_mag_zoom (GtkWidget * , gpointer );
381 static void callback_mag_flags (GtkWidget * , gpointer );
382 static void callback_graph_type (GtkWidget * , gpointer );
383 static void callback_graph_init_on_typechg (GtkWidget * , gpointer );
384 static void callback_create_help (GtkWidget * , gpointer );
385 static void update_zoom_spins (struct graph * );
386 static struct tcpheader *select_tcpip_session (capture_file *, struct segment * );
387 static int compare_headers (address *saddr1, address *daddr1, guint16 sport1, guint16 dport1, address *saddr2, address *daddr2, guint16 sport2, guint16 dport2, int dir);
388 static int get_num_dsegs (struct graph * );
389 static int get_num_acks (struct graph * );
390 static void graph_type_dependent_initialize (struct graph * );
391 static void graph_put (struct graph * );
392 static struct graph *graph_new (void);
393 static void graph_destroy (struct graph * );
394 static void graph_initialize_values (struct graph * );
395 static void graph_init_sequence (struct graph * );
396 static void draw_element_line (struct graph * , struct element * );
397 static void draw_element_arc (struct graph * , struct element * );
398 static void graph_display (struct graph * );
399 static void graph_pixmaps_create (struct graph * );
400 static void graph_pixmaps_switch (struct graph * );
401 static void graph_pixmap_draw (struct graph * );
402 static void graph_pixmap_display (struct graph * );
403 static void graph_element_lists_make (struct graph * );
404 static void graph_element_lists_free (struct graph * );
405 static void graph_element_lists_initialize (struct graph * );
406 static void graph_title_pixmap_create (struct graph * );
407 static void graph_title_pixmap_draw (struct graph * );
408 static void graph_title_pixmap_display (struct graph * );
409 static void graph_segment_list_get (struct graph * );
410 static void graph_segment_list_free (struct graph * );
411 static void graph_select_segment (struct graph * , int , int );
412 static int line_detect_collision (struct element * , int , int );
413 static int arc_detect_collision (struct element * , int , int );
414 static void axis_pixmaps_create (struct axis * );
415 static void axis_pixmaps_switch (struct axis * );
416 static void axis_display (struct axis * );
417 static void v_axis_pixmap_draw (struct axis * );
418 static void h_axis_pixmap_draw (struct axis * );
419 static void axis_pixmap_display (struct axis * );
420 static void axis_compute_ticks (struct axis * , double , double , int );
421 static double axis_zoom_get (struct axis * , int );
422 static void axis_ticks_up (int * , int * );
423 static void axis_ticks_down (int * , int * );
424 static void axis_destroy (struct axis * );
425 static int get_label_dim (struct axis * , int , double );
426 static void toggle_time_origin (struct graph * );
427 static void toggle_seq_origin (struct graph * );
428 static void cross_xor (struct graph * , int , int );
429 static void cross_draw (struct graph * , int , int );
430 static void cross_erase (struct graph * );
431 static void magnify_create (struct graph * , int , int );
432 static void magnify_move (struct graph * , int , int );
433 static void magnify_destroy (struct graph * );
434 static void magnify_draw (struct graph * );
435 static void magnify_get_geom (struct graph * , int , int );
436 static gint configure_event (GtkWidget * , GdkEventConfigure * );
437 static gint expose_event (GtkWidget * , GdkEventExpose * );
438 static gint button_press_event (GtkWidget * , GdkEventButton * );
439 static gint button_release_event (GtkWidget * , GdkEventButton * );
440 static gint motion_notify_event (GtkWidget * , GdkEventMotion * );
441 static gint key_press_event (GtkWidget * , GdkEventKey * );
442 static gint key_release_event (GtkWidget * , GdkEventKey * );
443 static gint leave_notify_event (GtkWidget * , GdkEventCrossing * );
444 static gint enter_notify_event (GtkWidget * , GdkEventCrossing * );
445 static void tseq_stevens_initialize (struct graph * );
446 static void tseq_stevens_get_bounds (struct graph * );
447 static void tseq_stevens_read_config (struct graph * );
448 static void tseq_stevens_make_elmtlist (struct graph * );
449 static void tseq_stevens_toggle_seq_origin (struct graph * );
450 static void tseq_stevens_toggle_time_origin (struct graph * );
451 static void tseq_tcptrace_read_config (struct graph * );
452 static void tseq_tcptrace_make_elmtlist (struct graph * );
453 static void tseq_tcptrace_toggle_seq_origin (struct graph * );
454 static void tseq_tcptrace_toggle_time_origin (struct graph * );
455 static void tput_initialize (struct graph * );
456 static void tput_read_config (struct graph * );
457 static void tput_make_elmtlist (struct graph * );
458 static void tput_toggle_time_origin (struct graph * );
459 static void rtt_read_config (struct graph * );
460 static void rtt_initialize (struct graph * );
461 static int rtt_is_retrans (struct unack * , unsigned int );
462 static struct unack *rtt_get_new_unack (double , unsigned int );
463 static void rtt_put_unack_on_list (struct unack ** , struct unack * );
464 static void rtt_delete_unack_from_list (struct unack ** , struct unack * );
465 static void rtt_make_elmtlist (struct graph * );
466 static void rtt_toggle_seq_origin (struct graph * );
467 #if defined(_WIN32) && !defined(__MINGW32__)
468 static int rint (double ); /* compiler template for Windows */
471 /* XXX - what about OS X? */
472 static char helptext[] =
474 "Here's what you can do:\n\
475 - Left Mouse Button selects segment in ethereal's packet list\n\
476 - Middle Mouse Button zooms in\n\
477 - <shift>-Middle Button zooms out\n\
478 - Right Mouse Button moves the graph (if zoomed in)\n\
479 - <ctrl>-Right Mouse Button displays a portion of graph magnified\n\
480 - Space toggles crosshairs\n\
481 - 's' toggles relative/absolute sequence numbers\n\
482 - 't' toggles time origin\n\
485 "Here's what you can do:\n\
486 - <ctrl>-Left Mouse Button selects segment in ethereal's packet list\n\
487 - Left Mouse Button zooms in\n\
488 - <shift>-Left Mouse Button zooms out\n\
489 - Right Mouse Button moves the graph (if zoomed in)\n\
490 - <ctrl>-Right Mouse Button displays a portion of graph magnified\n\
492 - Space bar toggles crosshairs\n\
493 - 's' - Toggles relative/absolute sequence numbers\n\
494 - 't' - Toggles time origin\n\
498 static void tcp_graph_cb (GtkWidget *w _U_, gpointer data, guint callback_action /*graph_type*/ _U_)
500 struct segment current;
502 struct tcpheader *thdr;
504 guint graph_type = GPOINTER_TO_INT(data);
506 debug(DBS_FENTRY) puts ("tcp_graph_cb()");
508 if (! (g = graph_new()))
512 graph_initialize_values (g);
515 g->type = graph_type;
516 if (!(thdr=select_tcpip_session (&cfile, ¤t))) {
520 graph_segment_list_get(g);
522 /* display_text(g); */
523 graph_init_sequence(g);
526 static void create_gui (struct graph *g)
528 debug(DBS_FENTRY) puts ("create_gui()");
529 /* create_text_widget(g); */
530 control_panel_create (g);
531 create_drawing_area(g);
535 static void create_text_widget (struct graph *g)
537 GtkWidget *streamwindow, *txt_scrollw, *box;
539 debug(DBS_FENTRY) puts ("create_text_widget()");
540 streamwindow = dlg_window_new ("Ethereal: Packet chain");
541 gtk_widget_set_name (streamwindow, "Packet chain");
542 WIDGET_SET_SIZE(streamwindow, TXT_WIDTH, TXT_HEIGHT);
543 gtk_container_border_width (GTK_CONTAINER(streamwindow), 2);
545 box = gtk_vbox_new (FALSE, 0);
546 gtk_container_add (GTK_CONTAINER (streamwindow), box);
547 gtk_widget_show (box);
549 txt_scrollw = scrolled_window_new (NULL, NULL);
550 #if GTK_MAJOR_VERSION >= 2
551 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
554 gtk_box_pack_start (GTK_BOX (box), txt_scrollw, TRUE, TRUE, 0);
555 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (txt_scrollw),
556 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
557 gtk_widget_show (txt_scrollw);
559 #if GTK_MAJOR_VERSION < 2
560 g->text = gtk_text_new(NULL, NULL);
561 gtk_text_set_editable(GTK_TEXT(g->text), FALSE);
563 g->text = gtk_text_view_new();
564 gtk_text_view_set_editable(GTK_TEXT_VIEW(g->text), FALSE);
566 gtk_container_add (GTK_CONTAINER (txt_scrollw), g->text);
567 gtk_widget_show (g->text);
568 gtk_widget_show (streamwindow);
570 static void display_text (struct graph *g)
574 double first_time, prev_time;
575 unsigned int isn_this=0, isn_opposite=0, seq_this_prev, seq_opposite_prev;
577 #if GTK_MAJOR_VERSION >= 2
582 debug(DBS_FENTRY) puts ("display_text()");
583 if (!gdk_color_parse ("SlateGray", &color)) {
585 * XXX - do more than just warn.
587 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
588 "Could not parse color SlateGray.");
590 #if GTK_MAJOR_VERSION < 2
591 gtk_text_freeze (GTK_TEXT (g->text));
593 g_snprintf ((char * )line, 256, "%10s%15s%15s%15s%15s%15s%15s%10s\n",
594 "pkt num", "time", "delta first", "delta prev",
595 "seqno", "delta first", "delta prev", "data (B)");
596 gtk_text_insert (GTK_TEXT (g->text), g->font, NULL, NULL,
597 (const char *)line, -1);
599 first_time = g->segments->rel_secs + g->segments->rel_usecs/1000000.0;
600 prev_time = first_time;
601 /* we have to find Initial Sequence Number for both ends of connection */
602 for (ptr=g->segments; ptr; ptr=ptr->next) {
603 if (compare_headers (g->current, ptr, COMPARE_CURR_DIR)) {
604 isn_this = ptr->th_seq;
608 for (ptr=g->segments; ptr; ptr=ptr->next) {
609 if (!compare_headers (g->current, ptr, COMPARE_CURR_DIR)) {
610 isn_opposite = ptr->th_seq;
614 seq_this_prev = isn_this;
615 seq_opposite_prev = isn_opposite;
616 for (ptr=g->segments; ptr; ptr=ptr->next) {
617 double time=ptr->rel_secs + ptr->rel_usecs/1000000.0;
618 unsigned int seq = ptr->th_seq;
619 int seq_delta_isn, seq_delta_prev;
621 if (compare_headers (g->current, ptr, COMPARE_CURR_DIR)) {
622 seq_delta_isn = seq - isn_this;
623 seq_delta_prev = seq - seq_this_prev;
627 seq_delta_isn = seq - isn_opposite;
628 seq_delta_prev = seq - seq_opposite_prev;
629 seq_opposite_prev = seq;
632 g_snprintf ((char *)line, 256, "%10d%15.6f%15.6f%15.6f%15u%15d%15d%10u\n",
633 ptr->num, time, time-first_time, time-prev_time,
634 seq, seq_delta_isn, seq_delta_prev,
636 #if GTK_MAJOR_VERSION < 2
637 gtk_text_insert(GTK_TEXT(g->text), g->font, c, NULL,
638 (const char * )line, -1);
640 gtk_text_buffer_insert(buf, &iter, (const char *)line, -1);
644 #if GTK_MAJOR_VERSION < 2
645 gtk_text_thaw (GTK_TEXT (g->text));
650 static void create_drawing_area (struct graph *g)
652 GdkColormap *colormap;
654 #define WINDOW_TITLE_LENGTH 64
655 char window_title[WINDOW_TITLE_LENGTH];
656 struct segment current;
657 struct tcpheader *thdr;
659 debug(DBS_FENTRY) puts ("create_drawing_area()");
661 g->font = gdk_font_load ("-sony-fixed-medium-r-normal--16-150-75-75"
663 g->font = gdk_font_load ("-biznet-fotinostypewriter-medium-r-normal-*-*-120"
664 "-*-*-m-*-iso8859-2");
666 thdr=select_tcpip_session (&cfile, ¤t);
667 g_snprintf (window_title, WINDOW_TITLE_LENGTH, "TCP Graph %d: %s %s:%d -> %s:%d",
669 cf_get_display_name(&cfile),
670 address_to_str(&(thdr->ip_src)),
672 address_to_str(&(thdr->ip_dst)),
675 g->toplevel = dlg_window_new ("Tcp Graph");
676 gtk_window_set_title(GTK_WINDOW(g->toplevel), window_title);
677 gtk_widget_set_name (g->toplevel, "Test Graph");
679 /* Create the drawing area */
680 g->drawing_area = gtk_drawing_area_new ();
681 g->x_axis->drawing_area = g->y_axis->drawing_area = g->drawing_area;
682 gtk_drawing_area_size (GTK_DRAWING_AREA (g->drawing_area),
683 g->wp.width + g->wp.x + RMARGIN_WIDTH,
684 g->wp.height + g->wp.y + g->x_axis->s.height);
685 gtk_widget_show (g->drawing_area);
687 SIGNAL_CONNECT(g->drawing_area, "expose_event", expose_event, NULL);
688 /* this has to be done later, after the widget has been shown */
690 SIGNAL_CONNECT(g->drawing_area,"configure_event", configure_event,
693 SIGNAL_CONNECT(g->drawing_area, "motion_notify_event",
694 motion_notify_event, NULL);
695 SIGNAL_CONNECT(g->drawing_area, "button_press_event",
696 button_press_event, NULL);
697 SIGNAL_CONNECT(g->drawing_area, "button_release_event",
698 button_release_event, NULL);
699 SIGNAL_CONNECT(g->drawing_area, "leave_notify_event",
700 leave_notify_event, NULL);
701 SIGNAL_CONNECT(g->drawing_area, "enter_notify_event",
702 enter_notify_event, NULL);
703 SIGNAL_CONNECT(g->toplevel, "destroy", callback_toplevel_destroy, g);
704 /* why doesn't drawing area send key_press_signals? */
705 SIGNAL_CONNECT(g->toplevel, "key_press_event", key_press_event, NULL);
706 SIGNAL_CONNECT(g->toplevel, "key_release_event", key_release_event,
708 gtk_widget_set_events(g->toplevel,
709 GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
711 gtk_widget_set_events (g->drawing_area,
713 | GDK_LEAVE_NOTIFY_MASK
714 | GDK_ENTER_NOTIFY_MASK
715 | GDK_BUTTON_PRESS_MASK
716 | GDK_BUTTON_RELEASE_MASK
717 | GDK_POINTER_MOTION_MASK
718 | GDK_POINTER_MOTION_HINT_MASK);
721 frame = gtk_frame_new (NULL);
722 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
723 gtk_container_add (GTK_CONTAINER (frame), g->drawing_area);
725 box = gtk_hbox_new (FALSE, 0);
726 gtk_box_pack_start (GTK_BOX (box), g->gui.control_panel, FALSE, FALSE, 0);
727 gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0);
728 gtk_container_add (GTK_CONTAINER (g->toplevel), box);
729 gtk_container_set_border_width (GTK_CONTAINER (g->toplevel), 5);
730 gtk_widget_show (frame);
731 gtk_widget_show (box);
734 gtk_container_add (GTK_CONTAINER (g->toplevel), g->drawing_area);
735 gtk_widget_show (g->toplevel);
737 /* in case we didn't get what we asked for */
738 g->wp.width = GTK_WIDGET (g->drawing_area)->allocation.width -
739 g->wp.x - RMARGIN_WIDTH;
740 g->wp.height = GTK_WIDGET (g->drawing_area)->allocation.height -
741 g->wp.y - g->x_axis->s.height;
743 #if GTK_MAJOR_VERSION < 2
744 g->font = g->drawing_area->style->font;
745 gdk_font_ref (g->font);
747 g->font = g->drawing_area->style->font_desc;
750 colormap = gdk_window_get_colormap (g->drawing_area->window);
752 xor_gc = gdk_gc_new (g->drawing_area->window);
753 gdk_gc_set_function (xor_gc, GDK_XOR);
754 if (!gdk_color_parse ("gray15", &color)) {
756 * XXX - do more than just warn.
758 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
759 "Could not parse color gray15.");
761 if (!gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE)) {
763 * XXX - do more than just warn.
765 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
766 "Could not allocate color gray15.");
768 gdk_gc_set_foreground (xor_gc, &color);
770 g->fg_gc = gdk_gc_new (g->drawing_area->window);
771 g->bg_gc = gdk_gc_new (g->drawing_area->window);
772 if (!gdk_color_parse ("white", &color)) {
774 * XXX - do more than just warn.
776 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
777 "Could not parse color white.");
779 if (!gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE)) {
781 * XXX - do more than just warn.
783 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
784 "Could not allocate color white.");
786 gdk_gc_set_foreground (g->bg_gc, &color);
788 /* this is probably quite an ugly way to get rid of the first configure
790 * immediatelly after gtk_widget_show (window) drawing_area gets a configure
791 * event which is handled during the next return to gtk_main which is
792 * probably the gdk_gc_new() call. configure handler calls
793 * graph_element_lists_make() which is not good because the graph struct is
794 * not fully set up yet - namely we're not sure about actual geometry
795 * and we don't have the GC's at all. so we just postpone installation
796 * of configure handler until we're ready to deal with it.
798 * !!! NEMÌLO BY TO BÝT NA KONCI graph_init_sequence()? !!!
801 SIGNAL_CONNECT(g->drawing_area,"configure_event", configure_event,
804 /* puts ("exiting create_drawing_area()"); */
807 static void callback_toplevel_destroy (GtkWidget *widget _U_, gpointer data)
809 struct graph *g = (struct graph * )data;
811 if (!(g->flags & GRAPH_DESTROYED)) {
812 g->flags |= GRAPH_DESTROYED;
813 graph_destroy ((struct graph * )data);
817 static void control_panel_create (struct graph *g)
819 GtkWidget *toplevel, *notebook;
821 GtkWidget *help_bt, *close_bt, *bbox;
822 #define WINDOW_TITLE_LENGTH 64
823 char window_title[WINDOW_TITLE_LENGTH];
825 debug(DBS_FENTRY) puts ("control_panel_create()");
827 notebook = gtk_notebook_new ();
828 control_panel_add_zoom_page (g, notebook);
829 control_panel_add_magnify_page (g, notebook);
830 control_panel_add_origin_page (g, notebook);
831 control_panel_add_cross_page (g, notebook);
832 control_panel_add_graph_type_page (g, notebook);
834 g_snprintf (window_title, WINDOW_TITLE_LENGTH,
835 "Graph %d - Control - Ethereal", refnum);
836 toplevel = dlg_window_new ("tcp-graph-control");
837 gtk_window_set_title(GTK_WINDOW(toplevel), window_title);
839 table = gtk_table_new (2, 1, FALSE);
840 gtk_container_add (GTK_CONTAINER (toplevel), table);
842 gtk_table_attach (GTK_TABLE (table), notebook, 0, 1, 0, 1,
843 GTK_FILL|GTK_EXPAND, GTK_FILL, 5, 5);
846 bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_CLOSE, NULL);
847 gtk_table_attach (GTK_TABLE (table), bbox, 0, 1, 1, 2,
848 GTK_FILL|GTK_EXPAND, GTK_FILL, 5, 5);
850 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
851 SIGNAL_CONNECT(help_bt, "clicked", callback_create_help, g);
853 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
854 window_set_cancel_button(toplevel, close_bt, NULL);
855 SIGNAL_CONNECT(close_bt, "clicked", callback_close, g);
857 SIGNAL_CONNECT(toplevel, "delete_event", callback_delete_event, g);
858 SIGNAL_CONNECT(toplevel, "destroy", callback_toplevel_destroy, g);
860 /* gtk_widget_show_all (table); */
861 /* g->gui.control_panel = table; */
862 gtk_widget_show_all (toplevel);
863 window_present(toplevel);
865 g->gui.control_panel = toplevel;
868 static void control_panel_add_zoom_page (struct graph *g, GtkWidget *n)
870 GtkWidget *zoom_frame;
871 GtkWidget *zoom_lock_frame;
875 zoom_frame = control_panel_create_zoom_group (g);
876 gtk_container_set_border_width (GTK_CONTAINER (zoom_frame), 5);
877 zoom_lock_frame = control_panel_create_zoomlock_group (g);
878 gtk_container_set_border_width (GTK_CONTAINER (zoom_lock_frame), 5);
879 box = gtk_vbox_new (FALSE, 0);
880 gtk_box_pack_start (GTK_BOX (box), zoom_frame, TRUE, TRUE, 0);
881 gtk_box_pack_start (GTK_BOX (box), zoom_lock_frame, TRUE, TRUE, 0);
882 gtk_widget_show (box);
883 label = gtk_label_new ("Zoom");
884 gtk_notebook_append_page (GTK_NOTEBOOK (n), box, label);
887 static void control_panel_add_magnify_page (struct graph *g, GtkWidget *n)
889 GtkWidget *mag_frame, *label;
891 mag_frame = control_panel_create_magnify_group (g);
892 gtk_container_set_border_width (GTK_CONTAINER (mag_frame), 5);
893 label = gtk_label_new ("Magnify");
894 gtk_notebook_append_page (GTK_NOTEBOOK (n), mag_frame, label);
897 static void control_panel_add_origin_page (struct graph *g, GtkWidget *n)
899 GtkWidget *time_orig_cap, *time_orig_conn, *time_orig_box, *time_orig_frame;
900 GtkWidget *seq_orig_isn, *seq_orig_zero, *seq_orig_box, *seq_orig_frame;
901 GtkWidget *box, *label;
903 /* time origin box */
905 gtk_radio_button_new_with_label (NULL, "beginning of capture");
906 time_orig_conn = gtk_radio_button_new_with_label (
907 gtk_radio_button_group (GTK_RADIO_BUTTON (time_orig_cap)),
908 "beginning of this TCP connection");
909 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (time_orig_conn), TRUE);
910 time_orig_box = gtk_vbox_new (TRUE, 0);
911 gtk_box_pack_start (GTK_BOX (time_orig_box), time_orig_conn, TRUE, TRUE, 0);
912 gtk_box_pack_start (GTK_BOX (time_orig_box), time_orig_cap, TRUE, TRUE, 0);
913 time_orig_frame = gtk_frame_new ("Time origin");
914 gtk_container_set_border_width (GTK_CONTAINER (time_orig_frame), 5);
915 gtk_container_add (GTK_CONTAINER (time_orig_frame), time_orig_box);
917 /* sequence number origin group */
919 gtk_radio_button_new_with_label (NULL, "initial sequence number");
920 seq_orig_zero = gtk_radio_button_new_with_label (gtk_radio_button_group (
921 GTK_RADIO_BUTTON (seq_orig_isn)), "0 (=absolute)");
922 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (seq_orig_isn), TRUE);
923 seq_orig_box = gtk_vbox_new (TRUE, 0);
924 gtk_box_pack_start (GTK_BOX (seq_orig_box), seq_orig_isn, TRUE, TRUE, 0);
925 gtk_box_pack_start (GTK_BOX (seq_orig_box), seq_orig_zero, TRUE, TRUE, 0);
926 seq_orig_frame = gtk_frame_new ("Sequence number origin");
927 gtk_container_set_border_width (GTK_CONTAINER (seq_orig_frame), 5);
928 gtk_container_add (GTK_CONTAINER (seq_orig_frame), seq_orig_box);
930 g->gui.time_orig_conn = (GtkToggleButton * )time_orig_conn;
931 g->gui.seq_orig_isn = (GtkToggleButton * )seq_orig_isn;
933 SIGNAL_CONNECT(time_orig_conn, "toggled", callback_time_origin, g);
934 SIGNAL_CONNECT(seq_orig_isn, "toggled", callback_seq_origin, g);
936 box = gtk_vbox_new (FALSE, 0);
937 gtk_container_set_border_width (GTK_CONTAINER (box), 5);
938 gtk_box_pack_start (GTK_BOX (box), time_orig_frame, TRUE, TRUE, 0);
939 gtk_box_pack_start (GTK_BOX (box), seq_orig_frame, TRUE, TRUE, 0);
940 gtk_widget_show (box);
941 label = gtk_label_new ("Origin");
942 gtk_notebook_append_page (GTK_NOTEBOOK (n), box, label);
945 static void control_panel_add_cross_page (struct graph *g, GtkWidget *n)
947 GtkWidget *cross_frame, *label;
949 cross_frame = control_panel_create_cross_group (g);
950 gtk_container_set_border_width (GTK_CONTAINER (cross_frame), 5);
951 label = gtk_label_new ("Cross");
952 gtk_notebook_append_page (GTK_NOTEBOOK (n), cross_frame, label);
955 static void control_panel_add_graph_type_page (struct graph *g, GtkWidget *n)
957 GtkWidget *frame, *label;
959 frame = control_panel_create_graph_type_group (g);
960 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
961 label = gtk_label_new ("Graph type");
962 gtk_notebook_append_page (GTK_NOTEBOOK (n), frame, label);
965 /* Treat this as a cancel, by calling "callback_close()" */
967 callback_delete_event(GtkWidget *widget _U_, GdkEvent *event _U_,
970 callback_close(NULL, data);
974 static void callback_close (GtkWidget *widget _U_, gpointer data)
976 struct graph *g = (struct graph * )data;
978 if (!(g->flags & GRAPH_DESTROYED)) {
979 g->flags |= GRAPH_DESTROYED;
980 graph_destroy ((struct graph * )data);
984 static void callback_create_help(GtkWidget *widget _U_, gpointer data _U_)
986 GtkWidget *toplevel, *vbox, *text, *scroll, *bbox, *close_bt;
987 #if GTK_MAJOR_VERSION < 2
988 struct graph *g = (struct graph * )data;
993 toplevel = dlg_window_new ("Help for TCP graphing");
994 gtk_window_set_default_size(GTK_WINDOW(toplevel), 500, 400);
996 vbox = gtk_vbox_new (FALSE, 3);
997 gtk_container_border_width(GTK_CONTAINER(vbox), 12);
998 gtk_container_add (GTK_CONTAINER (toplevel), vbox);
1000 scroll = scrolled_window_new (NULL, NULL);
1001 #if GTK_MAJOR_VERSION >= 2
1002 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
1005 gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
1006 #if GTK_MAJOR_VERSION < 2
1007 text = gtk_text_new (NULL, NULL);
1008 gtk_text_set_editable (GTK_TEXT (text), FALSE);
1009 gtk_text_set_line_wrap (GTK_TEXT (text), FALSE);
1010 gtk_text_set_word_wrap (GTK_TEXT (text), FALSE);
1011 gtk_text_insert (GTK_TEXT (text), g->font, NULL, NULL, helptext, -1);
1013 text = gtk_text_view_new();
1014 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
1015 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
1016 gtk_text_buffer_set_text(buf, helptext, -1);
1018 gtk_container_add (GTK_CONTAINER (scroll), text);
1021 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
1022 gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
1023 gtk_widget_show(bbox);
1025 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
1026 window_set_cancel_button(toplevel, close_bt, window_cancel_button_cb);
1028 SIGNAL_CONNECT(toplevel, "delete_event", window_delete_event_cb, NULL);
1030 gtk_widget_show_all (toplevel);
1031 window_present(toplevel);
1034 static void callback_time_origin (GtkWidget *toggle _U_, gpointer data)
1036 toggle_time_origin ((struct graph * )data);
1039 static void callback_seq_origin (GtkWidget *toggle _U_, gpointer data)
1041 toggle_seq_origin ((struct graph * )data);
1044 static GtkWidget *control_panel_create_zoom_group (struct graph *g)
1046 GtkWidget *zoom_in, *zoom_out, *zoom_box, *zoom_frame;
1047 GtkAdjustment *zoom_h_adj, *zoom_v_adj;
1048 GtkWidget *zoom_inout_box, *zoom_h_step_label, *zoom_h_step;
1049 GtkWidget *zoom_v_step_label, *zoom_v_step;
1050 GtkWidget *zoom_separator1, *zoom_separator2, *zoom_step_table, *zoom_table;
1051 GtkWidget *zoom_ratio_toggle, *zoom_same_toggle;
1052 GtkWidget *zoom_h_entry, *zoom_v_entry;
1053 GtkWidget *zoom_h_label, *zoom_v_label;
1055 zoom_in = gtk_radio_button_new_with_label (NULL, "in");
1056 zoom_out = gtk_radio_button_new_with_label (
1057 gtk_radio_button_group (GTK_RADIO_BUTTON (zoom_in)), "out");
1058 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (zoom_in), TRUE);
1059 zoom_inout_box = gtk_hbox_new (FALSE, 0);
1060 gtk_box_pack_start (GTK_BOX (zoom_inout_box), zoom_in, FALSE, FALSE, 10);
1061 gtk_box_pack_start (GTK_BOX (zoom_inout_box), zoom_out, FALSE, FALSE, 0);
1063 zoom_separator1 = gtk_hseparator_new ();
1065 zoom_h_entry = gtk_entry_new ();
1066 gtk_entry_set_text (GTK_ENTRY (zoom_h_entry), "1.000");
1067 gtk_editable_set_editable (GTK_EDITABLE (zoom_h_entry), FALSE);
1068 zoom_h_label = gtk_label_new ("Horizontal:");
1070 zoom_v_entry = gtk_entry_new ();
1071 gtk_entry_set_text (GTK_ENTRY (zoom_v_entry), "1.000");
1072 gtk_editable_set_editable (GTK_EDITABLE (zoom_v_entry), FALSE);
1073 zoom_v_label = gtk_label_new ("Vertical:");
1075 g->zoom.widget.h_zoom = (GtkEntry * )zoom_h_entry;
1076 g->zoom.widget.v_zoom = (GtkEntry * )zoom_v_entry;
1078 zoom_table = gtk_table_new (2, 2, FALSE);
1079 gtk_table_attach (GTK_TABLE (zoom_table), zoom_h_label, 0,1,0,1,
1080 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1081 gtk_table_attach (GTK_TABLE (zoom_table), zoom_h_entry, 1, 2, 0, 1,
1082 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1083 gtk_table_attach (GTK_TABLE (zoom_table), zoom_v_label, 0,1,1,2,
1084 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1085 gtk_table_attach (GTK_TABLE (zoom_table), zoom_v_entry, 1, 2, 1, 2,
1086 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1088 zoom_separator2 = gtk_hseparator_new ();
1090 zoom_h_adj = (GtkAdjustment * )gtk_adjustment_new ((gfloat)1.2, 1.0, 5, (gfloat)0.1, 1, 0);
1091 zoom_h_step = gtk_spin_button_new (zoom_h_adj, 0, 1);
1092 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (zoom_h_step), TRUE);
1093 zoom_h_step_label = gtk_label_new ("Horizontal step:");
1095 zoom_v_adj = (GtkAdjustment * )gtk_adjustment_new ((gfloat)1.2, 1.0, 5, (gfloat)0.1, 1, 0);
1096 zoom_v_step = gtk_spin_button_new (zoom_v_adj, 0, 1);
1097 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (zoom_v_step), TRUE);
1098 zoom_v_step_label = gtk_label_new ("Vertical step:");
1100 g->zoom.widget.h_step = (GtkSpinButton * )zoom_h_step;
1101 g->zoom.widget.v_step = (GtkSpinButton * )zoom_v_step;
1103 zoom_same_toggle = gtk_check_button_new_with_label("Keep them the same");
1104 zoom_ratio_toggle = gtk_check_button_new_with_label("Preserve their ratio");
1105 OBJECT_SET_DATA(zoom_same_toggle, "flag", (gpointer)ZOOM_STEPS_SAME);
1106 OBJECT_SET_DATA(zoom_ratio_toggle, "flag",
1107 (gpointer)ZOOM_STEPS_KEEP_RATIO);
1108 SIGNAL_CONNECT(zoom_same_toggle, "clicked", callback_zoom_flags, g);
1109 SIGNAL_CONNECT(zoom_ratio_toggle, "clicked", callback_zoom_flags, g);
1111 zoom_step_table = gtk_table_new (4, 2, FALSE);
1112 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_h_step_label, 0,1,0,1,
1113 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1114 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_h_step, 1, 2, 0, 1,
1115 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1116 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_v_step_label, 0,1,1,2,
1117 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1118 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_v_step, 1, 2, 1, 2,
1119 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1120 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_same_toggle, 0,2,2,3,
1121 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1122 gtk_table_attach (GTK_TABLE (zoom_step_table), zoom_ratio_toggle, 0,2,3,4,
1123 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1125 zoom_box = gtk_vbox_new (FALSE, 0);
1126 gtk_box_pack_start (GTK_BOX (zoom_box), zoom_inout_box, TRUE, TRUE, 0);
1127 gtk_box_pack_start (GTK_BOX (zoom_box), zoom_separator1, TRUE, TRUE, 0);
1128 gtk_box_pack_start (GTK_BOX (zoom_box), zoom_table, TRUE, TRUE, 0);
1129 gtk_box_pack_start (GTK_BOX (zoom_box), zoom_separator2, TRUE, TRUE, 0);
1130 gtk_box_pack_start (GTK_BOX (zoom_box), zoom_step_table, TRUE, TRUE, 0);
1131 zoom_frame = gtk_frame_new ("Zoom");
1132 gtk_container_add (GTK_CONTAINER (zoom_frame), zoom_box);
1134 OBJECT_SET_DATA(zoom_h_step, "direction", GINT_TO_POINTER(0));
1135 OBJECT_SET_DATA(zoom_v_step, "direction", GINT_TO_POINTER(1));
1137 SIGNAL_CONNECT(zoom_in, "toggled", callback_zoom_inout, g);
1138 SIGNAL_CONNECT(zoom_h_step, "changed", callback_zoom_step, g);
1139 SIGNAL_CONNECT(zoom_v_step, "changed", callback_zoom_step, g);
1141 g->zoom.widget.in_toggle = (GtkToggleButton * )zoom_in;
1142 g->zoom.widget.out_toggle = (GtkToggleButton * )zoom_out;
1146 static void callback_zoom_inout (GtkWidget *toggle, gpointer data)
1148 struct graph *g = (struct graph * )data;
1150 if (GTK_TOGGLE_BUTTON (toggle)->active)
1151 g->zoom.flags &= ~ZOOM_OUT;
1153 g->zoom.flags |= ZOOM_OUT;
1156 static void callback_zoom_step (GtkWidget *spin, gpointer data)
1158 struct graph *g = (struct graph * )data;
1161 double *zoom_this, *zoom_other;
1162 GtkSpinButton *widget_this, *widget_other;
1165 direction = (int)OBJECT_GET_DATA(spin, "direction");
1166 value = gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (spin));
1169 zoom_this = &g->zoom.step_y;
1170 zoom_other = &g->zoom.step_x;
1171 widget_this = g->zoom.widget.v_step;
1172 widget_other = g->zoom.widget.h_step;
1174 zoom_this = &g->zoom.step_x;
1175 zoom_other = &g->zoom.step_y;
1176 widget_this = g->zoom.widget.h_step;
1177 widget_other = g->zoom.widget.v_step;
1180 old_this = *zoom_this;
1182 if (g->zoom.flags & ZOOM_STEPS_SAME) {
1183 *zoom_other = value;
1184 gtk_spin_button_set_value (widget_other, (gfloat) *zoom_other);
1185 } else if (g->zoom.flags & ZOOM_STEPS_KEEP_RATIO) {
1186 double old_other = *zoom_other;
1187 *zoom_other *= value / old_this;
1188 if (*zoom_other < 1.0) {
1190 *zoom_this = old_this * 1.0 / old_other;
1191 gtk_spin_button_set_value (widget_this, (gfloat) *zoom_this);
1192 } else if (*zoom_other > 5.0) {
1194 *zoom_this = old_this * 5.0 / old_other;
1195 gtk_spin_button_set_value (widget_this, (gfloat) *zoom_this);
1197 gtk_spin_button_set_value (widget_other, (gfloat) *zoom_other);
1201 static void callback_zoom_flags (GtkWidget *toggle, gpointer data)
1203 struct graph *g = (struct graph * )data;
1204 int flag = (int)OBJECT_GET_DATA(toggle, "flag");
1206 if (GTK_TOGGLE_BUTTON (toggle)->active)
1207 g->zoom.flags |= flag;
1209 g->zoom.flags &= ~flag;
1212 static void update_zoom_spins (struct graph *g)
1216 g_snprintf (s, 32, "%.3f", g->zoom.x / g->zoom.initial.x);
1217 gtk_entry_set_text (g->zoom.widget.h_zoom, s);
1218 g_snprintf (s, 32, "%.3f", g->zoom.y / g->zoom.initial.y);
1219 gtk_entry_set_text (g->zoom.widget.v_zoom, s);
1222 static GtkWidget *control_panel_create_magnify_group (struct graph *g)
1224 GtkWidget *mag_width_label, *mag_width;
1225 GtkWidget *mag_height_label, *mag_height;
1226 GtkWidget *mag_x_label, *mag_x;
1227 GtkWidget *mag_y_label, *mag_y;
1228 GtkWidget *mag_wh_table, *mag_zoom_frame, *mag_zoom_table;
1229 GtkWidget *mag_h_zoom_label, *mag_h_zoom;
1230 GtkWidget *mag_v_zoom_label, *mag_v_zoom;
1231 GtkWidget *mag_zoom_same, *mag_zoom_ratio;
1232 GtkAdjustment *mag_width_adj, *mag_height_adj, *mag_x_adj, *mag_y_adj;
1233 GtkAdjustment *mag_h_zoom_adj, *mag_v_zoom_adj;
1234 GtkWidget *mag_box, *mag_frame;
1236 mag_width_label = gtk_label_new ("Width:");
1237 mag_width_adj = (GtkAdjustment * )gtk_adjustment_new (250,100,600,1,10,0);
1238 mag_width = gtk_spin_button_new (mag_width_adj, 0, 0);
1240 mag_height_label = gtk_label_new ("Height:");
1241 mag_height_adj = (GtkAdjustment * )gtk_adjustment_new (250,100,600,1,10,0);
1242 mag_height = gtk_spin_button_new (mag_height_adj, 0, 0);
1244 mag_x_label = gtk_label_new ("X:");
1245 mag_x_adj = (GtkAdjustment * )gtk_adjustment_new (0,-1000,1000,1,10,0);
1246 mag_x = gtk_spin_button_new (mag_x_adj, 0, 0);
1248 mag_y_label = gtk_label_new ("Y:");
1249 mag_y_adj = (GtkAdjustment * )gtk_adjustment_new (0,-1000,1000,1,10,0);
1250 mag_y = gtk_spin_button_new (mag_y_adj, 0, 0);
1252 mag_wh_table = gtk_table_new (4, 2, FALSE);
1253 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_width_label, 0,1,0,1,
1254 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1255 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_width, 1,2,0,1,
1256 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1257 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_height_label, 0,1,1,2,
1258 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1259 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_height, 1,2,1,2,
1260 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1261 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_x_label, 0,1,2,3,
1262 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1263 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_x, 1,2,2,3,
1264 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1265 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_y_label, 0,1,3,4,
1266 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1267 gtk_table_attach (GTK_TABLE (mag_wh_table), mag_y, 1,2,3,4,
1268 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 5, 0);
1270 mag_h_zoom_label = gtk_label_new ("Horizontal:");
1271 mag_h_zoom_adj = (GtkAdjustment *)gtk_adjustment_new(10.0, 1.0, 25.0, (gfloat)0.1, 1, 0);
1272 mag_h_zoom = gtk_spin_button_new (mag_h_zoom_adj, 0, 1);
1274 mag_v_zoom_label = gtk_label_new ("Vertical:");
1275 mag_v_zoom_adj = (GtkAdjustment *)gtk_adjustment_new(10.0, 1.0, 25.0, (gfloat)0.1, 1, 0);
1276 mag_v_zoom = gtk_spin_button_new (mag_v_zoom_adj, 0, 1);
1278 mag_zoom_same = gtk_check_button_new_with_label ("Keep them the same");
1279 mag_zoom_ratio = gtk_check_button_new_with_label("Preserve their ratio");
1281 mag_zoom_table = gtk_table_new (4, 2, FALSE);
1282 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_h_zoom_label, 0,1,0,1,
1283 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1284 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_h_zoom, 1,2,0,1,
1285 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1286 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_v_zoom_label, 0,1,1,2,
1287 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1288 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_v_zoom, 1,2,1,2,
1289 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1290 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_zoom_same, 0,2,2,3,
1291 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1292 gtk_table_attach (GTK_TABLE (mag_zoom_table), mag_zoom_ratio, 0,2,3,4,
1293 GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
1295 mag_zoom_frame = gtk_frame_new ("Magnify zoom");
1296 gtk_container_add (GTK_CONTAINER (mag_zoom_frame), mag_zoom_table);
1297 gtk_container_set_border_width (GTK_CONTAINER (mag_zoom_frame), 3);
1299 mag_box = gtk_vbox_new (FALSE, 0);
1300 gtk_box_pack_start (GTK_BOX (mag_box), mag_wh_table, TRUE, TRUE, 0);
1301 gtk_box_pack_start (GTK_BOX (mag_box), mag_zoom_frame, TRUE, TRUE, 0);
1302 mag_frame = gtk_frame_new ("Magnify");
1303 gtk_container_add (GTK_CONTAINER (mag_frame), mag_box);
1305 g->magnify.widget.h_zoom = (GtkSpinButton * )mag_h_zoom;
1306 g->magnify.widget.v_zoom = (GtkSpinButton * )mag_v_zoom;
1307 OBJECT_SET_DATA(mag_h_zoom, "direction", GINT_TO_POINTER(0));
1308 OBJECT_SET_DATA(mag_v_zoom, "direction", GINT_TO_POINTER(1));
1309 OBJECT_SET_DATA(mag_zoom_same, "flag", (gpointer)MAGZOOMS_SAME);
1310 OBJECT_SET_DATA(mag_zoom_ratio, "flag", (gpointer)MAGZOOMS_SAME_RATIO);
1312 SIGNAL_CONNECT(mag_width, "changed", callback_mag_width, g);
1313 SIGNAL_CONNECT(mag_height, "changed", callback_mag_height, g);
1314 SIGNAL_CONNECT(mag_x, "changed", callback_mag_x, g);
1315 SIGNAL_CONNECT(mag_y, "changed", callback_mag_y, g);
1316 SIGNAL_CONNECT(mag_h_zoom, "changed", callback_mag_zoom, g);
1317 SIGNAL_CONNECT(mag_v_zoom, "changed", callback_mag_zoom, g);
1318 SIGNAL_CONNECT(mag_zoom_same, "clicked", callback_mag_flags, g);
1319 SIGNAL_CONNECT(mag_zoom_ratio, "clicked", callback_mag_flags, g);
1324 static void callback_mag_width (GtkWidget *spin, gpointer data)
1326 struct graph *g = (struct graph * )data;
1328 g->magnify.width = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin));
1331 static void callback_mag_height (GtkWidget *spin, gpointer data)
1333 struct graph *g = (struct graph * )data;
1335 g->magnify.height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
1338 static void callback_mag_x (GtkWidget *spin, gpointer data)
1340 struct graph *g = (struct graph * )data;
1342 g->magnify.offset.x=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
1345 static void callback_mag_y (GtkWidget *spin, gpointer data)
1347 struct graph *g = (struct graph * )data;
1349 g->magnify.offset.y=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
1352 static void callback_mag_zoom (GtkWidget *spin, gpointer data)
1354 struct graph *g = (struct graph * )data;
1357 double *zoom_this, *zoom_other;
1358 GtkSpinButton *widget_this, *widget_other;
1361 if (g->magnify.flags & MAGZOOMS_IGNORE) {
1362 printf ("refusing callback for %s zoom widget.\n", (GtkSpinButton * )spin==g->magnify.widget.h_zoom ? "horizontal" : "vertical");
1363 g->magnify.flags &= ~MAGZOOMS_IGNORE;
1366 direction = (int)OBJECT_GET_DATA(spin, "direction");
1367 value = gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (spin));
1370 zoom_this = &g->magnify.zoom.y;
1371 zoom_other = &g->magnify.zoom.x;
1372 widget_this = g->magnify.widget.v_zoom;
1373 widget_other = g->magnify.widget.h_zoom;
1375 zoom_this = &g->magnify.zoom.x;
1376 zoom_other = &g->magnify.zoom.y;
1377 widget_this = g->magnify.widget.h_zoom;
1378 widget_other = g->magnify.widget.v_zoom;
1381 old_this = *zoom_this;
1383 if (g->magnify.flags & MAGZOOMS_SAME) {
1384 *zoom_other = value;
1385 /* g->magnify.flags |= MAGZOOMS_IGNORE; */
1386 gtk_spin_button_set_value (widget_other, (gfloat) *zoom_other);
1387 } else if (g->magnify.flags & MAGZOOMS_SAME_RATIO) {
1388 double old_other = *zoom_other;
1389 *zoom_other *= value / old_this;
1390 if (*zoom_other < 1.0) {
1392 *zoom_this = old_this * 1.0 / old_other;
1393 /* g->magnify.flags |= MAGZOOMS_IGNORE; */
1394 gtk_spin_button_set_value (widget_this, (gfloat) *zoom_this);
1395 } else if (*zoom_other > 25.0) {
1397 *zoom_this = old_this * 25.0 / old_other;
1398 /* g->magnify.flags |= MAGZOOMS_IGNORE; */
1399 gtk_spin_button_set_value (widget_this, (gfloat) *zoom_this);
1401 /* g->magnify.flags |= MAGZOOMS_IGNORE; */
1402 gtk_spin_button_set_value (widget_other, (gfloat) *zoom_other);
1406 static void callback_mag_flags (GtkWidget *toggle, gpointer data)
1408 struct graph *g = (struct graph * )data;
1409 int flag = (int)OBJECT_GET_DATA(toggle, "flag");
1411 if (GTK_TOGGLE_BUTTON (toggle)->active)
1412 g->magnify.flags |= flag;
1414 g->magnify.flags &= ~flag;
1417 static GtkWidget *control_panel_create_zoomlock_group (struct graph *g)
1419 GtkWidget *zoom_lock_h, *zoom_lock_v, *zoom_lock_none, *zoom_lock_box;
1420 GtkWidget *zoom_lock_frame;
1422 zoom_lock_none = gtk_radio_button_new_with_label (NULL, "none");
1423 zoom_lock_h = gtk_radio_button_new_with_label (
1424 gtk_radio_button_group (GTK_RADIO_BUTTON (zoom_lock_none)),
1426 zoom_lock_v = gtk_radio_button_new_with_label (
1427 gtk_radio_button_group (GTK_RADIO_BUTTON (zoom_lock_none)),
1429 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (zoom_lock_none), TRUE);
1430 zoom_lock_box = gtk_hbox_new (FALSE, 0);
1431 gtk_box_pack_start(GTK_BOX(zoom_lock_box), zoom_lock_none,
1433 gtk_box_pack_start(GTK_BOX(zoom_lock_box), zoom_lock_h, TRUE, TRUE, 0);
1434 gtk_box_pack_start(GTK_BOX(zoom_lock_box), zoom_lock_v, TRUE, TRUE, 0);
1435 zoom_lock_frame = gtk_frame_new ("Zoom lock:");
1436 gtk_container_add (GTK_CONTAINER (zoom_lock_frame), zoom_lock_box);
1438 SIGNAL_CONNECT(zoom_lock_h, "toggled", callback_zoomlock_h, g);
1439 SIGNAL_CONNECT(zoom_lock_v, "toggled", callback_zoomlock_v, g);
1441 return zoom_lock_frame;
1444 static void callback_zoomlock_h (GtkWidget *toggle, gpointer data)
1446 struct graph *g = (struct graph * )data;
1448 if (GTK_TOGGLE_BUTTON (toggle)->active)
1449 g->zoom.flags |= ZOOM_HLOCK;
1451 g->zoom.flags &= ~ZOOM_HLOCK;
1454 static void callback_zoomlock_v (GtkWidget *toggle, gpointer data)
1456 struct graph *g = (struct graph * )data;
1458 if (GTK_TOGGLE_BUTTON (toggle)->active)
1459 g->zoom.flags |= ZOOM_VLOCK;
1461 g->zoom.flags &= ~ZOOM_VLOCK;
1464 static GtkWidget *control_panel_create_cross_group (struct graph *g)
1466 GtkWidget *on, *off, *box, *frame, *vbox, *label;
1468 label = gtk_label_new ("Crosshairs:");
1469 off = gtk_radio_button_new_with_label (NULL, "off");
1470 on = gtk_radio_button_new_with_label (
1471 gtk_radio_button_group (GTK_RADIO_BUTTON (off)), "on");
1472 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (off), TRUE);
1473 box = gtk_hbox_new (FALSE, 0);
1474 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 10);
1475 gtk_box_pack_start (GTK_BOX (box), off, FALSE, FALSE, 10);
1476 gtk_box_pack_start (GTK_BOX (box), on, FALSE, FALSE, 0);
1477 vbox = gtk_vbox_new (FALSE, 0);
1478 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 15);
1479 /* frame = gtk_frame_new ("Cross:"); */
1480 frame = gtk_frame_new (NULL);
1481 gtk_container_add (GTK_CONTAINER (frame), vbox);
1483 SIGNAL_CONNECT(on, "toggled", callback_cross_on_off, g);
1485 g->cross.on_toggle = (GtkToggleButton * )on;
1486 g->cross.off_toggle = (GtkToggleButton * )off;
1491 static void callback_cross_on_off (GtkWidget *toggle, gpointer data)
1493 struct graph *g = (struct graph * )data;
1495 if (GTK_TOGGLE_BUTTON (toggle)->active) {
1497 g->cross.draw = TRUE;
1498 gdk_window_get_pointer (g->drawing_area->window, &x, &y, 0);
1499 cross_draw (g, x, y);
1501 g->cross.draw = FALSE;
1506 static GtkWidget *control_panel_create_graph_type_group (struct graph *g)
1508 GtkWidget *graph_tseqttrace, *graph_tseqstevens;
1509 GtkWidget *graph_tput, *graph_rtt, *graph_sep, *graph_init, *graph_box;
1510 GtkWidget *graph_frame;
1512 graph_tput = gtk_radio_button_new_with_label (NULL, "Throughput");
1513 graph_tseqttrace = gtk_radio_button_new_with_label (
1514 gtk_radio_button_group (GTK_RADIO_BUTTON (graph_tput)),
1515 "Time/Sequence (tcptrace-style)");
1516 graph_tseqstevens = gtk_radio_button_new_with_label (
1517 gtk_radio_button_group (GTK_RADIO_BUTTON (graph_tput)),
1518 "Time/Sequence (Stevens'-style)");
1519 graph_rtt = gtk_radio_button_new_with_label (
1520 gtk_radio_button_group (GTK_RADIO_BUTTON (graph_tput)),
1523 case GRAPH_TSEQ_STEVENS:
1524 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(graph_tseqstevens),TRUE);
1526 case GRAPH_TSEQ_TCPTRACE:
1527 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(graph_tseqttrace),TRUE);
1529 case GRAPH_THROUGHPUT:
1530 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (graph_tput), TRUE);
1533 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (graph_rtt), TRUE);
1536 graph_init = gtk_check_button_new_with_label ("Init on change");
1537 graph_sep = gtk_hseparator_new ();
1538 graph_box = gtk_vbox_new (FALSE, 0);
1539 gtk_box_pack_start (GTK_BOX (graph_box), graph_tseqttrace, TRUE, TRUE, 0);
1540 gtk_box_pack_start (GTK_BOX (graph_box), graph_tseqstevens, TRUE, TRUE, 0);
1541 gtk_box_pack_start (GTK_BOX (graph_box), graph_tput, TRUE, TRUE, 0);
1542 gtk_box_pack_start (GTK_BOX (graph_box), graph_rtt, TRUE, TRUE, 0);
1543 gtk_box_pack_start (GTK_BOX (graph_box), graph_sep, TRUE, TRUE, 0);
1544 gtk_box_pack_start (GTK_BOX (graph_box), graph_init, TRUE, TRUE, 0);
1545 graph_frame = gtk_frame_new ("Graph type:");
1546 gtk_container_add (GTK_CONTAINER (graph_frame), graph_box);
1548 OBJECT_SET_DATA(graph_tseqstevens, "new-graph-type",
1549 GINT_TO_POINTER(0));
1550 OBJECT_SET_DATA(graph_tseqttrace, "new-graph-type", GINT_TO_POINTER(1));
1551 OBJECT_SET_DATA(graph_tput, "new-graph-type", GINT_TO_POINTER(2));
1552 OBJECT_SET_DATA(graph_rtt, "new-graph-type", GINT_TO_POINTER(3));
1554 SIGNAL_CONNECT(graph_tseqttrace, "toggled", callback_graph_type, g);
1555 SIGNAL_CONNECT(graph_tseqstevens, "toggled", callback_graph_type, g);
1556 SIGNAL_CONNECT(graph_tput, "toggled", callback_graph_type, g);
1557 SIGNAL_CONNECT(graph_rtt, "toggled", callback_graph_type, g);
1558 SIGNAL_CONNECT(graph_init, "toggled", callback_graph_init_on_typechg,
1564 static void callback_graph_type (GtkWidget *toggle, gpointer data)
1566 int old_type, new_type;
1567 struct graph *g = (struct graph * )data;
1569 new_type = (int)OBJECT_GET_DATA(toggle,"new-graph-type");
1571 if (!GTK_TOGGLE_BUTTON (toggle)->active)
1577 graph_element_lists_free (g);
1578 graph_element_lists_initialize (g);
1580 if (old_type == GRAPH_THROUGHPUT || new_type == GRAPH_THROUGHPUT) {
1581 /* throughput graph uses differently constructed segment list so we
1582 * need to recreate it */
1583 graph_segment_list_free (g);
1584 graph_segment_list_get (g);
1587 if (g->flags & GRAPH_INIT_ON_TYPE_CHANGE) {
1588 g->geom.width = g->wp.width;
1589 g->geom.height = g->wp.height;
1590 g->geom.x = g->wp.x;
1591 g->geom.y = g->wp.y;
1593 g->x_axis->min = g->y_axis->min = 0;
1594 gtk_toggle_button_set_active (g->gui.time_orig_conn, TRUE);
1595 gtk_toggle_button_set_active (g->gui.seq_orig_isn, TRUE);
1596 graph_init_sequence (g);
1599 static void callback_graph_init_on_typechg (GtkWidget *toggle _U_, gpointer data)
1601 ((struct graph * )data)->flags ^= GRAPH_INIT_ON_TYPE_CHANGE;
1604 static struct graph *graph_new (void)
1608 g = (struct graph * )g_malloc0 (sizeof (struct graph));
1609 graph_element_lists_initialize (g);
1611 g->x_axis = (struct axis * )g_malloc0 (sizeof (struct axis));
1612 g->y_axis = (struct axis * )g_malloc0 (sizeof (struct axis));
1614 g->x_axis->flags = 0;
1615 g->x_axis->flags |= AXIS_ORIENTATION;
1616 g->x_axis->s.x = g->x_axis->s.y = 0;
1617 g->x_axis->s.height = HAXIS_INIT_HEIGHT;
1618 g->x_axis->p.x = VAXIS_INIT_WIDTH;
1619 g->x_axis->p.height = HAXIS_INIT_HEIGHT;
1621 g->y_axis->flags = 0;
1622 g->y_axis->flags &= ~AXIS_ORIENTATION;
1623 g->y_axis->p.x = g->y_axis->p.y = 0;
1624 g->y_axis->p.width = VAXIS_INIT_WIDTH;
1626 g->y_axis->s.y = TITLEBAR_HEIGHT;
1627 g->y_axis->s.width = VAXIS_INIT_WIDTH;
1632 static void graph_initialize_values (struct graph *g)
1634 g->geom.width = g->wp.width = 750;
1635 g->geom.height = g->wp.height = 550;
1636 g->geom.x = g->wp.x = VAXIS_INIT_WIDTH;
1637 g->geom.y = g->wp.y = TITLEBAR_HEIGHT;
1639 /* g->zoom.x = g->zoom.y = 1.0; */
1640 g->zoom.step_x = g->zoom.step_y = 1.2;
1642 g->cross.draw = g->cross.erase_needed = 0;
1643 g->grab.grabbed = 0;
1644 g->magnify.active = 0;
1645 g->magnify.offset.x = g->magnify.offset.y = 0;
1646 g->magnify.width = g->magnify.height = 250;
1647 g->magnify.zoom.x = g->magnify.zoom.y = 10.0;
1648 g->magnify.flags = 0;
1651 static void graph_put (struct graph *graph)
1655 for (g=graphs; g->next; g=g->next);
1661 static void graph_init_sequence (struct graph *g)
1663 debug(DBS_FENTRY) puts ("graph_init_sequence()");
1665 graph_type_dependent_initialize (g);
1666 g->zoom.initial.x = g->zoom.x;
1667 g->zoom.initial.y = g->zoom.y;
1668 graph_element_lists_make (g);
1669 g->x_axis->s.width = g->wp.width;
1670 g->x_axis->p.width = g->x_axis->s.width + RMARGIN_WIDTH;
1671 g->x_axis->p.y = TITLEBAR_HEIGHT + g->wp.height;
1672 g->x_axis->s.height = g->x_axis->p.height = HAXIS_INIT_HEIGHT;
1673 g->y_axis->s.height = g->wp.height;
1674 g->y_axis->p.height = g->wp.height + TITLEBAR_HEIGHT;
1675 graph_pixmaps_create (g);
1676 axis_pixmaps_create (g->y_axis);
1677 axis_pixmaps_create (g->x_axis);
1678 graph_title_pixmap_create (g);
1679 graph_title_pixmap_draw (g);
1680 graph_title_pixmap_display (g);
1682 axis_display (g->y_axis);
1683 axis_display (g->x_axis);
1686 static void graph_type_dependent_initialize (struct graph *g)
1689 case GRAPH_TSEQ_STEVENS:
1690 case GRAPH_TSEQ_TCPTRACE:
1691 tseq_stevens_initialize (g);
1693 case GRAPH_THROUGHPUT:
1694 tput_initialize (g);
1704 static void graph_destroy (struct graph *g)
1707 struct graph *p=NULL;
1708 /* struct graph *tmp; */
1710 debug(DBS_FENTRY) puts ("graph_destroy()");
1712 for (gtmp=graphs; gtmp; p=gtmp, gtmp=gtmp->next)
1716 axis_destroy (g->x_axis);
1717 axis_destroy (g->y_axis);
1718 /* window_destroy (g->drawing_area); */
1719 window_destroy (g->gui.control_panel);
1720 window_destroy (g->toplevel);
1721 /* window_destroy (g->text); */
1722 gdk_gc_unref (g->fg_gc);
1723 gdk_gc_unref (g->bg_gc);
1724 #if GTK_MAJOR_VERSION < 2
1725 gdk_font_unref (g->font);
1727 gdk_pixmap_unref (g->pixmap[0]);
1728 gdk_pixmap_unref (g->pixmap[1]);
1731 g_free ( (gpointer) (g->title) );
1732 graph_segment_list_free (g);
1733 graph_element_lists_free (g);
1735 for (tmp=graphs; tmp; tmp=tmp->next)
1736 printf ("%p next: %p\n", tmp, tmp->next);
1737 printf ("p=%p, g=%p, p->next=%p, g->next=%p\n",
1738 p, g, p ? p->next : NULL, g->next);
1746 for (tmp=graphs; tmp; tmp=tmp->next)
1747 printf ("%p next: %p\n", tmp, tmp->next);
1752 typedef struct _tcp_scan_t {
1753 struct segment *current;
1756 struct segment *last;
1760 tapall_tcpip_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
1762 static struct segment *segment=NULL;
1763 tcp_scan_t *ts=(tcp_scan_t *)pct;
1764 struct tcpheader *tcphdr=(struct tcpheader *)vip;
1767 segment=g_malloc(sizeof (struct segment));
1769 perror ("malloc failed");
1774 if (compare_headers(&ts->current->ip_src, &ts->current->ip_dst,
1775 ts->current->th_sport, ts->current->th_dport,
1776 &tcphdr->ip_src, &tcphdr->ip_dst,
1777 tcphdr->th_sport, tcphdr->th_dport,
1779 segment->next = NULL;
1780 segment->num = pinfo->fd->num;
1781 segment->rel_secs = pinfo->fd->rel_ts.secs;
1782 segment->rel_usecs = pinfo->fd->rel_ts.nsecs/1000;
1783 segment->abs_secs = pinfo->fd->abs_ts.secs;
1784 segment->abs_usecs = pinfo->fd->abs_ts.nsecs/1000;
1785 segment->th_seq=tcphdr->th_seq;
1786 segment->th_ack=tcphdr->th_ack;
1787 segment->th_win=tcphdr->th_win;
1788 segment->th_flags=tcphdr->th_flags;
1789 segment->th_sport=tcphdr->th_sport;
1790 segment->th_dport=tcphdr->th_dport;
1791 segment->th_seglen=tcphdr->th_seglen;
1792 COPY_ADDRESS(&segment->ip_src, &tcphdr->ip_src);
1793 COPY_ADDRESS(&segment->ip_dst, &tcphdr->ip_dst);
1794 if (ts->g->segments) {
1795 ts->last->next = segment;
1797 ts->g->segments = segment;
1800 if(pinfo->fd->num==ts->current->num){
1801 ts->g->current = segment;
1812 /* here we collect all the external data we will ever need */
1813 static void graph_segment_list_get (struct graph *g)
1815 struct segment current;
1816 GString *error_string;
1820 debug(DBS_FENTRY) puts ("graph_segment_list_get()");
1821 select_tcpip_session (&cfile, ¤t);
1822 if (g->type == GRAPH_THROUGHPUT)
1823 ts.direction = COMPARE_CURR_DIR;
1825 ts.direction = COMPARE_ANY_DIR;
1827 /* rescan all the packets and pick up all interesting tcp headers.
1828 * we only filter for TCP here for speed and do the actual compare
1829 * in the tap listener
1831 ts.current=¤t;
1834 error_string=register_tap_listener("tcp", &ts, "tcp", NULL, tapall_tcpip_packet, NULL);
1836 fprintf(stderr, "ethereal: Couldn't register tcp_graph tap: %s\n",
1838 g_string_free(error_string, TRUE);
1841 cf_retap_packets(&cfile, FALSE);
1842 remove_tap_listener(&ts);
1846 typedef struct _th_t {
1848 struct tcpheader *tcphdr;
1852 tap_tcpip_packet(void *pct, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *vip)
1857 th->tcphdr=(struct tcpheader *)vip;
1864 /* XXX should be enhanced so that if we have multiple TCP layers in the trace
1865 * then present the user with a dialog where the user can select WHICH tcp
1868 static struct tcpheader *select_tcpip_session (capture_file *cf, struct segment *hdrs)
1873 epan_dissect_t *edt;
1875 GString *error_string;
1876 th_t th = {0, NULL};
1878 fdata = cf->current_frame;
1880 /* no real filter yet */
1881 if (!dfilter_compile("tcp", &sfcode)) {
1882 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
1886 /* dissect the current frame */
1887 if (!wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header,
1888 cf->pd, fdata->cap_len, &err, &err_info)) {
1889 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1890 cf_read_error_message(err, err_info), cf->filename);
1895 error_string=register_tap_listener("tcp", &th, NULL, NULL, tap_tcpip_packet, NULL);
1897 fprintf(stderr, "ethereal: Couldn't register tcp_graph tap: %s\n",
1899 g_string_free(error_string, TRUE);
1903 edt = epan_dissect_new(TRUE, FALSE);
1904 epan_dissect_prime_dfilter(edt, sfcode);
1905 tap_queue_init(edt);
1906 epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL);
1907 tap_push_tapped_queue(edt);
1908 epan_dissect_free(edt);
1909 remove_tap_listener(&th);
1912 /* This "shouldn't happen", as our menu items shouldn't
1913 * even be enabled if the selected packet isn't a TCP
1914 * segment, as tcp_graph_selected_packet_enabled() is used
1915 * to determine whether to enable any of our menu items. */
1916 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1917 "Selected packet isn't a TCP segment");
1920 /* XXX fix this later, we should show a dialog allowing the user
1921 to select which session he wants here
1924 /* can only handle a single tcp layer yet */
1925 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1926 "The selected packet has more than one TCP"
1931 hdrs->num = fdata->num;
1932 hdrs->rel_secs = fdata->rel_ts.secs;
1933 hdrs->rel_usecs = fdata->rel_ts.nsecs/1000;
1934 hdrs->abs_secs = fdata->abs_ts.secs;
1935 hdrs->abs_usecs = fdata->abs_ts.nsecs/1000;
1936 hdrs->th_seq=th.tcphdr->th_seq;
1937 hdrs->th_ack=th.tcphdr->th_ack;
1938 hdrs->th_win=th.tcphdr->th_win;
1939 hdrs->th_flags=th.tcphdr->th_flags;
1940 hdrs->th_sport=th.tcphdr->th_sport;
1941 hdrs->th_dport=th.tcphdr->th_dport;
1942 hdrs->th_seglen=th.tcphdr->th_seglen;
1943 COPY_ADDRESS(&hdrs->ip_src, &th.tcphdr->ip_src);
1944 COPY_ADDRESS(&hdrs->ip_dst, &th.tcphdr->ip_dst);
1949 static int compare_headers (address *saddr1, address *daddr1, guint16 sport1, guint16 dport1, address *saddr2, address *daddr2, guint16 sport2, guint16 dport2, int dir)
1953 dir1 = ((!(CMP_ADDRESS(saddr1, saddr2))) &&
1954 (!(CMP_ADDRESS(daddr1, daddr2))) &&
1958 if(dir==COMPARE_CURR_DIR){
1961 dir2 = ((!(CMP_ADDRESS(saddr1, daddr2))) &&
1962 (!(CMP_ADDRESS(daddr1, saddr2))) &&
1965 return dir1 || dir2;
1969 static void graph_segment_list_free (struct graph *g)
1971 struct segment *segment;
1973 while (g->segments) {
1974 segment = g->segments->next;
1975 g_free (g->segments);
1976 g->segments = segment;
1981 static void graph_element_lists_initialize (struct graph *g)
1983 g->elists = (struct element_list *)g_malloc0 (sizeof (struct element_list));
1986 static void graph_element_lists_make (struct graph *g)
1988 debug(DBS_FENTRY) puts ("graph_element_lists_make()");
1991 case GRAPH_TSEQ_STEVENS:
1992 tseq_stevens_make_elmtlist (g);
1994 case GRAPH_TSEQ_TCPTRACE:
1995 tseq_tcptrace_make_elmtlist (g);
1997 case GRAPH_THROUGHPUT:
1998 tput_make_elmtlist (g);
2001 rtt_make_elmtlist (g);
2004 printf ("graph_element_lists_make: unknown graph type: %d\n", g->type);
2009 static void graph_element_lists_free (struct graph *g)
2011 struct element_list *list, *next_list;
2014 for (list=g->elists; list; list=list->next)
2015 g_free (list->elements);
2016 while (g->elists->next) {
2017 list = g->elists->next->next;
2018 g_free (g->elists->next);
2019 g->elists->next = list;
2023 for (list=g->elists; list; list=next_list) {
2024 g_free (list->elements);
2025 next_list = list->next;
2028 g->elists = NULL; /* just to make debugging easier */
2031 static void graph_title_pixmap_create (struct graph *g)
2033 if (g->title_pixmap)
2034 gdk_pixmap_unref (g->title_pixmap);
2036 g->title_pixmap = gdk_pixmap_new (g->drawing_area->window,
2037 g->x_axis->p.width, g->wp.y, -1);
2040 static void graph_title_pixmap_draw (struct graph *g)
2044 gdk_draw_rectangle(g->title_pixmap, g->bg_gc, TRUE, 0, 0,
2045 g->x_axis->p.width, g->wp.y);
2046 for (i=0; g->title[i]; i++) {
2048 #if GTK_MAJOR_VERSION < 2
2049 w = gdk_string_width(g->font, g->title[i]);
2050 h = gdk_string_height(g->font, g->title[i]);
2051 gdk_draw_string(g->title_pixmap, g->font, g->fg_gc,
2052 g->wp.width/2 - w/2, 20+h + i*(h+3),
2055 PangoLayout *layout;
2056 layout = gtk_widget_create_pango_layout(g->drawing_area,
2058 pango_layout_get_pixel_size(layout, &w, &h);
2059 gdk_draw_layout(g->title_pixmap, g->fg_gc,
2060 g->wp.width/2 - w/2, 20 + i*(h+3), layout);
2061 g_object_unref(G_OBJECT(layout));
2066 static void graph_title_pixmap_display (struct graph *g)
2068 gdk_draw_pixmap (g->drawing_area->window, g->fg_gc, g->title_pixmap,
2069 0, 0, g->wp.x, 0, g->x_axis->p.width, g->wp.y);
2072 static void graph_pixmaps_create (struct graph *g)
2074 debug(DBS_FENTRY) puts ("graph_pixmaps_create()");
2077 gdk_pixmap_unref (g->pixmap[0]);
2079 gdk_pixmap_unref (g->pixmap[1]);
2081 g->pixmap[0] = gdk_pixmap_new (g->drawing_area->window,
2082 g->wp.width, g->wp.height, -1);
2083 g->pixmap[1] = gdk_pixmap_new (g->drawing_area->window,
2084 g->wp.width, g->wp.height, -1);
2089 static void graph_display (struct graph *g)
2091 graph_pixmap_draw (g);
2092 graph_pixmaps_switch (g);
2093 graph_pixmap_display (g);
2096 static void graph_pixmap_display (struct graph *g)
2098 gdk_draw_pixmap (g->drawing_area->window, g->fg_gc,
2099 g->pixmap[g->displayed], 0, 0, g->wp.x, g->wp.y,
2100 g->wp.width, g->wp.height);
2101 if (g->cross.erase_needed) {
2102 cross_xor(g, g->cross.x, g->cross.y);
2106 static void graph_pixmaps_switch (struct graph *g)
2108 g->displayed = 1 ^ g->displayed;
2111 static void graph_pixmap_draw (struct graph *g)
2113 struct element_list *list;
2117 debug(DBS_FENTRY) puts ("graph_display()");
2118 not_disp = 1 ^ g->displayed;
2120 gdk_draw_rectangle (g->pixmap[not_disp], g->bg_gc, TRUE,
2121 0, 0, g->wp.width, g->wp.height);
2123 for (list=g->elists; list; list=list->next)
2124 for (e=list->elements; e->type != ELMT_NONE; e++) {
2129 draw_element_line (g, e);
2132 draw_element_arc (g, e);
2140 static void draw_element_line (struct graph *g, struct element *e)
2144 debug(DBS_GRAPH_DRAWING) printf ("line element: (%.2f,%.2f)->(%.2f,%.2f), "
2145 "seg %d ... ", e->p.line.dim.x1, e->p.line.dim.y1,
2146 e->p.line.dim.x2, e->p.line.dim.y2, e->parent->num);
2147 x1 = (int )rint (e->p.line.dim.x1 + g->geom.x - g->wp.x);
2148 x2 = (int )rint (e->p.line.dim.x2 + g->geom.x - g->wp.x);
2149 y1 = (int )rint ((g->geom.height-1-e->p.line.dim.y1) + g->geom.y-g->wp.y);
2150 y2 = (int )rint ((g->geom.height-1-e->p.line.dim.y2) + g->geom.y-g->wp.y);
2161 if ((x1<0 && x2<0) || (x1>=g->wp.width && x2>=g->wp.width) ||
2162 (y1<0 && y2<0) || (y1>=g->wp.height && y2>=g->wp.height)) {
2163 debug(DBS_GRAPH_DRAWING) printf (" refusing: (%d,%d)->(%d,%d)\n",
2167 if (x2 > g->wp.width-1)
2171 if (y2 > g->wp.height-1)
2172 y2 = g->wp.height-1;
2175 debug(DBS_GRAPH_DRAWING) printf ("line: (%d,%d)->(%d,%d)\n", x1, y1, x2,y2);
2176 gdk_draw_line (g->pixmap[1^g->displayed], e->gc, x1, y1, x2, y2);
2179 static void draw_element_arc (struct graph *g, struct element *e)
2183 x1 = (int )rint (e->p.arc.dim.x + g->geom.x - g->wp.x);
2184 x2 = (int )e->p.arc.dim.width;
2185 y1 = (int )rint (g->geom.height-1 - e->p.arc.dim.y + g->geom.y - g->wp.y);
2186 y2 = (int )e->p.arc.dim.height;
2187 if (x1<-x2 || x1>=g->wp.width || y1<-y2 || y1>=g->wp.height)
2189 debug(DBS_GRAPH_DRAWING) printf ("arc: (%d,%d)->(%d,%d)\n", x1, y1, x2, y2);
2190 gdk_draw_arc (g->pixmap[1^g->displayed], e->gc, e->p.arc.filled, x1,
2191 y1, x2, y2, e->p.arc.angle1, e->p.arc.angle2);
2194 static void axis_pixmaps_create (struct axis *axis)
2196 debug(DBS_FENTRY) puts ("axis_pixmaps_create()");
2197 if (axis->pixmap[0])
2198 gdk_pixmap_unref (axis->pixmap[0]);
2199 if (axis->pixmap[1])
2200 gdk_pixmap_unref (axis->pixmap[1]);
2202 axis->pixmap[0] = gdk_pixmap_new (axis->drawing_area->window,
2203 axis->p.width, axis->p.height, -1);
2204 axis->pixmap[1] = gdk_pixmap_new (axis->drawing_area->window,
2205 axis->p.width, axis->p.height, -1);
2207 axis->displayed = 0;
2210 static void axis_destroy (struct axis *axis)
2212 gdk_pixmap_unref (axis->pixmap[0]);
2213 gdk_pixmap_unref (axis->pixmap[1]);
2214 g_free ( (gpointer) (axis->label) );
2217 static void axis_display (struct axis *axis)
2219 if (axis->flags & AXIS_ORIENTATION)
2220 h_axis_pixmap_draw (axis);
2222 v_axis_pixmap_draw (axis);
2223 axis_pixmaps_switch (axis);
2224 axis_pixmap_display (axis);
2227 static void v_axis_pixmap_draw (struct axis *axis)
2229 struct graph *g = axis->g;
2232 int not_disp, rdigits, offset, imin, imax;
2233 double bottom, top, j, fl, corr;
2234 #if GTK_MAJOR_VERSION >= 2
2235 PangoLayout *layout;
2238 debug(DBS_FENTRY) puts ("v_axis_pixmap_draw()");
2239 bottom = (g->geom.height - (g->wp.height + g->wp.y + (-g->geom.y))) /
2240 (double )g->geom.height * g->bounds.height;
2241 bottom += axis->min;
2242 top = (g->geom.height - (g->wp.y + (-g->geom.y))) /
2243 (double )g->geom.height * g->bounds.height;
2245 axis_compute_ticks (axis, bottom, top, AXIS_VERTICAL);
2247 j = axis->major - floor (axis->major);
2248 for (rdigits=0; rdigits<=6; rdigits++) {
2255 not_disp = 1 ^ axis->displayed;
2256 gdk_draw_rectangle (axis->pixmap[not_disp], g->bg_gc, TRUE, 0, 0,
2257 axis->p.width, axis->p.height);
2259 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc, axis->p.width - 1,
2260 (gint) ((axis->p.height-axis->s.height)/2.0), axis->s.width - 1,
2263 offset = g->wp.y + (-g->geom.y);
2264 fl = floor (axis->min / axis->major) * axis->major;
2265 corr = rint ((axis->min - fl) * g->zoom.y);
2268 major_tick = axis->major * g->zoom.y;
2269 imin = (int) ((g->geom.height - offset + corr - g->wp.height) / major_tick + 1);
2270 imax = (int) ((g->geom.height - offset + corr) / major_tick);
2271 for (i=imin; i <= imax; i++) {
2274 int y = (int) (g->geom.height-1 - (int )rint (i * major_tick) -
2275 offset + corr + axis->s.y);
2277 debug(DBS_AXES_DRAWING) printf("%f @ %d\n",
2278 i*axis->major + fl, y);
2279 if (y < 0 || y > axis->p.height)
2281 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc,
2282 axis->s.width - 15, y, axis->s.width - 1, y);
2283 g_snprintf (desc, 32, "%.*f", rdigits, i*axis->major + fl);
2284 #if GTK_MAJOR_VERSION < 2
2285 w = gdk_string_width(g->font, desc);
2286 h = gdk_string_height(g->font, desc);
2287 gdk_draw_string(axis->pixmap[not_disp], g->font, g->fg_gc,
2288 axis->s.width-15-4-w, y + h/2, desc);
2290 layout = gtk_widget_create_pango_layout(g->drawing_area, desc);
2291 pango_layout_get_pixel_size(layout, &w, &h);
2292 gdk_draw_layout(axis->pixmap[not_disp], g->fg_gc,
2293 axis->s.width-14-4-w, y - h/2, layout);
2294 g_object_unref(G_OBJECT(layout));
2299 double minor_tick = axis->minor * g->zoom.y;
2300 imin = (int) ((g->geom.height - offset + corr - g->wp.height)/minor_tick + 1);
2301 imax = (int) ((g->geom.height - offset + corr) / minor_tick);
2302 for (i=imin; i <= imax; i++) {
2303 int y = (int) (g->geom.height-1 - (int )rint (i*minor_tick) -
2304 offset + corr + axis->s.y);
2306 debug (DBS_AXES_DRAWING) printf ("%f @ %d\n", i*axis->minor+fl, y);
2307 if (y > 0 && y < axis->p.height)
2308 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc,
2309 axis->s.width - 8, y,
2310 axis->s.width - 1, y);
2313 for (i=0; axis->label[i]; i++) {
2315 #if GTK_MAJOR_VERSION < 2
2316 w = gdk_string_width (g->font, axis->label[i]);
2317 h = gdk_string_height (g->font, axis->label[i]);
2318 gdk_draw_string(axis->pixmap[not_disp], g->font, g->fg_gc,
2319 (axis->p.width - w)/2 ,
2320 TITLEBAR_HEIGHT-15 - i*(h+3), axis->label[i]);
2322 layout = gtk_widget_create_pango_layout(g->drawing_area,
2324 pango_layout_get_pixel_size(layout, &w, &h);
2325 gdk_draw_layout(axis->pixmap[not_disp], g->fg_gc,
2326 (axis->p.width - w)/2,
2327 TITLEBAR_HEIGHT-10 - i*(h+3) - h,
2329 g_object_unref(G_OBJECT(layout));
2334 static void h_axis_pixmap_draw (struct axis *axis)
2336 struct graph *g = axis->g;
2338 double major_tick, minor_tick;
2339 int not_disp, rdigits, offset, imin, imax;
2340 double left, right, j, fl, corr;
2341 #if GTK_MAJOR_VERSION >= 2
2342 PangoLayout *layout;
2345 debug(DBS_FENTRY) puts ("h_axis_pixmap_draw()");
2346 left = (g->wp.x-g->geom.x) /
2347 (double )g->geom.width * g->bounds.width;
2349 right = (g->wp.x-g->geom.x+g->wp.width) /
2350 (double )g->geom.width * g->bounds.width;
2352 axis_compute_ticks (axis, left, right, AXIS_HORIZONTAL);
2354 j = axis->major - floor (axis->major);
2355 for (rdigits=0; rdigits<=6; rdigits++) {
2362 not_disp = 1 ^ axis->displayed;
2363 gdk_draw_rectangle (axis->pixmap[not_disp], g->bg_gc, TRUE, 0, 0,
2364 axis->p.width, axis->p.height);
2366 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc, 0, 0,
2367 (gint) (axis->s.width + (axis->p.width-axis->s.width)/2.0), 0);
2368 offset = g->wp.x - g->geom.x;
2370 fl = floor (axis->min / axis->major) * axis->major;
2371 corr = rint ((axis->min - fl) * g->zoom.x);
2374 major_tick = axis->major*g->zoom.x;
2375 imin = (int) ((offset + corr) / major_tick + 1);
2376 imax = (int) ((offset + corr + axis->s.width) / major_tick);
2377 for (i=imin; i <= imax; i++) {
2380 int x = (int ) (rint (i * major_tick) - offset - corr);
2382 /* printf ("%f @ %d\n", i*axis->major + fl, x); */
2383 if (x < 0 || x > axis->s.width)
2385 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc, x, 0, x, 15);
2386 g_snprintf (desc, 32, "%.*f", rdigits, i*axis->major + fl);
2387 #if GTK_MAJOR_VERSION < 2
2388 w = gdk_string_width (g->font, desc);
2389 h = gdk_string_height (g->font, desc);
2390 gdk_draw_string (axis->pixmap[not_disp], g->font, g->fg_gc,
2391 x - w/2, 15+h+4, desc);
2393 layout = gtk_widget_create_pango_layout(g->drawing_area, desc);
2394 pango_layout_get_pixel_size(layout, &w, &h);
2395 gdk_draw_layout(axis->pixmap[not_disp], g->fg_gc,
2396 x - w/2, 15+4, layout);
2397 g_object_unref(G_OBJECT(layout));
2400 if (axis->minor > 0) {
2402 minor_tick = axis->minor*g->zoom.x;
2403 imin = (int) ((offset + corr) / minor_tick + 1);
2404 imax = (int) ((offset + corr + g->wp.width) / minor_tick);
2405 for (i=imin; i <= imax; i++) {
2406 int x = (int) (rint (i * minor_tick) - offset - corr);
2407 if (x > 0 && x < axis->s.width)
2408 gdk_draw_line (axis->pixmap[not_disp], g->fg_gc, x, 0, x, 8);
2411 for (i=0; axis->label[i]; i++) {
2413 #if GTK_MAJOR_VERSION < 2
2414 w = gdk_string_width (g->font, axis->label[i]);
2415 h = gdk_string_height (g->font, axis->label[i]);
2416 gdk_draw_string(axis->pixmap[not_disp], g->font, g->fg_gc,
2417 axis->s.width - w - 50, 15+2*h+15 + i*(h+3),
2420 layout = gtk_widget_create_pango_layout(g->drawing_area,
2422 pango_layout_get_pixel_size(layout, &w, &h);
2423 gdk_draw_layout(axis->pixmap[not_disp], g->fg_gc,
2424 axis->s.width - w - 50, 15+h+15 + i*(h+3),
2426 g_object_unref(G_OBJECT(layout));
2431 static void axis_pixmaps_switch (struct axis *axis)
2433 axis->displayed = 1 ^ axis->displayed;
2436 static void axis_pixmap_display (struct axis *axis)
2438 gdk_draw_pixmap (axis->drawing_area->window, axis->g->fg_gc,
2439 axis->pixmap[axis->displayed], 0, 0, axis->p.x, axis->p.y,
2440 axis->p.width, axis->p.height);
2443 static void axis_compute_ticks (struct axis *axis, double x0, double xmax, int dir)
2445 int i, j, ii, jj, ms;
2446 double zoom, x, steps[3]={ 0.1, 0.5 };
2447 int dim, check_needed, diminished;
2448 double majthresh[2]={2.0, 3.0};
2450 debug((DBS_FENTRY | DBS_AXES_TICKS)) puts ("axis_compute_ticks()");
2451 debug(DBS_AXES_TICKS)
2452 printf ("x0=%f xmax=%f dir=%s\n", x0,xmax, dir?"VERTICAL":"HORIZONTAL");
2454 zoom = axis_zoom_get (axis, dir);
2456 for (i=-9; i<=12; i++) {
2457 if (x / pow (10, i) < 1)
2461 ms = (int )(x / pow (10, i));
2471 axis->major = steps[j] * pow (10, i);
2473 debug(DBS_AXES_TICKS) printf ("zoom=%.1f, x=%f -> i=%d -> ms=%d -> j=%d ->"
2474 " axis->major=%f\n", zoom, x, i, ms, j, axis->major);
2476 /* let's compute minor ticks */
2479 axis_ticks_down (&ii, &jj);
2480 axis->minor = steps[jj] * pow (10, ii);
2481 /* we don't want minors if they would be less than 10 pixels apart */
2482 if (axis->minor*zoom < 10) {
2483 debug(DBS_AXES_TICKS) printf ("refusing axis->minor of %f: "
2484 "axis->minor*zoom == %f\n", axis->minor, axis->minor*zoom);
2488 check_needed = TRUE;
2490 while (check_needed) {
2491 check_needed = FALSE;
2492 dim = get_label_dim (axis, dir, xmax);
2493 debug(DBS_AXES_TICKS) printf ("axis->major==%.1f, axis->minor==%.1f =>"
2494 " axis->major*zoom/dim==%f, axis->minor*zoom/dim==%f\n",
2495 axis->major, axis->minor, axis->major*zoom/dim,
2496 axis->minor*zoom/dim);
2498 /* corrections: if majors are less than majthresh[dir] times label
2499 * dimension apart, we need to use bigger ones */
2500 if (axis->major*zoom / dim < majthresh[dir]) {
2501 axis_ticks_up (&ii, &jj);
2502 axis->minor = axis->major;
2503 axis_ticks_up (&i, &j);
2504 axis->major = steps[j] * pow (10, i);
2505 check_needed = TRUE;
2506 debug(DBS_AXES_TICKS) printf ("axis->major enlarged to %.1f\n",
2509 /* if minor ticks are bigger than majthresh[dir] times label dimension,
2510 * we could promote them to majors as well */
2511 if (axis->minor*zoom / dim > majthresh[dir] && !diminished) {
2512 axis_ticks_down (&i, &j);
2513 axis->major = axis->minor;
2514 axis_ticks_down (&ii, &jj);
2515 axis->minor = steps[jj] * pow (10, ii);
2516 check_needed = TRUE;
2519 debug(DBS_AXES_TICKS) printf ("axis->minor diminished to %.1f\n",
2522 if (axis->minor*zoom < 10) {
2523 debug(DBS_AXES_TICKS) printf ("refusing axis->minor of %f: "
2524 "axis->minor*zoom == %f\n", axis->minor, axis->minor*zoom);
2530 debug(DBS_AXES_TICKS) printf ("corrected: axis->major == %.1f -> "
2531 "axis->minor == %.1f\n", axis->major, axis->minor);
2534 static void axis_ticks_up (int *i, int *j)
2543 static void axis_ticks_down (int *i, int *j)
2552 static int get_label_dim (struct axis *axis, int dir, double label)
2557 #if GTK_MAJOR_VERSION >= 2
2558 PangoLayout *layout;
2561 /* First, let's compute how many digits to the right of radix
2562 * we need to print */
2563 y = axis->major - floor (axis->major);
2564 for (rdigits=0; rdigits<=6; rdigits++) {
2570 g_snprintf (str, 32, "%.*f", rdigits, label);
2572 case AXIS_HORIZONTAL:
2573 #if GTK_MAJOR_VERSION < 2
2574 dim = gdk_string_width(axis->g->font, str);
2576 layout = gtk_widget_create_pango_layout(axis->g->drawing_area,
2578 pango_layout_get_pixel_size(layout, &dim, NULL);
2579 g_object_unref(G_OBJECT(layout));
2583 #if GTK_MAJOR_VERSION < 2
2584 dim = gdk_string_height(axis->g->font, str);
2586 layout = gtk_widget_create_pango_layout(axis->g->drawing_area,
2588 pango_layout_get_pixel_size(layout, NULL, &dim);
2589 g_object_unref(G_OBJECT(layout));
2593 puts ("initialize axis: an axis must be either horizontal or vertical");
2600 static double axis_zoom_get (struct axis *axis, int dir)
2603 case AXIS_HORIZONTAL:
2604 return axis->g->zoom.x;
2607 return axis->g->zoom.y;
2615 static void graph_select_segment (struct graph *g, int x, int y)
2617 struct element_list *list;
2620 debug(DBS_FENTRY) puts ("graph_select_segment()");
2623 y = g->geom.height-1 - (y - g->geom.y);
2625 for (list=g->elists; list; list=list->next)
2626 for (e=list->elements; e->type != ELMT_NONE; e++) {
2631 if (line_detect_collision (e, x, y))
2632 cf_goto_frame(&cfile, e->parent->num);
2635 if (arc_detect_collision (e, x, y))
2636 cf_goto_frame(&cfile, e->parent->num);
2644 static int line_detect_collision (struct element *e, int x, int y)
2648 if (e->p.line.dim.x1 < e->p.line.dim.x2) {
2649 x1 = (int )rint (e->p.line.dim.x1);
2650 x2 = (int )rint (e->p.line.dim.x2);
2652 x1 = (int )rint (e->p.line.dim.x2);
2653 x2 = (int )rint (e->p.line.dim.x1);
2655 if (e->p.line.dim.y1 < e->p.line.dim.y2) {
2656 y1 = (int )rint (e->p.line.dim.y1);
2657 y2 = (int )rint (e->p.line.dim.y2);
2659 y1 = (int )rint (e->p.line.dim.y2);
2660 y2 = (int )rint (e->p.line.dim.y1);
2663 printf ("line: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", x1, y1, x2, y2, x, y);
2665 if ((x1==x && x2==x && y1<=y && y<=y2)||(y1==y && y2==y && x1<=x && x<=x2))
2671 static int arc_detect_collision (struct element *e, int x, int y)
2675 x1 = (int )rint (e->p.arc.dim.x);
2676 x2 = (int )rint (e->p.arc.dim.x + e->p.arc.dim.width);
2677 y1 = (int )rint (e->p.arc.dim.y - e->p.arc.dim.height);
2678 y2 = (int )rint (e->p.arc.dim.y);
2680 printf ("arc: (%d,%d)->(%d,%d), clicked: (%d,%d)\n", x1, y1, x2, y2, x, y);
2682 if (x1<=x && x<=x2 && y1<=y && y<=y2)
2688 static void cross_xor (struct graph *g, int x, int y)
2690 if (x > g->wp.x && x < g->wp.x+g->wp.width &&
2691 y >= g->wp.y && y < g->wp.y+g->wp.height) {
2692 gdk_draw_line (g->drawing_area->window, xor_gc, g->wp.x,
2693 y, g->wp.x + g->wp.width, y);
2694 gdk_draw_line (g->drawing_area->window, xor_gc, x,
2695 g->wp.y, x, g->wp.y + g->wp.height);
2699 static void cross_draw (struct graph *g, int x, int y)
2701 cross_xor (g, x, y);
2704 g->cross.erase_needed = 1;
2707 static void cross_erase (struct graph *g)
2709 cross_xor (g, g->cross.x, g->cross.y);
2710 g->cross.erase_needed = 0;
2713 static void magnify_create (struct graph *g, int x, int y)
2716 struct element_list *list, *new_list;
2717 struct ipoint pos, offsetpos;
2720 mg = g->magnify.g = (struct graph * )g_malloc (sizeof (struct graph));
2721 memcpy ((void * )mg, (void * )g, sizeof (struct graph));
2723 mg->toplevel = dlg_window_new("tcp graph magnify");
2724 mg->drawing_area = mg->toplevel;
2725 gtk_window_set_default_size(GTK_WINDOW(mg->toplevel), g->magnify.width, g->magnify.height);
2726 gtk_widget_set_events (mg->drawing_area, GDK_EXPOSURE_MASK
2727 /* | GDK_ENTER_NOTIFY_MASK */
2728 /* | GDK_ALL_EVENTS_MASK */
2733 mg->wp.width = g->magnify.width;
2734 mg->wp.height = g->magnify.height;
2735 mg->geom.width = (int )rint (g->geom.width * g->magnify.zoom.x);
2736 mg->geom.height = (int )rint (g->geom.height * g->magnify.zoom.y);
2737 mg->zoom.x = (mg->geom.width - 1) / g->bounds.width;
2738 mg->zoom.y = (mg->geom.height- 1) / g->bounds.height;
2740 /* in order to keep original element lists intact we need our own */
2741 graph_element_lists_initialize (mg);
2742 list = g->elists->next;
2743 new_list = mg->elists;
2744 for ( ; list; list=list->next) {
2746 (struct element_list * )g_malloc (sizeof (struct element_list));
2747 new_list = new_list->next;
2748 new_list->next = NULL;
2749 new_list->elements = NULL;
2751 graph_element_lists_make (mg);
2753 gdk_window_get_position (GTK_WIDGET (g->toplevel)->window, &pos.x, &pos.y);
2754 g->magnify.x = pos.x + x - g->magnify.width/2;
2755 g->magnify.y = pos.y + y - g->magnify.height/2;
2756 offsetpos.x = g->magnify.x + g->magnify.offset.x;
2757 offsetpos.x = offsetpos.x >= 0 ? offsetpos.x : 0;
2758 offsetpos.y = g->magnify.y + g->magnify.offset.y;
2759 offsetpos.y = offsetpos.y >= 0 ? offsetpos.y : 0;
2760 gtk_widget_set_uposition (mg->drawing_area, offsetpos.x, offsetpos.y);
2761 magnify_get_geom (g, x, y);
2763 gtk_widget_show (mg->drawing_area);
2765 /* we need to wait for the first expose event before we start drawing */
2766 while (!gdk_events_pending ());
2768 e = gdk_event_get ();
2770 if (e->any.type == GDK_EXPOSE) {
2778 mg->pixmap[0] = mg->pixmap[1] = NULL;
2779 graph_pixmaps_create (mg);
2781 g->magnify.active = 1;
2784 static void magnify_move (struct graph *g, int x, int y)
2786 struct ipoint pos, offsetpos;
2788 gdk_window_get_position (GTK_WIDGET (g->toplevel)->window, &pos.x, &pos.y);
2789 g->magnify.x = pos.x + x - g->magnify.width/2;
2790 g->magnify.y = pos.y + y - g->magnify.height/2;
2791 offsetpos.x = g->magnify.x + g->magnify.offset.x;
2792 offsetpos.x = offsetpos.x >= 0 ? offsetpos.x : 0;
2793 offsetpos.y = g->magnify.y + g->magnify.offset.y;
2794 offsetpos.y = offsetpos.y >= 0 ? offsetpos.y : 0;
2795 magnify_get_geom (g, x, y);
2796 gtk_widget_set_uposition (g->magnify.g->drawing_area, offsetpos.x,
2801 static void magnify_destroy (struct graph *g)
2803 struct element_list *list;
2804 struct graph *mg = g->magnify.g;
2806 window_destroy (GTK_WIDGET (mg->drawing_area));
2807 gdk_pixmap_unref (mg->pixmap[0]);
2808 gdk_pixmap_unref (mg->pixmap[1]);
2809 for (list=mg->elists; list; list=list->next)
2810 g_free (list->elements);
2811 while (mg->elists->next) {
2812 list = mg->elists->next->next;
2813 g_free (mg->elists->next);
2814 mg->elists->next = list;
2816 g_free (g->magnify.g);
2817 g->magnify.active = 0;
2820 static void magnify_get_geom (struct graph *g, int x, int y)
2824 gdk_window_get_position (GTK_WIDGET (g->toplevel)->window, &posx, &posy);
2826 g->magnify.g->geom.x = g->geom.x;
2827 g->magnify.g->geom.y = g->geom.y;
2829 g->magnify.g->geom.x -=
2830 (int )rint ((g->magnify.g->geom.width - g->geom.width) *
2831 ((x-g->geom.x)/(double )g->geom.width));
2832 g->magnify.g->geom.y -=
2833 (int )rint ((g->magnify.g->geom.height - g->geom.height) *
2834 ((y-g->geom.y)/(double )g->geom.height));
2836 /* we have coords of origin of graph relative to origin of g->toplevel.
2837 * now we need them to relate to origin of magnify window */
2838 g->magnify.g->geom.x -= (g->magnify.x - posx);
2839 g->magnify.g->geom.y -= (g->magnify.y - posy);
2842 static void magnify_draw (struct graph *g)
2844 int not_disp = 1 ^ g->magnify.g->displayed;
2846 graph_pixmap_draw (g->magnify.g);
2847 /* graph pixmap is almost ready, just add border */
2848 gdk_draw_line (g->magnify.g->pixmap[not_disp], g->fg_gc, 0, 0,
2849 g->magnify.width - 1, 0);
2850 gdk_draw_line (g->magnify.g->pixmap[not_disp], g->fg_gc,
2851 g->magnify.width - 1, 0, g->magnify.width - 1, g->magnify.height);
2852 gdk_draw_line (g->magnify.g->pixmap[not_disp], g->fg_gc, 0, 0,
2853 0, g->magnify.height - 1);
2854 gdk_draw_line (g->magnify.g->pixmap[not_disp], g->fg_gc, 0,
2855 g->magnify.height - 1, g->magnify.width - 1, g->magnify.height - 1);
2857 graph_pixmaps_switch (g->magnify.g);
2858 graph_pixmap_display (g->magnify.g);
2862 static gint configure_event (GtkWidget *widget, GdkEventConfigure *event)
2868 int cur_g_width, cur_g_height;
2869 int cur_wp_width, cur_wp_height;
2871 debug(DBS_FENTRY) puts ("configure_event()");
2873 for (g=graphs; g; g=g->next)
2874 if (g->drawing_area == widget)
2877 cur_wp_width = g->wp.width;
2878 cur_wp_height = g->wp.height;
2879 g->wp.width = event->width - g->y_axis->p.width - RMARGIN_WIDTH;
2880 g->wp.height = event->height - g->x_axis->p.height - g->wp.y;
2881 g->x_axis->s.width = g->wp.width;
2882 g->x_axis->p.width = g->wp.width + RMARGIN_WIDTH;
2883 g->y_axis->p.height = g->wp.height + g->wp.y;
2884 g->y_axis->s.height = g->wp.height;
2885 g->x_axis->p.y = g->y_axis->p.height;
2886 zoom.x = (double )g->wp.width / cur_wp_width;
2887 zoom.y = (double )g->wp.height / cur_wp_height;
2888 cur_g_width = g->geom.width;
2889 cur_g_height = g->geom.height;
2890 g->geom.width = (int )rint (g->geom.width * zoom.x);
2891 g->geom.height = (int )rint (g->geom.height * zoom.y);
2892 g->zoom.x = (double )(g->geom.width - 1) / g->bounds.width;
2893 g->zoom.y = (double )(g->geom.height -1) / g->bounds.height;
2894 /* g->zoom.initial.x = g->zoom.x; */
2895 /* g->zoom.initial.y = g->zoom.y; */
2897 g->geom.x = (int) (g->wp.x - (double )g->geom.width/cur_g_width *
2898 (g->wp.x - g->geom.x));
2899 g->geom.y = (int) (g->wp.y - (double )g->geom.height/cur_g_height *
2900 (g->wp.y - g->geom.y));
2902 printf ("configure: graph: (%d,%d), (%d,%d); viewport: (%d,%d), (%d,%d); "
2903 "zooms: (%f,%f)\n", g->geom.x, g->geom.y, g->geom.width,
2904 g->geom.height, g->wp.x, g->wp.y, g->wp.width, g->wp.height,
2905 g->zoom.x, g->zoom.y);
2908 update_zoom_spins (g);
2909 graph_element_lists_make (g);
2910 graph_pixmaps_create (g);
2911 graph_title_pixmap_create (g);
2912 axis_pixmaps_create (g->y_axis);
2913 axis_pixmaps_create (g->x_axis);
2914 /* we don't do actual drawing here; we leave it to expose handler */
2915 graph_pixmap_draw (g);
2916 graph_pixmaps_switch (g);
2917 graph_title_pixmap_draw (g);
2918 h_axis_pixmap_draw (g->x_axis);
2919 axis_pixmaps_switch (g->x_axis);
2920 v_axis_pixmap_draw (g->y_axis);
2921 axis_pixmaps_switch (g->y_axis);
2925 static gint expose_event (GtkWidget *widget, GdkEventExpose *event)
2929 debug(DBS_FENTRY) puts ("expose_event()");
2934 for (g=graphs; g; g=g->next)
2935 if (g->drawing_area == widget)
2938 /* lower left corner */
2939 gdk_draw_rectangle (g->drawing_area->window, g->bg_gc, TRUE, 0,
2940 g->wp.y + g->wp.height, g->y_axis->p.width, g->x_axis->p.height);
2942 gdk_draw_rectangle (g->drawing_area->window, g->bg_gc, TRUE,
2943 g->wp.x + g->wp.width, g->wp.y, RMARGIN_WIDTH, g->wp.height);
2945 graph_pixmap_display (g);
2946 graph_title_pixmap_display (g);
2947 axis_pixmap_display (g->x_axis);
2948 axis_pixmap_display (g->y_axis);
2953 static gint button_press_event (GtkWidget *widget, GdkEventButton *event)
2957 debug(DBS_FENTRY) puts ("button_press_event()");
2959 for (g=graphs; g; g=g->next)
2960 if (g->drawing_area == widget)
2963 if (event->button == 3) {
2964 if (event->state & GDK_CONTROL_MASK)
2965 magnify_create (g, (int )rint (event->x), (int )rint (event->y));
2967 g->grab.x = (int )rint (event->x) - g->geom.x;
2968 g->grab.y = (int )rint (event->y) - g->geom.y;
2969 g->grab.grabbed = TRUE;
2972 /* Windows mouse control: */
2973 /* [<ctrl>-left] - select packet */
2974 /* [left] - zoom in */
2975 /* [<shift>-left] - zoom out */
2976 } else if (event->button == 1) {
2977 if (event->state & GDK_CONTROL_MASK) {
2978 graph_select_segment (g, (int)event->x, (int)event->y);
2981 } else if (event->button == 2) {
2983 int cur_width = g->geom.width, cur_height = g->geom.height;
2984 struct { double x, y; } factor;
2986 if (g->zoom.flags & ZOOM_OUT) {
2987 if (g->zoom.flags & ZOOM_HLOCK)
2990 factor.x = 1 / g->zoom.step_x;
2991 if (g->zoom.flags & ZOOM_VLOCK)
2994 factor.y = 1 / g->zoom.step_y;
2996 if (g->zoom.flags & ZOOM_HLOCK)
2999 factor.x = g->zoom.step_x;
3000 if (g->zoom.flags & ZOOM_VLOCK)
3003 factor.y = g->zoom.step_y;
3006 g->geom.width = (int )rint (g->geom.width * factor.x);
3007 g->geom.height = (int )rint (g->geom.height * factor.y);
3008 if (g->geom.width < g->wp.width)
3009 g->geom.width = g->wp.width;
3010 if (g->geom.height < g->wp.height)
3011 g->geom.height = g->wp.height;
3012 g->zoom.x = (g->geom.width - 1) / g->bounds.width;
3013 g->zoom.y = (g->geom.height- 1) / g->bounds.height;
3015 g->geom.x -= (int )rint ((g->geom.width - cur_width) *
3016 ((event->x-g->geom.x)/(double )cur_width));
3017 g->geom.y -= (int )rint ((g->geom.height - cur_height) *
3018 ((event->y-g->geom.y)/(double )cur_height));
3020 if (g->geom.x > g->wp.x)
3021 g->geom.x = g->wp.x;
3022 if (g->geom.y > g->wp.y)
3023 g->geom.y = g->wp.y;
3024 if (g->wp.x + g->wp.width > g->geom.x + g->geom.width)
3025 g->geom.x = g->wp.width + g->wp.x - g->geom.width;
3026 if (g->wp.y + g->wp.height > g->geom.y + g->geom.height)
3027 g->geom.y = g->wp.height + g->wp.y - g->geom.height;
3029 printf ("button press: graph: (%d,%d), (%d,%d); viewport: (%d,%d), "
3030 "(%d,%d); zooms: (%f,%f)\n", g->geom.x, g->geom.y,
3031 g->geom.width, g->geom.height, g->wp.x, g->wp.y, g->wp.width,
3032 g->wp.height, g->zoom.x, g->zoom.y);
3034 graph_element_lists_make (g);
3035 g->cross.erase_needed = 0;
3037 axis_display (g->y_axis);
3038 axis_display (g->x_axis);
3039 update_zoom_spins (g);
3041 cross_draw (g, (int) event->x, (int) event->y);
3043 } else if (event->button == 1) {
3044 graph_select_segment (g, (int )event->x, (int )event->y);
3052 static gint motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
3056 GdkModifierType state;
3058 /* debug(DBS_FENTRY) puts ("motion_notify_event()"); */
3060 for (g=graphs; g; g=g->next)
3061 if (g->drawing_area == widget)
3065 gdk_window_get_pointer (event->window, &x, &y, &state);
3069 state = event->state;
3072 /* Testing just (state & GDK_BUTTON1_MASK) is not enough since when button1
3073 * is pressed while pointer is in motion, we will receive one more motion
3074 * notify *before* we get the button press. This last motion notify works
3075 * with stale grab coordinates */
3076 if (state & GDK_BUTTON3_MASK) {
3077 if (g->grab.grabbed) {
3078 g->geom.x = x-g->grab.x;
3079 g->geom.y = y-g->grab.y;
3081 if (g->geom.x > g->wp.x)
3082 g->geom.x = g->wp.x;
3083 if (g->geom.y > g->wp.y)
3084 g->geom.y = g->wp.y;
3085 if (g->wp.x + g->wp.width > g->geom.x + g->geom.width)
3086 g->geom.x = g->wp.width + g->wp.x - g->geom.width;
3087 if (g->wp.y + g->wp.height > g->geom.y + g->geom.height)
3088 g->geom.y = g->wp.height + g->wp.y - g->geom.height;
3089 g->cross.erase_needed = 0;
3091 axis_display (g->y_axis);
3092 axis_display (g->x_axis);
3094 cross_draw (g, x, y);
3095 } else if (g->magnify.active)
3096 magnify_move (g, x, y);
3097 } else if (state & GDK_BUTTON1_MASK) {
3098 graph_select_segment (g, x, y);
3099 if (g->cross.erase_needed)
3102 cross_draw (g, x, y);
3104 if (g->cross.erase_needed)
3107 cross_draw (g, x, y);
3113 static gint button_release_event (GtkWidget *widget, GdkEventButton *event)
3117 debug(DBS_FENTRY) puts ("button_release_event()");
3119 for (g=graphs; g; g=g->next)
3120 if (g->drawing_area == widget)
3123 if (event->button == 3)
3124 g->grab.grabbed = FALSE;
3126 if (g->magnify.active)
3127 magnify_destroy (g);
3131 static gint key_press_event (GtkWidget *widget, GdkEventKey *event)
3135 debug(DBS_FENTRY) puts ("key_press_event()");
3137 for (g=graphs; g; g=g->next)
3138 if (g->toplevel == widget)
3141 if (event->keyval == 32 /*space*/) {
3144 if (g->cross.draw) {
3146 gdk_window_get_pointer (g->drawing_area->window, &x, &y, 0);
3148 } else if (g->cross.erase_needed) {
3152 /* toggle buttons emit their "toggled" signals so don't bother doing
3153 * any real work here, it will be done in signal handlers */
3155 gtk_toggle_button_set_active (g->cross.on_toggle, TRUE);
3157 gtk_toggle_button_set_active (g->cross.off_toggle, TRUE);
3158 } else if (event->keyval == 't')
3159 toggle_time_origin (g);
3160 else if (event->keyval == 's')
3161 toggle_seq_origin (g);
3162 else if (event->keyval == GDK_Shift_L) {
3163 /* g->zoom.flags |= ZOOM_OUT; */
3164 gtk_toggle_button_set_active (g->zoom.widget.out_toggle, TRUE);
3169 static gint key_release_event (GtkWidget *widget, GdkEventKey *event)
3173 debug(DBS_FENTRY) puts ("key_release_event()");
3175 for (g=graphs; g; g=g->next)
3176 if (g->toplevel == widget)
3179 if (event->keyval == GDK_Shift_L || event->keyval == GDK_ISO_Prev_Group) {
3180 /* g->zoom.flags &= ~ZOOM_OUT; */
3181 gtk_toggle_button_set_active (g->zoom.widget.in_toggle, TRUE);
3186 static gint leave_notify_event (GtkWidget *widget, GdkEventCrossing *event _U_)
3190 for (g=graphs; g; g=g->next)
3191 if (g->drawing_area == widget)
3194 if (g->cross.erase_needed)
3200 static gint enter_notify_event (GtkWidget *widget, GdkEventCrossing *event _U_)
3204 for (g=graphs; g; g=g->next)
3205 if (g->drawing_area == widget)
3208 /* graph_pixmap_display (g); */
3209 if (g->cross.draw) {
3211 gdk_window_get_pointer (g->drawing_area->window, &x, &y, 0);
3212 cross_draw (g, x, y);
3217 static void toggle_time_origin (struct graph *g)
3220 case GRAPH_TSEQ_STEVENS:
3221 tseq_stevens_toggle_time_origin (g);
3223 case GRAPH_TSEQ_TCPTRACE:
3224 tseq_tcptrace_toggle_time_origin (g);
3226 case GRAPH_THROUGHPUT:
3227 tput_toggle_time_origin (g);
3232 axis_display (g->x_axis);
3235 static void toggle_seq_origin (struct graph *g)
3238 case GRAPH_TSEQ_STEVENS:
3239 tseq_stevens_toggle_seq_origin (g);
3240 axis_display (g->y_axis);
3242 case GRAPH_TSEQ_TCPTRACE:
3243 tseq_tcptrace_toggle_seq_origin (g);
3244 axis_display (g->y_axis);
3247 rtt_toggle_seq_origin (g);
3248 axis_display (g->x_axis);
3255 static int get_num_dsegs (struct graph *g)
3258 struct segment *tmp;
3260 for (tmp=g->segments, count=0; tmp; tmp=tmp->next) {
3261 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3262 g->current->th_sport, g->current->th_dport,
3263 &tmp->ip_src, &tmp->ip_dst,
3264 tmp->th_sport, tmp->th_dport,
3265 COMPARE_CURR_DIR)) {
3272 static int get_num_acks (struct graph *g)
3275 struct segment *tmp;
3277 for (tmp=g->segments, count=0; tmp; tmp=tmp->next) {
3278 if(!compare_headers(&g->current->ip_src, &g->current->ip_dst,
3279 g->current->th_sport, g->current->th_dport,
3280 &tmp->ip_src, &tmp->ip_dst,
3281 tmp->th_sport, tmp->th_dport,
3282 COMPARE_CURR_DIR)) {
3290 * Stevens-style time-sequence grapH
3293 static void tseq_stevens_read_config (struct graph *g)
3295 debug(DBS_FENTRY) puts ("tseq_stevens_read_config()");
3297 g->s.tseq_stevens.seq_width = 4;
3298 g->s.tseq_stevens.seq_height = 4;
3299 g->s.tseq_stevens.flags = 0;
3301 g->title = (const char ** )g_malloc (2 * sizeof (char *));
3302 g->title[0] = "Time/Sequence Graph";
3304 g->y_axis->label = (const char ** )g_malloc (3 * sizeof (char * ));
3305 g->y_axis->label[0] = "number[B]";
3306 g->y_axis->label[1] = "Sequence";
3307 g->y_axis->label[2] = NULL;
3308 g->x_axis->label = (const char ** )g_malloc (2 * sizeof (char * ));
3309 g->x_axis->label[0] = "Time[s]";
3310 g->x_axis->label[1] = NULL;
3313 static void tseq_stevens_initialize (struct graph *g)
3315 debug(DBS_FENTRY) puts ("tseq_stevens_initialize()");
3316 tseq_stevens_get_bounds (g);
3322 case GRAPH_TSEQ_STEVENS:
3323 tseq_stevens_read_config(g);
3325 case GRAPH_TSEQ_TCPTRACE:
3326 tseq_tcptrace_read_config(g);
3331 static void tseq_stevens_get_bounds (struct graph *g)
3333 struct segment *tmp, *last, *first;
3334 double t, t0, tmax, ymax;
3337 guint32 ack_base = 0;
3339 for (first=g->segments; first->next; first=first->next) {
3340 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3341 g->current->th_sport, g->current->th_dport,
3342 &first->ip_src, &first->ip_dst,
3343 first->th_sport, first->th_dport,
3344 COMPARE_CURR_DIR)) {
3352 seq_base = first->th_seq;
3353 for (tmp=g->segments; tmp; tmp=tmp->next) {
3354 unsigned int highest_byte_num;
3356 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3357 g->current->th_sport, g->current->th_dport,
3358 &tmp->ip_src, &tmp->ip_dst,
3359 tmp->th_sport, tmp->th_dport,
3360 COMPARE_CURR_DIR)) {
3361 seq_cur = tmp->th_seq -seq_base;
3362 highest_byte_num = seq_cur + tmp->th_seglen;
3365 seq_cur = tmp->th_ack;
3368 highest_byte_num = seq_cur - ack_base;
3370 if (highest_byte_num > ymax)
3371 ymax = highest_byte_num;
3372 t = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3377 puts ("tseq_stevens_get_bounds: segment list corrupted!");
3381 t0 = g->segments->rel_secs + g->segments->rel_usecs / 1000000.0;
3383 g->bounds.y0 = seq_base;
3384 g->bounds.width = tmax - t0;
3385 g->bounds.height = ymax;
3386 g->zoom.x = (g->geom.width - 1) / g->bounds.width;
3387 g->zoom.y = (g->geom.height -1) / g->bounds.height;
3390 static void tseq_stevens_make_elmtlist (struct graph *g)
3392 struct segment *tmp;
3393 struct element *elements, *e;
3394 double x0 = g->bounds.x0, y0 = g->bounds.y0;
3395 guint32 seq_base = (guint32) y0;
3398 debug(DBS_FENTRY) puts ("tseq_stevens_make_elmtlist()");
3399 if (g->elists->elements == NULL) {
3400 int n = 1 + get_num_dsegs (g);
3401 e = elements = (struct element * )g_malloc (n*sizeof (struct element));
3403 e = elements = g->elists->elements;
3405 for (tmp=g->segments; tmp; tmp=tmp->next) {
3408 if(!compare_headers(&g->current->ip_src, &g->current->ip_dst,
3409 g->current->th_sport, g->current->th_dport,
3410 &tmp->ip_src, &tmp->ip_dst,
3411 tmp->th_sport, tmp->th_dport,
3412 COMPARE_CURR_DIR)) {
3415 seq_cur = tmp->th_seq - seq_base;
3416 secs = g->zoom.x * (tmp->rel_secs + tmp->rel_usecs / 1000000.0 - x0);
3417 seqno = g->zoom.y * seq_cur;
3422 e->p.arc.dim.width = g->s.tseq_stevens.seq_width;
3423 e->p.arc.dim.height = g->s.tseq_stevens.seq_height;
3424 e->p.arc.dim.x = secs - g->s.tseq_stevens.seq_width/2.0;
3425 e->p.arc.dim.y = seqno + g->s.tseq_stevens.seq_height/2.0;
3426 e->p.arc.filled = TRUE;
3427 e->p.arc.angle1 = 0;
3428 e->p.arc.angle2 = 23040;
3431 e->type = ELMT_NONE;
3432 g->elists->elements = elements;
3435 static void tseq_stevens_toggle_seq_origin (struct graph *g)
3437 g->s.tseq_stevens.flags ^= SEQ_ORIGIN;
3439 if ((g->s.tseq_stevens.flags & SEQ_ORIGIN) == SEQ_ORIGIN_ZERO)
3440 g->y_axis->min = g->bounds.y0;
3441 else /* g->tseq_stevens.flags & SEQ_ORIGIN == SEQ_ORIGIN_ISN */
3445 static void tseq_stevens_toggle_time_origin (struct graph *g)
3447 g->s.tseq_stevens.flags ^= TIME_ORIGIN;
3449 if ((g->s.tseq_stevens.flags & TIME_ORIGIN) == TIME_ORIGIN_CAP)
3450 g->x_axis->min = g->bounds.x0;
3451 else /* g->tseq_stevens.flags & TIME_ORIGIN == TIME_ORIGIN_CONN */
3456 * tcptrace-style time-sequence graph
3459 static void tseq_tcptrace_read_config (struct graph *g)
3461 GdkColormap *colormap;
3464 g->s.tseq_tcptrace.flags = 0;
3465 g->s.tseq_tcptrace.gc_seq = gdk_gc_new (g->drawing_area->window);
3466 g->s.tseq_tcptrace.gc_ack[0] = gdk_gc_new (g->drawing_area->window);
3467 g->s.tseq_tcptrace.gc_ack[1] = gdk_gc_new (g->drawing_area->window);
3468 colormap = gdk_window_get_colormap (g->drawing_area->window);
3469 if (!gdk_color_parse ("black", &color)) {
3471 * XXX - do more than just warn.
3473 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3474 "Could not parse color black.");
3476 if (!gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE)) {
3478 * XXX - do more than just warn.
3480 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3481 "Could not allocate color black.");
3483 gdk_gc_set_foreground (g->s.tseq_tcptrace.gc_seq, &color);
3484 if (!gdk_color_parse ("LightSlateGray", &color)) {
3486 * XXX - do more than just warn.
3488 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3489 "Could not parse color LightSlateGray.");
3491 if (!gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE)) {
3493 * XXX - do more than just warn.
3495 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3496 "Could not allocate color LightSlateGray.");
3498 gdk_gc_set_foreground (g->s.tseq_tcptrace.gc_ack[0], &color);
3499 if (!gdk_color_parse ("LightGray", &color)) {
3501 * XXX - do more than just warn.
3503 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3504 "Could not parse color LightGray.");
3506 if (!gdk_colormap_alloc_color (colormap, &color, FALSE, TRUE)) {
3508 * XXX - do more than just warn.
3510 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
3511 "Could not allocate color LightGray.");
3513 gdk_gc_set_foreground (g->s.tseq_tcptrace.gc_ack[1], &color);
3515 g->elists->next = (struct element_list * )
3516 g_malloc (sizeof (struct element_list));
3517 g->elists->next->next = NULL;
3518 g->elists->next->elements = NULL;
3520 g->title = (const char ** )g_malloc (2 * sizeof (char *));
3521 g->title[0] = "Time/Sequence Graph";
3523 g->y_axis->label = (const char ** )g_malloc (3 * sizeof (char * ));
3524 g->y_axis->label[0] = "number[B]";
3525 g->y_axis->label[1] = "Sequence";
3526 g->y_axis->label[2] = NULL;
3527 g->x_axis->label = (const char ** )g_malloc (2 * sizeof (char * ));
3528 g->x_axis->label[0] = "Time[s]";
3529 g->x_axis->label[1] = NULL;
3532 static void tseq_tcptrace_make_elmtlist (struct graph *g)
3534 struct segment *tmp;
3535 struct element *elements0, *e0; /* list of elmts with prio 0 */
3536 struct element *elements1, *e1; /* list of elmts with prio 1 */
3538 double p_t; /* ackno, window and time of previous segment */
3539 double p_ackno, p_win;
3544 debug(DBS_FENTRY) puts ("tseq_tcptrace_make_elmtlist()");
3546 if (g->elists->elements == NULL) {
3547 int n = 1 + 4*get_num_acks(g);
3548 e0 = elements0 = (struct element * )g_malloc (n*sizeof (struct element));
3550 e0 = elements0 = g->elists->elements;
3552 if (g->elists->next->elements == NULL ) {
3553 int n = 1 + 3*get_num_dsegs(g);
3554 e1 = elements1 = (struct element * )g_malloc (n*sizeof (struct element));
3556 e1 = elements1 = g->elists->next->elements;
3560 seq_base = (guint32) y0;
3561 /* initialize "previous" values */
3562 for (tmp=g->segments; tmp; tmp=tmp->next)
3563 if(!compare_headers(&g->current->ip_src, &g->current->ip_dst,
3564 g->current->th_sport, g->current->th_dport,
3565 &tmp->ip_src, &tmp->ip_dst,
3566 tmp->th_sport, tmp->th_dport,
3567 COMPARE_CURR_DIR)) {
3571 p_ackno = (unsigned int )(g->zoom.y * (tmp->th_ack - y0));
3574 p_win = g->zoom.y * tmp->th_win;
3575 p_t = g->segments->rel_secs + g->segments->rel_usecs/1000000.0 - x0;
3576 for (tmp=g->segments; tmp; tmp=tmp->next) {
3580 secs = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3583 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3584 g->current->th_sport, g->current->th_dport,
3585 &tmp->ip_src, &tmp->ip_dst,
3586 tmp->th_sport, tmp->th_dport,
3587 COMPARE_CURR_DIR)) {
3588 /* forward direction -> we need seqno and amount of data */
3591 seq_cur = tmp->th_seq -seq_base;
3592 if (TCP_SYN (tmp->th_flags))
3595 data = tmp->th_seglen;
3597 y1 = g->zoom.y * (seq_cur);
3598 y2 = g->zoom.y * (seq_cur + data);
3599 e1->type = ELMT_LINE;
3601 e1->gc = g->s.tseq_tcptrace.gc_seq;
3602 e1->p.line.dim.x1 = e1->p.line.dim.x2 = x;
3603 e1->p.line.dim.y1 = y1;
3604 e1->p.line.dim.y2 = y2;
3606 e1->type = ELMT_LINE;
3608 e1->gc = g->s.tseq_tcptrace.gc_seq;
3609 e1->p.line.dim.x1 = x - 1;
3610 e1->p.line.dim.x2 = x + 1;
3611 e1->p.line.dim.y1 = e1->p.line.dim.y2 = y1;
3613 e1->type = ELMT_LINE;
3615 e1->gc = g->s.tseq_tcptrace.gc_seq;
3616 e1->p.line.dim.x1 = x + 1;
3617 e1->p.line.dim.x2 = x - 1;
3618 e1->p.line.dim.y1 = e1->p.line.dim.y2 = y2;
3622 if (TCP_SYN (tmp->th_flags) && ! TCP_ACK (tmp->th_flags))
3623 /* SYN's have ACK==0 and are useless here */
3625 /* backward direction -> we need ackno and window */
3626 seq_cur = tmp->th_ack - seq_base;
3627 ackno = seq_cur * g->zoom.y;
3628 win = tmp->th_win * g->zoom.y;
3631 e0->type = ELMT_LINE;
3633 e0->gc = g->s.tseq_tcptrace.gc_ack[toggle];
3634 e0->p.line.dim.x1 = p_t;
3635 e0->p.line.dim.y1 = p_ackno;
3636 e0->p.line.dim.x2 = x;
3637 e0->p.line.dim.y2 = p_ackno;
3639 e0->type = ELMT_LINE;
3641 e0->gc = g->s.tseq_tcptrace.gc_ack[toggle];
3642 e0->p.line.dim.x1 = x;
3643 e0->p.line.dim.y1 = p_ackno;
3644 e0->p.line.dim.x2 = x;
3645 e0->p.line.dim.y2 = ackno!=p_ackno || ackno<4 ? ackno : ackno-4;
3648 e0->type = ELMT_LINE;
3650 e0->gc = g->s.tseq_tcptrace.gc_ack[toggle];
3651 e0->p.line.dim.x1 = p_t;
3652 e0->p.line.dim.y1 = p_win + p_ackno;
3653 e0->p.line.dim.x2 = x;
3654 e0->p.line.dim.y2 = p_win + p_ackno;
3656 e0->type = ELMT_LINE;
3658 e0->gc = g->s.tseq_tcptrace.gc_ack[toggle];
3659 e0->p.line.dim.x1 = x;
3660 e0->p.line.dim.y1 = p_win + p_ackno;
3661 e0->p.line.dim.x2 = x;
3662 e0->p.line.dim.y2 = win + ackno;
3670 e0->type = ELMT_NONE;
3671 e1->type = ELMT_NONE;
3672 g->elists->elements = elements0;
3673 g->elists->next->elements = elements1;
3676 static void tseq_tcptrace_toggle_seq_origin (struct graph *g)
3678 g->s.tseq_tcptrace.flags ^= SEQ_ORIGIN;
3680 if ((g->s.tseq_tcptrace.flags & SEQ_ORIGIN) == SEQ_ORIGIN_ZERO)
3681 g->y_axis->min = g->bounds.y0;
3682 else /* g->tseq_stevens.flags & SEQ_ORIGIN == SEQ_ORIGIN_ISN */
3686 static void tseq_tcptrace_toggle_time_origin (struct graph *g)
3688 g->s.tseq_tcptrace.flags ^= TIME_ORIGIN;
3690 if ((g->s.tseq_tcptrace.flags & TIME_ORIGIN) == TIME_ORIGIN_CAP)
3691 g->x_axis->min = g->bounds.x0;
3692 else /* g->tseq_stevens.flags & TIME_ORIGIN == TIME_ORIGIN_CONN */
3700 static void tput_make_elmtlist (struct graph *g)
3702 struct segment *tmp, *oldest;
3703 struct element *elements, *e;
3707 if (g->elists->elements == NULL) {
3708 int n = 1 + get_num_dsegs (g);
3709 e = elements = (struct element * )g_malloc (n*sizeof (struct element));
3711 e = elements = g->elists->elements;
3713 for (oldest=g->segments,tmp=g->segments->next,i=0; tmp; tmp=tmp->next,i++) {
3714 double time = tmp->rel_secs + tmp->rel_usecs/1000000.0;
3715 dtime = time - (oldest->rel_secs + oldest->rel_usecs/1000000.0);
3716 if (i>g->s.tput.nsegs) {
3717 sum -= oldest->th_seglen;
3718 oldest=oldest->next;
3720 sum += tmp->th_seglen;
3722 /* debug(DBS_TPUT_ELMTS) printf ("tput=%f\n", tput); */
3727 e->p.arc.dim.width = g->s.tput.width;
3728 e->p.arc.dim.height = g->s.tput.height;
3729 e->p.arc.dim.x = g->zoom.x*(time - g->bounds.x0) - g->s.tput.width/2.0;
3730 e->p.arc.dim.y = g->zoom.y*tput + g->s.tput.height/2.0;
3731 e->p.arc.filled = TRUE;
3732 e->p.arc.angle1 = 0;
3733 e->p.arc.angle2 = 23040;
3736 e->type = ELMT_NONE;
3737 g->elists->elements = elements;
3740 /* Purpose of <graph_type>_initialize functions:
3741 * - find maximum and minimum for both axes
3742 * - call setup routine for style struct */
3743 static void tput_initialize (struct graph *g)
3745 struct segment *tmp, *oldest, *last;
3747 double dtime, tput, tputmax=0;
3748 double t, t0, tmax = 0, y0, ymax;
3750 debug(DBS_FENTRY) puts ("tput_initialize()");
3752 tput_read_config(g);
3754 for (last=g->segments; last->next; last=last->next);
3755 for (oldest=g->segments,tmp=g->segments->next,i=0; tmp; tmp=tmp->next,i++) {
3756 dtime = tmp->rel_secs + tmp->rel_usecs/1000000.0 -
3757 (oldest->rel_secs + oldest->rel_usecs/1000000.0);
3758 if (i>g->s.tput.nsegs) {
3759 sum -= oldest->th_seglen;
3760 oldest=oldest->next;
3762 sum += tmp->th_seglen;
3764 debug(DBS_TPUT_ELMTS) printf ("tput=%f\n", tput);
3767 t = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3772 t0 = g->segments->rel_secs + g->segments->rel_usecs / 1000000.0;
3778 g->bounds.width = tmax - t0;
3779 g->bounds.height = ymax - y0;
3780 g->zoom.x = (g->geom.width - 1) / g->bounds.width;
3781 g->zoom.y = (g->geom.height -1) / g->bounds.height;
3784 static void tput_read_config (struct graph *g)
3786 debug(DBS_FENTRY) puts ("tput_read_config()");
3788 g->s.tput.width = 4;
3789 g->s.tput.height = 4;
3790 g->s.tput.nsegs = 20;
3792 g->title = (const char ** )g_malloc (2 * sizeof (char *));
3793 g->title[0] = "Throughput Graph";
3795 g->y_axis->label = (const char ** )g_malloc (3 * sizeof (char * ));
3796 g->y_axis->label[0] = "[B/s]";
3797 g->y_axis->label[1] = "Throughput";
3798 g->y_axis->label[2] = NULL;
3799 g->x_axis->label = (const char ** )g_malloc (2 * sizeof (char * ));
3800 g->x_axis->label[0] = "Time[s]";
3801 g->x_axis->label[1] = NULL;
3802 g->s.tput.flags = 0;
3805 static void tput_toggle_time_origin (struct graph *g)
3807 g->s.tput.flags ^= TIME_ORIGIN;
3809 if ((g->s.tput.flags & TIME_ORIGIN) == TIME_ORIGIN_CAP)
3810 g->x_axis->min = g->bounds.x0;
3811 else /* g->s.tput.flags & TIME_ORIGIN == TIME_ORIGIN_CONN */
3817 static void rtt_read_config (struct graph *g)
3819 debug(DBS_FENTRY) puts ("rtt_read_config()");
3822 g->s.rtt.height = 4;
3825 g->title = (const char ** )g_malloc (2 * sizeof (char *));
3826 g->title[0] = "Round Trip Time Graph";
3828 g->y_axis->label = (const char ** )g_malloc (3 * sizeof (char * ));
3829 g->y_axis->label[0] = "RTT [s]";
3830 g->y_axis->label[1] = NULL;
3831 g->x_axis->label = (const char ** )g_malloc (2 * sizeof (char * ));
3832 g->x_axis->label[0] = "Sequence Number[B]";
3833 g->x_axis->label[1] = NULL;
3836 static void rtt_initialize (struct graph *g)
3838 struct segment *tmp, *first=NULL;
3839 struct unack *unack = NULL, *u;
3841 double x0, y0, ymax;
3843 guint32 seq_base = 0;
3845 debug(DBS_FENTRY) puts ("rtt_initialize()");
3847 rtt_read_config (g);
3849 for (tmp=g->segments; tmp; tmp=tmp->next) {
3850 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3851 g->current->th_sport, g->current->th_dport,
3852 &tmp->ip_src, &tmp->ip_dst,
3853 tmp->th_sport, tmp->th_dport,
3854 COMPARE_CURR_DIR)) {
3855 guint32 seqno = tmp->th_seq;
3862 if (tmp->th_seglen && !rtt_is_retrans (unack, seqno)) {
3863 double time = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3864 u = rtt_get_new_unack (time, seqno);
3866 rtt_put_unack_on_list (&unack, u);
3869 if (seqno + tmp->th_seglen > xmax)
3870 xmax = seqno + tmp->th_seglen;
3872 guint32 ackno = tmp->th_ack -seq_base;
3873 double time = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3876 for (u=unack; u; u=v)
3877 if (ackno > u->seqno) {
3878 double rtt = time - u->time;
3882 rtt_delete_unack_from_list (&unack, u);
3894 g->bounds.width = xmax;
3895 g->bounds.height = ymax - y0;
3896 g->zoom.x = g->geom.width / g->bounds.width;
3897 g->zoom.y = g->geom.height / g->bounds.height;
3900 static int rtt_is_retrans (struct unack *list, unsigned int seqno)
3904 for (u=list; u; u=u->next)
3905 if (u->seqno== seqno)
3911 static struct unack *rtt_get_new_unack (double time, unsigned int seqno)
3915 u = (struct unack * )g_malloc (sizeof (struct unack));
3924 static void rtt_put_unack_on_list (struct unack **l, struct unack *new)
3926 struct unack *u, *list = *l;
3928 for (u=list; u; u=u->next)
3938 static void rtt_delete_unack_from_list (struct unack **l, struct unack *dead)
3940 struct unack *u, *list = *l;
3949 for (u=list; u; u=u->next)
3950 if (u->next == dead) {
3951 u->next = u->next->next;
3957 static void rtt_make_elmtlist (struct graph *g)
3959 struct segment *tmp;
3960 struct unack *unack = NULL, *u;
3961 struct element *elements, *e;
3962 guint32 seq_base = (guint32) g->bounds.x0;
3964 debug(DBS_FENTRY) puts ("rtt_make_elmtlist()");
3966 if (g->elists->elements == NULL) {
3967 int n = 1 + get_num_dsegs (g);
3968 e = elements = (struct element * )g_malloc (n*sizeof (struct element));
3970 e = elements = g->elists->elements;
3973 for (tmp=g->segments; tmp; tmp=tmp->next) {
3974 if(compare_headers(&g->current->ip_src, &g->current->ip_dst,
3975 g->current->th_sport, g->current->th_dport,
3976 &tmp->ip_src, &tmp->ip_dst,
3977 tmp->th_sport, tmp->th_dport,
3978 COMPARE_CURR_DIR)) {
3979 guint32 seqno = tmp->th_seq -seq_base;
3981 if (tmp->th_seglen && !rtt_is_retrans (unack, seqno)) {
3982 double time = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3983 u = rtt_get_new_unack (time, seqno);
3985 rtt_put_unack_on_list (&unack, u);
3988 guint32 ackno = tmp->th_ack -seq_base;
3989 double time = tmp->rel_secs + tmp->rel_usecs / 1000000.0;
3992 for (u=unack; u; u=v)
3993 if (ackno > u->seqno) {
3994 double rtt = time - u->time;
3999 e->p.arc.dim.width = g->s.rtt.width;
4000 e->p.arc.dim.height = g->s.rtt.height;
4001 e->p.arc.dim.x = g->zoom.x * u->seqno - g->s.rtt.width/2.0;
4002 e->p.arc.dim.y = g->zoom.y * rtt + g->s.rtt.height/2.0;
4003 e->p.arc.filled = TRUE;
4004 e->p.arc.angle1 = 0;
4005 e->p.arc.angle2 = 23040;
4009 rtt_delete_unack_from_list (&unack, u);
4014 e->type = ELMT_NONE;
4015 g->elists->elements = elements;
4018 static void rtt_toggle_seq_origin (struct graph *g)
4020 g->s.rtt.flags ^= SEQ_ORIGIN;
4022 if ((g->s.rtt.flags & SEQ_ORIGIN) == SEQ_ORIGIN_ZERO)
4023 g->x_axis->min = g->bounds.x0;
4028 #if defined(_WIN32) && !defined(__MINGW32__)
4029 /* replacement of Unix rint() for Windows */
4030 static int rint (double x)
4035 buf = _fcvt(x, 0, &dec, &sig);
4045 static gboolean tcp_graph_selected_packet_enabled(frame_data *current_frame, epan_dissect_t *edt)
4047 return current_frame != NULL ? (edt->pi.ipproto == IP_PROTO_TCP) : FALSE;
4052 register_tap_listener_tcp_graph(void)
4054 register_stat_menu_item("TCP Stream Graph/Time-Sequence Graph (Stevens)", REGISTER_STAT_GROUP_NONE,
4055 tcp_graph_cb, tcp_graph_selected_packet_enabled, NULL, GINT_TO_POINTER(0));
4056 register_stat_menu_item("TCP Stream Graph/Time-Sequence Graph (tcptrace)", REGISTER_STAT_GROUP_NONE,
4057 tcp_graph_cb, tcp_graph_selected_packet_enabled, NULL, GINT_TO_POINTER(1));
4058 register_stat_menu_item("TCP Stream Graph/Throughput Graph", REGISTER_STAT_GROUP_NONE,
4059 tcp_graph_cb, tcp_graph_selected_packet_enabled, NULL, GINT_TO_POINTER(2));
4060 register_stat_menu_item("TCP Stream Graph/Round Trip Time Graph", REGISTER_STAT_GROUP_NONE,
4061 tcp_graph_cb, tcp_graph_selected_packet_enabled, NULL, GINT_TO_POINTER(3));