diff --git a/AUTHORS b/AUTHORS index aaa796aec4..6230ddf5c1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3291,6 +3291,10 @@ Brian Cavagnolo { Allison aobourn [AT] isilon.com { HDFS and HDFS data Dissector } + +Edwin Groothuis { + Time Shift functionality +} and by: Pavel Roskin diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index dc2be14110..767a063f14 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -46,6 +46,7 @@ int proto_frame = -1; int hf_frame_arrival_time = -1; +int hf_frame_shift_offset = -1; int hf_frame_arrival_time_epoch = -1; static int hf_frame_time_invalid = -1; static int hf_frame_time_delta = -1; @@ -219,6 +220,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) PROTO_ITEM_SET_GENERATED(item); expert_add_info_format(pinfo, item, PI_MALFORMED, PI_WARN, "Arrival Time: Fractional second out of range (0-1000000000)"); } + item = proto_tree_add_time(fh_tree, hf_frame_shift_offset, tvb, + 0, 0, &(pinfo->fd->shift_offset)); + PROTO_ITEM_SET_GENERATED(item); if(generate_epoch_time) { proto_tree_add_time(fh_tree, hf_frame_arrival_time_epoch, tvb, @@ -543,6 +547,10 @@ proto_register_frame(void) { "Arrival Time", "frame.time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, "Absolute time when this frame was captured", HFILL }}, + { &hf_frame_shift_offset, + { "Time shift for this packet","frame.offset_shift", FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, + "Time shift applied to this packet", HFILL }}, + { &hf_frame_arrival_time_epoch, { "Epoch Time", "frame.time_epoch", FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, "Epoch time when this frame was captured", HFILL }}, diff --git a/epan/frame_data.c b/epan/frame_data.c index 1154090ae6..a233c75127 100644 --- a/epan/frame_data.c +++ b/epan/frame_data.c @@ -203,6 +203,8 @@ frame_data_init(frame_data *fdata, guint32 num, fdata->lnk_t = (gint16) phdr->pkt_encap; fdata->abs_ts.secs = phdr->ts.secs; fdata->abs_ts.nsecs = phdr->ts.nsecs; + fdata->shift_offset.secs = 0; + fdata->shift_offset.nsecs = 0; fdata->flags.passed_dfilter = 0; fdata->flags.encoding = PACKET_CHAR_ENC_CHAR_ASCII; fdata->flags.visited = 0; diff --git a/epan/frame_data.h b/epan/frame_data.h index 2947d09bf7..df9b7ba252 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -60,6 +60,7 @@ typedef struct _frame_data { const void *color_filter; /**< Per-packet matching color_filter_t object */ nstime_t abs_ts; /**< Absolute timestamp */ + nstime_t shift_offset;/**< How much the abs_tm of the frame is shifted */ nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */ nstime_t del_dis_ts; /**< Delta timestamp to previous displayed frame (yes, it can be negative) */ nstime_t del_cap_ts; /**< Delta timestamp to previous captured frame (yes, it can be negative) */ diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index c7c86b9094..1881325a2c 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -117,6 +117,7 @@ set(WIRESHARK_GTK_SRC tap_param_dlg.c text_import.c text_page_utils.c + time_shift_dlg.c uat_gui.c voip_calls.c webbrowser.c diff --git a/gtk/Makefile.common b/gtk/Makefile.common index 6af2ec584c..ae9f44645a 100644 --- a/gtk/Makefile.common +++ b/gtk/Makefile.common @@ -141,6 +141,7 @@ WIRESHARK_GTK_SRC = \ tap_param_dlg.c \ text_import.c \ text_page_utils.c \ + time_shift_dlg.c \ uat_gui.c \ voip_calls.c \ webbrowser.c @@ -322,6 +323,7 @@ noinst_HEADERS = \ sat.h \ sctp_stat.h \ service_response_time_table.h \ + time_shift_dlg.h \ stock_icons.h \ summary_dlg.h \ supported_protos_dlg.h \ diff --git a/gtk/help_dlg.c b/gtk/help_dlg.c index 1e28a5c27d..1ae8c0c506 100644 --- a/gtk/help_dlg.c +++ b/gtk/help_dlg.c @@ -346,6 +346,9 @@ topic_action(topic_action_e action) case(HELP_SAVE_WIN32_DIALOG): help_topic_html("ChIOSaveSection.html"); break; + case(HELP_TIME_SHIFT_DIALOG): + help_topic_html("ChWorkShiftTimePacketSection.html"); + break; default: g_assert_not_reached(); diff --git a/gtk/help_dlg.h b/gtk/help_dlg.h index 66de9f7a23..988bed5d34 100644 --- a/gtk/help_dlg.h +++ b/gtk/help_dlg.h @@ -100,7 +100,8 @@ typedef enum { HELP_EXPORT_BYTES_WIN32_DIALOG, HELP_OPEN_WIN32_DIALOG, HELP_MERGE_WIN32_DIALOG, - HELP_SAVE_WIN32_DIALOG + HELP_SAVE_WIN32_DIALOG, + HELP_TIME_SHIFT_DIALOG } topic_action_e; diff --git a/gtk/menus.c b/gtk/menus.c index 8ee0e73b0c..ddc5bbac6a 100644 --- a/gtk/menus.c +++ b/gtk/menus.c @@ -102,6 +102,7 @@ #include "gtk/dissector_tables_dlg.h" #include "gtk/utf8_entities.h" #include "gtk/expert_comp_dlg.h" +#include "gtk/time_shift_dlg.h" #include "gtk/new_packet_list.h" @@ -1075,6 +1076,7 @@ static const char *ui_desc_menubar = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" @@ -1532,6 +1534,7 @@ static const GtkActionEntry main_menu_bar_entries[] = { { "/Edit/Un-IgnoreAllPackets", NULL, "U_n-Ignore All Packets", "X", NULL, G_CALLBACK(new_packet_list_unignore_all_frames_cb) }, { "/Edit/SetTimeReference", WIRESHARK_STOCK_TIME, "Set Time Reference (toggle)", "T", NULL, G_CALLBACK(set_reftime_cb) }, { "/Edit/Un-TimeReferenceAllPackets",NULL, "Un-Time Reference All Packets", "T", NULL, G_CALLBACK(new_packet_list_untime_reference_all_frames_cb) }, + { "/Edit/TimeShift", NULL, "Time Shift...", "A", NULL, G_CALLBACK(set_time_shift_cb) }, { "/Edit/FindNextTimeReference", NULL, "Find Next Time Reference", "N", NULL, G_CALLBACK(find_next_ref_time_cb) }, { "/Edit/FindPreviousTimeReference", NULL, "Find Previous Time Reference", "B", NULL, G_CALLBACK(find_previous_ref_time_cb) }, @@ -1984,6 +1987,7 @@ static GtkItemFactoryEntry menu_items[] = {"/Edit/", NULL, NULL, 0, "", NULL,}, {"/Edit/Set Time Reference (toggle)", "T", GTK_MENU_FUNC(reftime_frame_cb), REFTIME_TOGGLE, "", WIRESHARK_STOCK_TIME,}, {"/Edit/Un-Time Reference All Packets", "T", GTK_MENU_FUNC(new_packet_list_untime_reference_all_frames_cb), 0, NULL, NULL,}, + {"/Edit/Time Shift...", "A", GTK_MENU_FUNC(time_shift_cb), 0, "", WIRESHARK_STOCK_TIME,}, {"/Edit/Find Next Time Reference", "N", GTK_MENU_FUNC(reftime_frame_cb), REFTIME_FIND_NEXT, NULL, NULL,}, {"/Edit/Find Previous Time Reference", "B", GTK_MENU_FUNC(reftime_frame_cb), REFTIME_FIND_PREV, NULL, NULL,}, {"/Edit/", NULL, NULL, 0, "", NULL,}, @@ -2975,6 +2979,7 @@ static const char *ui_desc_packet_list_menu_popup = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" @@ -3101,6 +3106,7 @@ static const GtkActionEntry packet_list_menu_popup_action_entries[] = { { "/MarkPacket", NULL, "Mark Packet (toggle)", NULL, NULL, G_CALLBACK(new_packet_list_mark_frame_cb) }, { "/IgnorePacket", NULL, "Ignore Packet (toggle)", NULL, NULL, G_CALLBACK(new_packet_list_ignore_frame_cb) }, { "/Set Time Reference", WIRESHARK_STOCK_TIME, "Set Time Reference (toggle)", NULL, NULL, G_CALLBACK(packet_list_menu_set_ref_time_cb) }, + { "/TimeShift", WIRESHARK_STOCK_TIME, "Time Shift...", NULL, NULL, G_CALLBACK(time_shift_cb) }, { "/ManuallyResolveAddress", NULL, "Manually Resolve Address", NULL, NULL, G_CALLBACK(manual_addr_resolv_dlg) }, { "/Apply as Filter", NULL, "Apply as Filter", NULL, NULL, NULL }, diff --git a/gtk/time_shift_dlg.c b/gtk/time_shift_dlg.c new file mode 100644 index 0000000000..fc5e86dba5 --- /dev/null +++ b/gtk/time_shift_dlg.c @@ -0,0 +1,919 @@ +/* time_shift_dlg.c + * Routines for "Time Shift" window + * Submitted by Edwin Groothuis + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "../globals.h" +#include "../alert_box.h" +#include "../simple_dialog.h" +#include "../main_statusbar.h" + +#include "gtk/gui_utils.h" +#include "gtk/time_shift_dlg.h" +#include "gtk/dlg_utils.h" +#include "gtk/stock_icons.h" +#include "gtk/prefs_dlg.h" +#include "gtk/keys.h" +#include "gtk/help_dlg.h" +#include "ui_util.h" + +/* Capture callback data keys */ +#define E_TIMESHIFT_SELECT "timeshift_select" +#define E_TIMESHIFT_OFFSET_KEY "timeshift_offset_te" +#define E_SETTIME_SELECT "settime_select" +#define E_SETTIME_TIME_KEY "settime_time_te" +#define E_SETTIME_PACKETNUMBER_KEY "settime_packetnumber_te" +#define E_ADJTIME_SELECT "adjtime_select" +#define E_ADJTIME_TIME1_KEY "adjtime_time1_te" +#define E_ADJTIME_PACKETNUMBER1_KEY "adjtime_packetnumber1_te" +#define E_ADJTIME_TIME2_KEY "adjtime_time2_te" +#define E_ADJTIME_PACKETNUMBER2_KEY "adjtime_packetnumber2_te" +#define E_UNDO_SELECT "undo_select" +#define E_UNDO_SHIFT_KEY "undo_shift_cb" + +static void time_shift_ok_cb(GtkWidget *ok_bt, GtkWindow *parent_w); +static void time_shift_apply_cb(GtkWidget *ok_bt, GtkWindow *parent_w); +static void time_shift_close_cb(GtkWidget *close_bt, gpointer parent_w); +static void time_shift_frame_destroy_cb(GtkWidget *win, gpointer user_data); + +/* + * Keep a static pointer to the current "Time Shift" window, if any, so + * that if somebody tries to do "Time Shift" while there's already a + * "Time Shift" window up, we just pop up the existing one, rather than + * creating a new one. + */ +static GtkWidget *time_shift_frame_w; + +void +time_shift_cb(GtkWidget *w _U_, gpointer d _U_) +{ + GtkWidget *main_vb, *main_hb, *label, + *types_frame, *types_vb, + + *timeshift_offset_hb, + *timeshift_offset_text_box, + + *settime_time_hb, + *settime_packetnumber_text_box, + *settime_time_text_box, + + *adjtime_offset_hb, + *adjtime_packetnumber1_text_box, + *adjtime_packetnumber2_text_box, + *adjtime_time1_text_box, + *adjtime_time2_text_box, + + *undo_offset_hb, + *undo_type_hb, + + *timeshift_rb, *settime_rb, + *adjtime_rb, *undo_rb, + + *bbox, *ok_bt, *cancel_bt, *help_bt; + + + if (time_shift_frame_w != NULL) { + /* There's already a "Time Shift" dialog box; reactivate it. */ + reactivate_window(time_shift_frame_w); + return; + } + + time_shift_frame_w = dlg_window_new("Wireshark: Time Shift"); + + /* Container for each row of widgets */ + main_vb = gtk_vbox_new(FALSE, 3); + gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); + gtk_container_add(GTK_CONTAINER(time_shift_frame_w), main_vb); + gtk_widget_show(main_vb); + + + /* + * Shift All Packets frame + */ + main_hb = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(main_vb), main_hb); + gtk_widget_show(main_hb); + + types_frame = gtk_frame_new(NULL); + gtk_box_pack_start(GTK_BOX(main_hb), types_frame, TRUE, TRUE, 0); + gtk_widget_show(types_frame); + + types_vb = gtk_vbox_new(FALSE, 3); + gtk_container_set_border_width(GTK_CONTAINER(types_vb), 3); + gtk_container_add(GTK_CONTAINER(types_frame), types_vb); + gtk_widget_show(types_vb); + + /* Radio button row */ + timeshift_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), timeshift_offset_hb, FALSE, FALSE, 0); + gtk_widget_show(timeshift_offset_hb); + + timeshift_rb = gtk_radio_button_new_with_label (NULL, "Shift all packets"); + gtk_box_pack_start(GTK_BOX(timeshift_offset_hb), timeshift_rb, TRUE, TRUE, 0); + gtk_widget_show(timeshift_rb); + + /* Time Shift entry row */ + timeshift_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), timeshift_offset_hb, FALSE, FALSE, 0); + gtk_widget_show(timeshift_offset_hb); + + label = gtk_label_new("Time offset in the format [+-][[hh:]mm:]ss[.ddd]"); + gtk_box_pack_start(GTK_BOX(timeshift_offset_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + timeshift_offset_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(timeshift_offset_hb), timeshift_offset_text_box, + TRUE, TRUE, 0); + gtk_widget_show(timeshift_offset_text_box); + + /* + * Set Packet Number to Time frame + */ + main_hb = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(main_vb), main_hb); + gtk_widget_show(main_hb); + + types_frame = gtk_frame_new(NULL); + gtk_box_pack_start(GTK_BOX(main_hb), types_frame, TRUE, TRUE, 0); + gtk_widget_show(types_frame); + + types_vb = gtk_vbox_new(FALSE, 3); + gtk_container_set_border_width(GTK_CONTAINER(types_vb), 3); + gtk_container_add(GTK_CONTAINER(types_frame), types_vb); + gtk_widget_show(types_vb); + + /* time shift type row */ + settime_time_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), settime_time_hb, FALSE, + FALSE, 0); + gtk_widget_show(settime_time_hb); + + settime_rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group( + GTK_RADIO_BUTTON(timeshift_rb)), "Set packet to time"); + gtk_box_pack_start(GTK_BOX(settime_time_hb), settime_rb, TRUE, TRUE, 0); + gtk_widget_show(settime_rb); + + settime_time_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), settime_time_hb, FALSE, + FALSE, 0); + gtk_widget_show(settime_time_hb); + + label = gtk_label_new("Packet number"); + gtk_box_pack_start(GTK_BOX(settime_time_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + settime_packetnumber_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(settime_time_hb), settime_packetnumber_text_box, + TRUE, TRUE, 0); + gtk_entry_set_text(GTK_ENTRY(settime_packetnumber_text_box), "1"); + gtk_widget_show(settime_packetnumber_text_box); + + /* time shift row */ + settime_time_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), settime_time_hb, FALSE, FALSE, + 0); + gtk_widget_show(settime_time_hb); + + label = gtk_label_new("Set packet to time [YYYY-MM-DD] hh:mm:ss[.ddd]"); + gtk_box_pack_start(GTK_BOX(settime_time_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + settime_time_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(settime_time_hb), settime_time_text_box, TRUE, + TRUE, 0); + gtk_widget_show(settime_time_text_box); + + /* + * Set two Packet Numbers to Time frame and extrapolate + */ + main_hb = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(main_vb), main_hb); + gtk_widget_show(main_hb); + + types_frame = gtk_frame_new(NULL); + gtk_box_pack_start(GTK_BOX(main_hb), types_frame, TRUE, TRUE, 0); + gtk_widget_show(types_frame); + + types_vb = gtk_vbox_new(FALSE, 3); + gtk_container_set_border_width(GTK_CONTAINER(types_vb), 3); + gtk_container_add(GTK_CONTAINER(types_frame), types_vb); + gtk_widget_show(types_vb); + + /* packet number row 1 */ + adjtime_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), adjtime_offset_hb, FALSE, FALSE, 0); + gtk_widget_show(adjtime_offset_hb); + + adjtime_rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group( + GTK_RADIO_BUTTON(timeshift_rb)), "Set packets to time and extrapolate"); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), adjtime_rb, TRUE, TRUE, 0); + gtk_widget_show(adjtime_rb); + + adjtime_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), adjtime_offset_hb, FALSE, FALSE, 0); + gtk_widget_show(adjtime_offset_hb); + + label = gtk_label_new("Packet number"); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + adjtime_packetnumber1_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), adjtime_packetnumber1_text_box, + TRUE, TRUE, 0); + gtk_entry_set_text(GTK_ENTRY(adjtime_packetnumber1_text_box), ""); + gtk_widget_show(adjtime_packetnumber1_text_box); + + /* time shift row */ + adjtime_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), adjtime_offset_hb, FALSE, FALSE, + 0); + gtk_widget_show(adjtime_offset_hb); + + label = gtk_label_new("Set packet to time [YYYY-MM-DD] hh:mm:ss[.ddd]"); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + adjtime_time1_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), adjtime_time1_text_box, TRUE, + TRUE, 0); + gtk_entry_set_text(GTK_ENTRY(adjtime_time1_text_box), ""); + gtk_widget_show(adjtime_time1_text_box); + + /* packet number row 2 */ + adjtime_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), adjtime_offset_hb, FALSE, + FALSE, 0); + gtk_widget_show(adjtime_offset_hb); + + label = gtk_label_new("Packet number"); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + adjtime_packetnumber2_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), adjtime_packetnumber2_text_box, + TRUE, TRUE, 0); + gtk_entry_set_text(GTK_ENTRY(adjtime_packetnumber2_text_box), ""); + gtk_widget_show(adjtime_packetnumber2_text_box); + + /* time shift row */ + adjtime_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), adjtime_offset_hb, FALSE, FALSE, + 0); + gtk_widget_show(adjtime_offset_hb); + + label = gtk_label_new("Set packet to time [YYYY-MM-DD] hh:mm:ss[.ddd]"); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), label, FALSE, FALSE, 0); + gtk_widget_show(label); + + adjtime_time2_text_box = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(adjtime_offset_hb), adjtime_time2_text_box, TRUE, + TRUE, 0); + gtk_entry_set_text(GTK_ENTRY(adjtime_time2_text_box), ""); + gtk_widget_show(adjtime_time2_text_box); + + /* + * Undo all shifts + */ + main_hb = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(main_vb), main_hb); + gtk_widget_show(main_hb); + + types_frame = gtk_frame_new(NULL); + gtk_box_pack_start(GTK_BOX(main_hb), types_frame, TRUE, TRUE, 0); + gtk_widget_show(types_frame); + + types_vb = gtk_vbox_new(FALSE, 3); + gtk_container_set_border_width(GTK_CONTAINER(types_vb), 3); + gtk_container_add(GTK_CONTAINER(types_frame), types_vb); + gtk_widget_show(types_vb); + + /* time shift type row */ + undo_type_hb = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(types_vb), undo_type_hb); + gtk_widget_show(undo_type_hb); + + /* time shift row */ + undo_offset_hb = gtk_hbox_new(FALSE, 3); + gtk_box_pack_start(GTK_BOX(types_vb), undo_offset_hb, FALSE, + FALSE, 0); + gtk_widget_show(undo_offset_hb); + + undo_rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group( + GTK_RADIO_BUTTON(timeshift_rb)), "Undo all shifts"); + gtk_box_pack_start(GTK_BOX(undo_offset_hb), undo_rb, TRUE, TRUE, 0); + gtk_widget_show(undo_rb); + + /* + * Button row + */ + bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, + GTK_STOCK_HELP, NULL); + gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0); + gtk_widget_show(bbox); + + ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK); + g_signal_connect(ok_bt, "clicked", G_CALLBACK(time_shift_ok_cb), + time_shift_frame_w); + + ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_APPLY); + g_signal_connect(ok_bt, "clicked", G_CALLBACK(time_shift_apply_cb), + time_shift_frame_w); + + cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL); + g_signal_connect(cancel_bt, "clicked", G_CALLBACK(time_shift_close_cb), + time_shift_frame_w); + + help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP); + g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), + (gpointer)HELP_TIME_SHIFT_DIALOG); + + g_object_set_data(G_OBJECT(time_shift_frame_w), E_TIMESHIFT_SELECT, + timeshift_rb); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_TIMESHIFT_OFFSET_KEY, + timeshift_offset_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_SETTIME_SELECT, settime_rb); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_SETTIME_TIME_KEY, + settime_time_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_SETTIME_PACKETNUMBER_KEY, + settime_packetnumber_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_ADJTIME_SELECT, adjtime_rb); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_ADJTIME_TIME1_KEY, + adjtime_time1_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_ADJTIME_PACKETNUMBER1_KEY, + adjtime_packetnumber1_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_ADJTIME_TIME2_KEY, + adjtime_time2_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_ADJTIME_PACKETNUMBER2_KEY, + adjtime_packetnumber2_text_box); + g_object_set_data(G_OBJECT(time_shift_frame_w), E_UNDO_SELECT, undo_rb); + + dlg_set_activate(timeshift_offset_text_box, ok_bt); + + /* Give the initial focus to the "offset" entry box. */ + gtk_widget_grab_focus(timeshift_offset_text_box); + + g_signal_connect(time_shift_frame_w, "delete_event", + G_CALLBACK(window_delete_event_cb), NULL); + g_signal_connect(time_shift_frame_w, "destroy", + G_CALLBACK(time_shift_frame_destroy_cb), NULL); + + gtk_widget_show(time_shift_frame_w); + window_present(time_shift_frame_w); +} + +#ifdef _MSC_VER +/* should be good enough to round down on Windows */ +#define truncl(ld) floorl(ld) + +#define localtime_r(a, b) memcpy((b), localtime((a)), sizeof(struct tm)); +#endif + +static void +error_message(const gchar *msg) +{ + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(time_shift_frame_w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", msg); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +} + +static int action_timeshift(GtkWindow *parent_w); +static void action_settime(GtkWindow *parent_w); +static void action_adjtime(GtkWindow *parent_w); +static void action_undo(GtkWindow *parent_w); + +static void +time_shift_apply_cb(GtkWidget *ok_bt _U_, GtkWindow *parent_w) +{ + GtkWidget *flag_rb; + + flag_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_TIMESHIFT_SELECT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(flag_rb)) == TRUE) { + action_timeshift(parent_w); + return; + } + + flag_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_SETTIME_SELECT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(flag_rb)) == TRUE) { + action_settime(parent_w); + return; + } + + flag_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_ADJTIME_SELECT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(flag_rb)) == TRUE) { + action_adjtime(parent_w); + return; + } + + flag_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_UNDO_SELECT); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(flag_rb)) == TRUE) { + action_undo(parent_w); + return; + } +} + +static void +time_shift_ok_cb(GtkWidget *ok_bt, GtkWindow *parent_w) +{ + time_shift_apply_cb(ok_bt, parent_w); + window_destroy(GTK_WIDGET(parent_w)); +} + +#define CHECK_YEARS(Y) \ + if (Y < 1970) { \ + error_message("years must be larger than 1970"); \ + return(1); \ + } +#define CHECK_MONTHS(M) \ + if (M < 1 || M > 12) { \ + error_message("months must be between [1..12]"); \ + return(1); \ + } +#define CHECK_DAYS(D) \ + if (D < 1 || D > 31) { \ + error_message("days must be between [1..31]"); \ + return(1); \ + } +#define CHECK_HOURS(h) \ + if (h < 0 || h > 23) { \ + error_message("hours must be between [0..23]"); \ + return(1); \ + } +#define CHECK_HOUR(h) \ + if (h < 0) { \ + error_message("negative hours, you have have specified more than " \ + "one minus character?"); \ + return(1); \ + } \ + offset_float += h * 3600 +#define CHECK_MINUTE(m) \ + if (m < 0 || m > 59) { \ + error_message("minutes must be between [0..59]"); \ + return(1); \ + } \ + offset_float += m * 60 +#define CHECK_SECOND(s) \ + if (s < 0 || s > 59) { \ + error_message("seconds must be between [0..59]"); \ + return(1); \ + } \ + offset_float += s +#define CHECK_SEC_DEC(f) \ + if (f < 0) { \ + error_message("fractional seconds must be > 0"); \ + return(1); \ + } \ + offset_float += f + +static int +action_timeshift(GtkWindow *parent_w) +{ + GtkWidget *offset_te; + const gchar *offset_text; + gchar *poffset_text; + nstime_t offset; + long double offset_float = 0; + guint32 i; + frame_data *fd; + int neg; + int h, m; + long double f; + + /* + * The following offset types are allowed: + * -?((hh:)mm:)ss(.decimals)? + * + * Since Wireshark doesn't support regular expressions (please prove me + * wrong :-) we will have to figure it out ourselves in the + * following order: + * + * 1. hh:mm:ss.decimals + * 2. mm:ss.decimals + * 3. ss.decimals + * + */ + + offset_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_TIMESHIFT_OFFSET_KEY); + offset_text = gtk_entry_get_text(GTK_ENTRY(offset_te)); + poffset_text = (gchar *)offset_text; + + /* strip whitespace */ + while (isspace(poffset_text[0])) + ++poffset_text; + + /* check for minus sign */ + neg = FALSE; + if (poffset_text[0] == '-') { + neg = TRUE; + poffset_text++; + } + + /* check for empty string */ + if (poffset_text[0] == '\0') + return(1); + + h = m = 0; + f = 0.0; + if (sscanf(poffset_text, "%d:%d:%Lf", &h, &m, &f) == 3) { + /* printf("%%d:%%d:%%d.%%d\n"); */ + CHECK_HOUR(h); + CHECK_MINUTE(m); + CHECK_SEC_DEC(f); + } else if (sscanf(poffset_text, "%d:%Lf", &m, &f) == 2) { + /* printf("%%d:%%d.%%d\n"); */ + CHECK_MINUTE(m); + CHECK_SEC_DEC(f); + } else if (sscanf(poffset_text, "%Lf", &f) == 1) { + /* printf("%%d.%%d\n"); */ + CHECK_SEC_DEC(f); + } else { + error_message("Could not parse the time: Expected ((hh:)mm:)ss.(dec)."); + return(1); + } + + if (offset_float == 0) + return(1); + + nstime_set_zero(&offset); + offset.secs = (time_t)truncl(offset_float); + offset_float -= offset.secs; + offset.nsecs = (int)(offset_float * 1000000000); + + for (i = 1; i <= cfile.count; i++) { + + if ((fd = frame_data_sequence_find(cfile.frames, i)) == NULL) + continue; /* Shouldn't happen */ + if (neg) { + nstime_subtract(&(fd->abs_ts), &offset); + nstime_subtract(&(fd->shift_offset), &offset); + } else { + nstime_add(&(fd->abs_ts), &offset); + nstime_add(&(fd->shift_offset), &offset); + } + } + new_packet_list_queue_draw(); + + return(0); +} + +static int +timestring2nstime(const gchar *ts, nstime_t *packettime, nstime_t *nstime) +{ + gchar *pts; + int h, m, Y, M, D; + long double f; + struct tm tm, packettm; + time_t tt; + long double offset_float = 0; + + /* + * The following time format is allowed: + * [YYYY-MM-DD] hh:mm:ss(.decimals)? + * + * Since Wireshark doesn't support regular expressions (please prove me + * wrong :-) we will have to figure it out ourselves in the + * following order: + * + * 1. YYYY-MM-DD hh:mm:ss.decimals + * 2. hh:mm:ss.decimals + * + */ + + pts = (gchar *)ts; + + /* strip whitespace */ + while (isspace(pts[0])) + ++pts; + + /* check for empty string */ + if (pts[0] == '\0') + return(1); + + if (sscanf(pts, "%d-%d-%d %d:%d:%Lf", &Y, &M, &D, &h, &m, &f) == 6) { + /* printf("%%d-%%d-%%d %%d:%%d:%%f\n"); */ + CHECK_YEARS(Y); + CHECK_MONTHS(M); + CHECK_DAYS(D); + CHECK_HOURS(h); + CHECK_MINUTE(m); + CHECK_SEC_DEC(f); + } else if (sscanf(pts, "%d:%d:%Lf", &h, &m, &f) == 3) { + /* printf("%%d:%%d:%%f\n"); */ + Y = M = D = 0; + CHECK_HOUR(h); + CHECK_MINUTE(m); + CHECK_SEC_DEC(f); + } else { + error_message("Could not parse the time: Expected (YY-MM-DD) " + "hh:mm:ss(.dec)"); + return(1); + } + + localtime_r(&(packettime->secs), &packettm); + + /* Convert the time entered in an epoch offset */ + localtime_r(&(packettime->secs), &tm); + if (Y == 0) { + tm.tm_year = packettm.tm_year; + tm.tm_mon = packettm.tm_mon; + tm.tm_mday = packettm.tm_mday; + } else { + tm.tm_year = Y - 1900; + tm.tm_mon = M - 1; + tm.tm_mday = D; + } + tm.tm_hour = h; + tm.tm_min = m; + tm.tm_sec = (int)truncl(f); + tt = mktime(&tm); + if (tt == -1) { + error_message("mktime went wrong. Was the time invalid?"); + return(1); + } + + nstime->secs = tt; + f -= tm.tm_sec; + nstime->nsecs = (int)(f * 1000000000); + + return(0); +} + +static void +action_settime(GtkWindow *parent_w) +{ + GtkWidget *packetnumber_te; + const gchar *packetnumber_text; + long packetnumber; + GtkWidget *time_te; + const gchar *time_text; + gchar *ptime_text; + nstime_t settime, difftime, packettime; + frame_data *fd, *packetfd; + guint32 i; + + packetnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_SETTIME_PACKETNUMBER_KEY); + packetnumber_text = gtk_entry_get_text(GTK_ENTRY(packetnumber_te)); + packetnumber = strtol((char *)packetnumber_text, NULL, 10); + + time_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_SETTIME_TIME_KEY); + time_text = gtk_entry_get_text(GTK_ENTRY(time_te)); + ptime_text = (gchar *)time_text; + + /* + * Get a copy of the real time (abs_ts - shift_offset) do we can find out the + * difference between the specified time and the original packet + */ + if ((packetfd = frame_data_sequence_find(cfile.frames, packetnumber)) == NULL) + return; + nstime_copy(&packettime, &(packetfd->abs_ts)); + nstime_subtract(&packettime, &(packetfd->shift_offset)); + + if (timestring2nstime(time_text, &packettime, &settime) != 0) + return; + + /* Calculate difference between packet time and requested time */ + nstime_delta(&difftime, &settime, &packettime); + + /* Up to here nothing is changed */ + + /* Set everything back to the original time */ + for (i = 1; i <= cfile.count; i++) { + if ((fd = frame_data_sequence_find(cfile.frames, i)) == NULL) + continue; /* Shouldn't happen */ + nstime_subtract(&(fd->abs_ts), &(fd->shift_offset)); + nstime_add(&(fd->abs_ts), &difftime); + nstime_set_zero(&(fd->shift_offset)); + nstime_copy(&(fd->shift_offset), &difftime); + } + + new_packet_list_queue_draw(); +} + +#ifdef NOTDEF +static char * +nstime_string(const nstime_t *t) +{ + static char s[100]; + char ts[100]; + struct tm tm; + + localtime_r(&(t->secs), &tm); + strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", &tm); + g_snprintf(s, 100, "%s.%d", ts, t->nsecs); + return(s); +} +#endif + +/* + * If the line between (OT1, NT1) and (OT2, NT2) is a straight line + * and (OT3, NT3) is on that line, + * then (NT2 - NT1) / (OT2 - OT2) = (NT3 - NT1) / (OT3 - OT1) and + * then (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) = (NT3 - NT1) and + * then NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) = NT3 and + * then NT3 = NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) and + * thus NT3 = NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT1) + * or NT3 = NT1 + (OT3 - OT1) * ( deltaNT12 / deltaOT12) + * + * All the things you come up when waiting for the train to come... + */ +static void +calcNT3(nstime_t *OT1, nstime_t *OT3, nstime_t *NT1, nstime_t *NT3, + nstime_t *deltaOT, nstime_t *deltaNT) +{ + long double fnt, fot, f, secs, nsecs; + + fnt = deltaNT->secs + (deltaNT->nsecs / 1000000000.0); + fot = deltaOT->secs + (deltaOT->nsecs / 1000000000.0); + f = fnt / fot; + + nstime_copy(NT3, OT3); + nstime_subtract(NT3, OT1); + secs = f * NT3->secs; + nsecs = f * NT3->nsecs; + NT3->secs = (time_t)secs; + secs -= truncl(secs); + NT3->nsecs = (int)(nsecs + (secs * 1000000000)); + while (NT3->nsecs > 1000000000) { + NT3->secs += 1; + NT3->nsecs -= 1000000000; + } + while (NT3->nsecs < 0) { + NT3->secs -= 1; + NT3->nsecs += 1000000000; + } + nstime_add(NT3, NT1); +} + +static void +action_adjtime(GtkWindow *parent_w _U_) +{ + GtkWidget *packetnumber_te; + const gchar *packetnumber_text; + long packetnumber1, packetnumber2; + GtkWidget *time_te; + const gchar *time1_text, *time2_text; + gchar *ptime1_text, *ptime2_text; + nstime_t nt1, nt2, ot1, ot2, nt3; + nstime_t dnt, dot, d3t; + frame_data *fd, *packet1fd, *packet2fd; + guint32 i; + + packetnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_ADJTIME_PACKETNUMBER1_KEY); + packetnumber_text = gtk_entry_get_text(GTK_ENTRY(packetnumber_te)); + packetnumber1 = strtol((char *)packetnumber_text, NULL, 10); + packetnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_ADJTIME_PACKETNUMBER2_KEY); + packetnumber_text = gtk_entry_get_text(GTK_ENTRY(packetnumber_te)); + packetnumber2 = strtol((char *)packetnumber_text, NULL, 10); + + /* + * The following time format is allowed: + * [YYYY-MM-DD] hh:mm:ss(.decimals)? + * + * Since Wireshark doesn't support regular expressions (please prove me + * wrong :-) we will have to figure it out ourselves in the + * following order: + * + * 1. YYYY-MM-DD hh:mm:ss.decimals + * 2. hh:mm:ss.decimals + * + */ + + time_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_ADJTIME_TIME1_KEY); + time1_text = gtk_entry_get_text(GTK_ENTRY(time_te)); + ptime1_text = (gchar *)time1_text; + time_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), + E_ADJTIME_TIME2_KEY); + time2_text = gtk_entry_get_text(GTK_ENTRY(time_te)); + ptime2_text = (gchar *)time2_text; + + /* + * Get a copy of the real time (abs_ts - shift_offset) do we can find out the + * difference between the specified time and the original packet + */ + if ((packet1fd = frame_data_sequence_find(cfile.frames, packetnumber1)) == NULL) + return; + nstime_copy(&ot1, &(packet1fd->abs_ts)); + nstime_subtract(&ot1, &(packet1fd->shift_offset)); + + if (timestring2nstime(time1_text, &ot1, &nt1) != 0) + return; + + /* + * Get a copy of the real time (abs_ts - shift_offset) do we can find out the + * difference between the specified time and the original packet + */ + if ((packet2fd = frame_data_sequence_find(cfile.frames, packetnumber2)) == NULL) + return; + nstime_copy(&ot2, &(packet2fd->abs_ts)); + nstime_subtract(&ot2, &(packet2fd->shift_offset)); + + if (timestring2nstime(time2_text, &ot2, &nt2) != 0) + return; + + nstime_copy(&dot, &ot2); + nstime_subtract(&dot, &ot1); + + nstime_copy(&dnt, &nt2); + nstime_subtract(&dnt, &nt1); + + /* Up to here nothing is changed */ + + for (i = 1; i <= cfile.count; i++) { + if ((fd = frame_data_sequence_find(cfile.frames, i)) == NULL) + continue; /* Shouldn't happen */ + + /* Set everything back to the original time */ + nstime_subtract(&(fd->abs_ts), &(fd->shift_offset)); + nstime_set_zero(&(fd->shift_offset)); + + /* Add the difference to each packet */ + calcNT3(&ot1, &(fd->abs_ts), &nt1, &nt3, &dot, &dnt); + + nstime_copy(&d3t, &nt3); + nstime_subtract(&d3t, &(fd->abs_ts)); + + nstime_copy(&(fd->abs_ts), &nt3); + nstime_copy(&(fd->shift_offset), &d3t); + } + + new_packet_list_queue_draw(); +} + +static void +action_undo(GtkWindow *parent_w _U_) +{ + guint32 i; + frame_data *fd; + + for (i = 1; i <= cfile.count; i++) { + if ((fd = frame_data_sequence_find(cfile.frames, i)) == NULL) + continue; /* Shouldn't happen */ + nstime_subtract(&(fd->abs_ts), &(fd->shift_offset)); + nstime_set_zero(&(fd->shift_offset)); + } + new_packet_list_queue_draw(); +} + +static void +time_shift_close_cb(GtkWidget *close_bt _U_, gpointer parent_w _U_) +{ + gtk_grab_remove(GTK_WIDGET(parent_w)); + window_destroy(GTK_WIDGET(parent_w)); +} + +static void +time_shift_frame_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_) +{ + /* Note that we no longer have a "Time Shift" dialog box. */ + time_shift_frame_w = NULL; +} + diff --git a/gtk/time_shift_dlg.h b/gtk/time_shift_dlg.h new file mode 100644 index 0000000000..3ac4442507 --- /dev/null +++ b/gtk/time_shift_dlg.h @@ -0,0 +1,38 @@ +/* time_shift_dlg.h + * Submitted by Edwin Groothuis + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __TIME_SHIFT_DLG_H__ +#define __TIME_SHIFT_DLG_H__ + +#include "globals.h" + +/** User requested to shift the time of the trace + * + * @param widget parent widget (unused) + * @param data unused + * @param action the function to use + */ +extern void time_shift_cb(GtkWidget *widget, gpointer data); + +#endif /* __TIME_SHIFT_DLG_H__ */