diff --git a/src/callbacks.c b/src/callbacks.c index 1d53ce0..4703a09 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -78,6 +78,8 @@ static gboolean MAC_yes = FALSE; static int load_select_nr = 0; int show_error_dialog = 1; +static void selection_dialog_show(void); + static char *ethernet_mactoa(struct sockaddr *addr) { static char buff[256]; @@ -379,22 +381,21 @@ on_ok_button1_clicked (GtkButton *button, notbk = lookup_widget("notebook1"); page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notbk)); - if (page == 0) { /* so we have the build notebook open */ - - if (load_data(btx, file_p, 1, 1) == -1) { + if (page == 0) { /* so we have the build notebook open */ + if (load_data(file_p, 1, 1) == -1) { /* calling previous function with last argument =1 means loading for builder */ error("Error: wrong file format!"); fclose(file_p); - return; + return; } break; } else if (page == 1) { /* it is the send build generator */ - if (load_gen_b_data(btx, file_p) == -1) { + if (load_gen_b_data(file_p) == -1) { error("Error: wrong file format!"); fclose(file_p); - return; + return; } break; } @@ -402,19 +403,19 @@ on_ok_button1_clicked (GtkButton *button, /* page with sequence generator is open */ else if (page == 2) { /* it is the send build generator */ - if (load_gen_s_data(btx, file_p) == -1) { + if (load_gen_s_data(file_p) == -1) { error("Error: wrong file format!"); fclose(file_p); - return; + return; } break; } else if (page == 3) { /* it is the send pcap file generator */ - if (load_data(btx, file_p, 2, MAXNUMLOADPACKETS) == -1) { + if (load_data(file_p, 2, MAXNUMLOADPACKETS) == -1) { error("Error: wrong file format!"); fclose(file_p); - return; + return; } break; } @@ -431,7 +432,7 @@ on_ok_button1_clicked (GtkButton *button, case 10: case 11: { //if (check_if_file_is_packet(file_p) == -1) { - if (load_data(btx, file_p, 1, 1) == -1) { + if (load_data(file_p, 1, 1) == -1) { error("Error: wrong file format!"); fclose(file_p); return; @@ -445,11 +446,10 @@ on_ok_button1_clicked (GtkButton *button, fclose(file_p); snprintf(buff, 100, " Parameters loaded from file %s", fname); - statusbar_text(btx, buff); + statusbar_text(buff); gtk_grab_remove(gtk_widget_get_toplevel(GTK_WIDGET(button))); gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button))); - } @@ -466,7 +466,7 @@ void on_Load_button_clicked (GtkButton *button, gpointer user_data) { - statusbar_text(button, ""); + statusbar_text(""); if (file_menu != NULL) { gdk_window_show(gtk_widget_get_window(file_menu)); @@ -486,7 +486,7 @@ void on_Save_button_clicked (GtkButton *button, gpointer user_data) { - statusbar_text(button, ""); + statusbar_text(""); if (save_file_menu != NULL) { gdk_window_show(gtk_widget_get_window(save_file_menu)); @@ -498,7 +498,6 @@ on_Save_button_clicked (GtkButton *button, gtk_widget_show(save_file_menu); btx = button; - } @@ -546,34 +545,34 @@ on_ok_button2_clicked (GtkButton *button, // return; //} - if (save_packet(btx, user_data, file_p) == -1) { - fclose(file_p); + if (save_packet(file_p) == -1) { + fclose(file_p); return; - } + } } else if (page == 1) { /* it is the send_built page */ - if (save_gen_b(btx, file_p) == -1) { - fclose(file_p); + if (save_gen_b(file_p) == -1) { + fclose(file_p); return; - } + } } else if (page == 2) { - if (save_gen_s(btx, file_p) == -1) { - fclose(file_p); + if (save_gen_s(file_p) == -1) { + fclose(file_p); return; - } + } } else if (page == 3) { - if (save_gen_pcap(btx, file_p) == -1) { - fclose(file_p); + if (save_gen_pcap(file_p) == -1) { + fclose(file_p); return; - } + } } else @@ -581,7 +580,7 @@ on_ok_button2_clicked (GtkButton *button, fclose(file_p); snprintf(buff4, 100, " Parameters saved in file %s", fname); - statusbar_text(btx, buff4); + statusbar_text(buff4); gtk_grab_remove(gtk_widget_get_toplevel(GTK_WIDGET(button))); //gtk_widget_destroy(gtk_widget_get_toplevel(GTK_WIDGET(button))); @@ -873,7 +872,7 @@ on_L_dst_select_bt_clicked (GtkButton *button, entry_field = lookup_widget("L_dst_mac"); IP_yes = FALSE; MAC_yes = TRUE; - selection_dialog_show(button, user_data); + selection_dialog_show(); } @@ -884,15 +883,13 @@ on_L_src_select_bt_clicked (GtkButton *button, entry_field = lookup_widget("L_src_mac"); IP_yes = FALSE; MAC_yes = TRUE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } /* this one shows the addresslist dialog. it tries to open a file with addresses. It should return an error in case of file error or if the contents of the file does not hold the specified structure */ -void -selection_dialog_show (GtkButton *button, - gpointer user_data) +static void +selection_dialog_show (void) { FILE *fp; @@ -1387,7 +1384,7 @@ on_Build_button_clicked (GtkButton *button, nt1 = lookup_widget("Stop_button"); gtk_widget_set_sensitive(nt1, TRUE); - statusbar_text(button, " Builder window opened"); + statusbar_text(" Builder window opened"); } @@ -1450,7 +1447,7 @@ on_Gen_button_clicked (GtkButton *button, nt1 = lookup_widget("Stop_button"); gtk_widget_set_sensitive(nt1, TRUE); - statusbar_text(button, " Gen-b window opened."); + statusbar_text(" Gen-b window opened."); /* get access to the buffer of text field */ text_e = lookup_widget("text5"); @@ -1458,11 +1455,11 @@ on_Gen_button_clicked (GtkButton *button, show_error_dialog = 0; - if (make_packet(button, user_data) == -1) { - //error("Packet contents is not ok!\n"); + if (make_packet() == -1) { + //error("Packet contents is not ok!\n"); snprintf(&tmp[0], 200, "\n\n Packet constructed in Builder is not ok!"); gtk_entry_set_text(GTK_ENTRY(crc_value), ""); - } + } else { /* copy data to tmp field */ for (i=0, j=0, m=1; j < number; m++, j++) { @@ -1590,7 +1587,7 @@ on_Gen_s_bt_clicked (GtkButton *button, gtk_widget_set_sensitive(nt1, TRUE); nt1 = lookup_widget("Stop_button"); gtk_widget_set_sensitive(nt1, TRUE); - statusbar_text(button, " Gen-s window opened"); + statusbar_text(" Gen-s window opened"); //on_button87_clicked(button, user_data); } @@ -1609,8 +1606,7 @@ void on_Send_button_clicked (GtkButton *button, gpointer user_data) { - - if (send_packet(button, user_data) == -1) { + if (send_packet() == -1) { //printf("problems sending packet; send_packet() returned -1\n"); return; } @@ -1676,8 +1672,7 @@ on_button24_clicked (GtkButton *button, entry_field_ip = lookup_widget("entry38"); IP_yes = TRUE; MAC_yes = FALSE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } @@ -1688,8 +1683,7 @@ on_button25_clicked (GtkButton *button, entry_field_ip = lookup_widget("entry37"); IP_yes = TRUE; MAC_yes = FALSE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } @@ -1966,8 +1960,7 @@ on_button33_clicked (GtkButton *button, entry_field_ip = lookup_widget("A_senderip"); IP_yes = TRUE; MAC_yes = TRUE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } @@ -1994,8 +1987,7 @@ on_button35_clicked (GtkButton *button, entry_field_ip = lookup_widget("A_targetip"); IP_yes = TRUE; MAC_yes = TRUE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } @@ -2140,7 +2132,7 @@ on_Interface_button_clicked (GtkButton *button, char buff[1000]; char *ptr; - statusbar_text(button, ""); + statusbar_text(""); if (interface_dialog_menu != NULL) { gdk_window_show(gtk_widget_get_window(interface_dialog_menu)); @@ -2247,7 +2239,7 @@ on_error_dialog_destroy (GtkWidget *object, error_dialog_menu = NULL; } -void error(gchar *error_type) +void error(const gchar *error_type) { GtkWidget *label; @@ -3344,7 +3336,7 @@ on_Reset_button_clicked (GtkButton *button, gint page; FILE *file_p; - statusbar_text(button, ""); + statusbar_text(""); notbk = lookup_widget("notebook1"); page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notbk)); @@ -3356,7 +3348,7 @@ on_Reset_button_clicked (GtkButton *button, return; } - if (load_data(button, file_p, 1, 1) == -1) + if (load_data(file_p, 1, 1) == -1) ;//error("Data in file \".defaultBuilder\" has wrong format"); fclose(file_p); } @@ -3367,7 +3359,7 @@ on_Reset_button_clicked (GtkButton *button, return; } - if (load_gen_b_data(button, file_p) == -1) + if (load_gen_b_data(file_p) == -1) ;//error("Data in file \".defaultGen-b\" has wrong format"); fclose(file_p); } @@ -3378,14 +3370,14 @@ on_Reset_button_clicked (GtkButton *button, return; } - if (load_gen_s_data(button, file_p) == -1) + if (load_gen_s_data(file_p) == -1) //error("Data in file \".defaultGen-s\" has wrong format"); ; //fclose(file_p); //YYY : the above line causes a crash, I don't know why... } - statusbar_text(button, " Loaded default parameters"); + statusbar_text(" Loaded default parameters"); return; } @@ -3400,7 +3392,7 @@ on_button62_clicked (GtkButton *button, gint page; FILE *file_p; - statusbar_text(button, ""); + statusbar_text(""); notbk = lookup_widget("notebook1"); page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notbk)); @@ -3411,10 +3403,10 @@ on_button62_clicked (GtkButton *button, return; } - if (save_packet(button, user_data, file_p) == -1) { - fclose(file_p); - return; - } + if (save_packet(file_p) == -1) { + fclose(file_p); + return; + } } else if (page == 1) { /* we have the Gen-b notebook open */ @@ -3423,33 +3415,32 @@ on_button62_clicked (GtkButton *button, return; } - if (save_gen_b(button, file_p) == -1) { - fclose(file_p); - return; - } + if (save_gen_b(file_p) == -1) { + fclose(file_p); + return; + } } - + else if (page == 2) { /* we have the Gen-s notebook open */ if((file_p = fopen(".defaultGen-s", "w")) == NULL) { error("Can't save parameters in file: \".defaultGen-s\""); return; } - if (save_gen_s(button, file_p) == -1) { - fclose(file_p); - return; - } + if (save_gen_s(file_p) == -1) { + fclose(file_p); + return; + } } - + else return; fclose(file_p); - statusbar_text(button, " Parameters set as default parameters"); + statusbar_text(" Parameters set as default parameters"); return; - } @@ -3626,8 +3617,7 @@ on_Gen_p_clicked (GtkButton *button, nt1 = lookup_widget("Stop_button"); gtk_widget_set_sensitive(nt1, FALSE); - statusbar_text(button, " Open a Pcap file. Selected packet will be shown in Builder!"); - + statusbar_text(" Open a Pcap file. Selected packet will be shown in Builder!"); } @@ -3657,7 +3647,7 @@ on_clist2_selection_changed (GtkTreeSelection *treeselection, memccpy(tmp, length_text, 32, 4); length = strtol(tmp, (char **)NULL, 10); - load_packet_disector(btx, text, 1, NULL, length); + load_packet_disector(text, 1, NULL, length); } @@ -4445,8 +4435,7 @@ on_button88_clicked (GtkButton *button, IPv6_yes = TRUE; IP_yes = FALSE; MAC_yes = FALSE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } @@ -4458,8 +4447,7 @@ on_button89_clicked (GtkButton *button, IPv6_yes = TRUE; IP_yes = FALSE; MAC_yes = FALSE; - selection_dialog_show(button, user_data); - + selection_dialog_show(); } diff --git a/src/callbacks.h b/src/callbacks.h index 88e1ca0..13d2eb7 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -18,12 +18,14 @@ * * */ + +#ifndef __CALLBACKS_H__ +#define __CALLBACKS_H__ + #include + // moj del: -//GtkWidget *clist1; -void selection_dialog_show(GtkButton *button, gpointer user_data); -void on_optionmenu7_clicked(GtkComboBox *combo_box, gpointer user_data); -void error(gchar *error_type); +void error(const gchar *error_type); // void @@ -458,6 +460,10 @@ void on_rtp_ok_bt_clicked (GtkButton *button, gpointer user_data); +void +on_optionmenu7_clicked (GtkComboBox *combo_box, + gpointer user_data); + void on_fileselection3_destroy (GtkWidget *object, gpointer user_data); @@ -800,3 +806,5 @@ on_checkbutton66_toggled (GtkToggleButton *togglebutton, void on_checkbutton67_toggled (GtkToggleButton *togglebutton, gpointer user_data); + +#endif /* __CALLBACKS_H__ */ diff --git a/src/function.c b/src/function.c index 7eba874..c8e0bc1 100644 --- a/src/function.c +++ b/src/function.c @@ -126,9 +126,26 @@ struct params { long long ramp_speed; } params1; +static int ipv6_get(void); +static int ipv4_get(void); +static int udp_get(guint32 pseudo_header_sum); +static int tcp_get(guint32 pseudo_header_sum); +static int igmp_get(void); +static int icmp_get(void); +static int arp_get(void); +static int get_network_payload(int length, int max, const gchar *entry); +static int link_level_get(void); +static int get_8023(void); +static int get_8021q(void); +static int get_mac_from_string(void); +static unsigned char linear2alaw(int pcm_val); +static unsigned char linear2ulaw(short pcm_val); +static short search(int val, short *table, int size); +static int icmpv6_get(guint32 pseudo_header_sum); + /* this function is called every second insiede the main gtk loop */ -int gtk_timer(GtkButton *button) { - +static int gtk_timer(G_GNUC_UNUSED gpointer user_data) +{ GtkWidget *statusbar; GtkWidget *button1, *button2, *button3, *button4, *button5, *button6, *button7; gint context_id; @@ -235,7 +252,7 @@ int gtk_timer(GtkButton *button) { * more than in the last packet[number] = ... line */ /* send button was pressed */ -int send_packet(GtkButton *button, gpointer user_data) +int send_packet(void) { GtkWidget *statusbar, *notebk, *reltime, *en5, *en6; GtkWidget *en1, *en2, *en3, *en4, *ckbt1, *ckbt2, *ckbt3, *ckbt4, *ckbt5, *xoptm, *yoptm; @@ -269,14 +286,14 @@ int send_packet(GtkButton *button, gpointer user_data) /* do we have the rights to do that? */ if (getuid() && geteuid()) { snprintf(buff, 100, " Sorry but you need the su rights"); - gtk_statusbar_push(GTK_STATUSBAR(button), GPOINTER_TO_INT(context_id), buff); + gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); error("Sorry but you need the su rights!"); return -1; } if ( page == 0 ) { /* so we have the build notebook open, it means we send only one packet */ - if (make_packet(button, user_data) == -1) { + if (make_packet() == -1) { //printf("problems with making packet!\n"); snprintf(buff, 100, " Problems with making packet!"); gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); @@ -328,7 +345,7 @@ int send_packet(GtkButton *button, gpointer user_data) /* is it the generator that sends the build packets? */ else if (page == 1) { - if (make_packet(button, user_data) == -1) { + if (make_packet() == -1) { //printf("problems with making packet!\n"); snprintf(buff, 100, " Problems with making packet!"); gtk_statusbar_push(GTK_STATUSBAR(statusbar), @@ -947,7 +964,7 @@ int send_packet(GtkButton *button, gpointer user_data) li_packets_sent = 0; li_last_packets_sent = 0; count10 = 0; - g_timeout_add( 100, (GSourceFunc)gtk_timer, button); + g_timeout_add(100, gtk_timer, NULL); pthread_create(&thread_id, NULL, &sendbuilt, ¶ms1); @@ -1196,7 +1213,7 @@ int send_packet(GtkButton *button, gpointer user_data) if (params1.fd == -1) { //printf("Error: Could not open socket!\n"); snprintf(buff, 100, " Problems with sending"); - gtk_statusbar_push(GTK_STATUSBAR(button), GPOINTER_TO_INT(context_id), buff); + gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); error("Error: Could not open socket!"); return -1; } @@ -1209,7 +1226,7 @@ int send_packet(GtkButton *button, gpointer user_data) /* does the interface exists? */ if (ioctl(params1.fd, SIOCGIFINDEX, ¶ms1.ifr) == -1) { snprintf(buff, 100, " Problems with sending"); - gtk_statusbar_push(GTK_STATUSBAR(button), GPOINTER_TO_INT(context_id), buff); + gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); snprintf(buff, 100, "No such interface: %s", iftext); error(buff); close(params1.fd); @@ -1220,7 +1237,7 @@ int send_packet(GtkButton *button, gpointer user_data) ioctl(params1.fd, SIOCGIFFLAGS, ¶ms1.ifr); if ( (params1.ifr.ifr_flags & IFF_UP) == 0) { snprintf(buff, 100, " Problems with sending"); - gtk_statusbar_push(GTK_STATUSBAR(button), GPOINTER_TO_INT(context_id), buff); + gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); snprintf(buff, 100, "Interface %s is down", iftext); error(buff); close(params1.fd); @@ -1247,7 +1264,7 @@ int send_packet(GtkButton *button, gpointer user_data) li_packets_sent = 0; li_last_packets_sent = 0; count10 = 0; - g_timeout_add( 100, (GSourceFunc)gtk_timer, button); + g_timeout_add(100, gtk_timer, NULL); snprintf(buff, 100, " Starting stream generator..."); gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); @@ -1265,7 +1282,7 @@ int send_packet(GtkButton *button, gpointer user_data) } -int make_packet(GtkButton *button, gpointer user_data) +int make_packet(void) { GtkWidget *ipv4, *ipv6, *arp, *usedef; GtkWidget *text_e; @@ -1294,13 +1311,13 @@ int make_packet(GtkButton *button, gpointer user_data) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ipv4))) { /* now we get the link layer info */ - if (link_level_get(button, user_data) == -1) { + if (link_level_get() == -1) { //printf("Error: problem on link layer with IPv4 packet\n"); return -1; } /* call the function that gets the ipv4 protocol information */ - if (ipv4_get(button, user_data) == -1) { + if (ipv4_get() == -1) { //printf("Error: problem with IPv4 information\n"); return -1; } @@ -1316,12 +1333,12 @@ int make_packet(GtkButton *button, gpointer user_data) } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ipv6))) { /* now we get the link layer info */ - if (link_level_get(button, user_data) == -1) { + if (link_level_get() == -1) { return -1; } /* call the function that gets the ipv6 protocol information */ - if (ipv6_get(button, user_data) == -1) { + if (ipv6_get() == -1) { //printf("Error: problem with IPv6 information\n"); return -1; } @@ -1330,13 +1347,13 @@ int make_packet(GtkButton *button, gpointer user_data) else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(arp))) { /* now we get the link layer info */ - if (link_level_get(button, user_data) == -1) { + if (link_level_get() == -1) { //printf("Error: problem on link layer with arp packet\n"); return -1; } /* call the function that gets the arp protocol information */ - if (arp_get(button, user_data) == -1) { + if (arp_get() == -1) { //printf("Error: problem with arp information\n"); return -1; } @@ -1351,7 +1368,7 @@ int make_packet(GtkButton *button, gpointer user_data) else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedef))) { /* if usedef is active we will manually get the link layer info */ - if (link_level_get(button, user_data) == -1) { + if (link_level_get() == -1) { //printf("Error: problem on link layer\n"); return -1; } @@ -1365,7 +1382,7 @@ int make_packet(GtkButton *button, gpointer user_data) gtk_text_buffer_get_bounds(buffer,&start,&end); text = gtk_text_buffer_get_text(buffer,&start,&end,FALSE); - if (get_network_payload(button, user_data, length, max, text) == -1) { + if (get_network_payload(length, max, text) == -1) { //printf("Error: problem with payload on network layer\n"); g_free(text); return -1; @@ -1389,7 +1406,8 @@ int make_packet(GtkButton *button, gpointer user_data) } -int ipv6_get(GtkButton *button, gpointer user_data) { +static int ipv6_get(void) +{ GtkWidget *version, *tos, *flowlabel, *payloadlength, *nextheader, *hoplimit; GtkWidget *src6ip, *dst6ip, *payloadlength_bt, *pay_text_e; GtkWidget *extensionhdr/*, *exthdrbto*/; @@ -1563,21 +1581,21 @@ int ipv6_get(GtkButton *button, gpointer user_data) { /* so we came to the end of ip header. what is next? */ /* tcp, udp, icmp or manually attached payload? */ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(udp_bt))) { - if (udp_get(button, user_data, pseudo_header_sum) == -1) { + if (udp_get(pseudo_header_sum) == -1) { //printf("Error: Problem with UDP information\n"); return -1; } } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcp_bt))) { - if (tcp_get(button, user_data, pseudo_header_sum) == -1) { + if (tcp_get(pseudo_header_sum) == -1) { //printf("Error: Problem with TCP information\n"); return -1; } } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(icmp6_bt))) { - if (icmpv6_get(button, user_data, pseudo_header_sum) == -1) { + if (icmpv6_get(pseudo_header_sum) == -1) { //printf("Error: Problem with ICMP information\n"); return -1; } @@ -1601,7 +1619,7 @@ int ipv6_get(GtkButton *button, gpointer user_data) { /* YYY 1514-number is not ok in case we use 802.1q!!! */ pay_max = 9900 - number; - if (get_network_payload(button, user_data, pay_length, pay_max, pay_text) == -1) { + if (get_network_payload(pay_length, pay_max, pay_text) == -1) { //printf("Error: Problem with IPv4 payload\n"); g_free(pay_text); return -1; @@ -1626,7 +1644,8 @@ int ipv6_get(GtkButton *button, gpointer user_data) { } /* let's parse the IPv4 protokol information */ -int ipv4_get(GtkButton *button, gpointer user_data) { +static int ipv4_get(void) +{ GtkWidget *version, *header_length, *tos, *total_length, *identification, *flags; GtkWidget *frag_offset, *ttl, *protocol, *header_cks, *header_cks_bt; GtkWidget *src_ip, *dst_ip, *options, *total_length_bt; @@ -1919,28 +1938,28 @@ int ipv4_get(GtkButton *button, gpointer user_data) { /* so we came to the end of ip header. what is next? */ /* tcp, udp, icmp or manually attached payload? */ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(udp_bt))) { - if (udp_get(button, user_data, pseudo_header_sum) == -1) { + if (udp_get(pseudo_header_sum) == -1) { //printf("Error: Problem with UDP information\n"); return -1; } } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcp_bt))) { - if (tcp_get(button, user_data, pseudo_header_sum) == -1) { + if (tcp_get(pseudo_header_sum) == -1) { //printf("Error: Problem with TCP information\n"); return -1; } } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(icmp_bt))) { - if (icmp_get(button, user_data) == -1) { + if (icmp_get() == -1) { //printf("Error: Problem with ICMP information\n"); return -1; } } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(igmp_bt))) { - if (igmp_get(button, user_data) == -1) { + if (igmp_get() == -1) { //printf("Error: Problem with IGMP information\n"); return -1; } @@ -1964,7 +1983,7 @@ int ipv4_get(GtkButton *button, gpointer user_data) { /* YYY 1514-number is not ok in case we use 802.1q!!! */ pay_max = 9900 - number; - if (get_network_payload(button, user_data, pay_length, pay_max, pay_text) == -1) { + if (get_network_payload(pay_length, pay_max, pay_text) == -1) { //printf("Error: Problem with IPv4 payload\n"); g_free(pay_text); return -1; @@ -1995,11 +2014,10 @@ int ipv4_get(GtkButton *button, gpointer user_data) { return 1; } - -int udp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) + +static int udp_get(guint32 pseudo_header_sum) { - GtkWidget *srcport, *dstport, *length, *length_bt, *checksum, *checksum_bt; GtkWidget *payload_bt, *payload; @@ -2131,8 +2149,7 @@ int udp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) //payload_t = (char *) malloc(payload_length + 1); //payload_t = gtk_editable_get_chars(GTK_EDITABLE(payload),0,-1); - if (get_network_payload(button, user_data, payload_length, - 9900, payload_t) == -1) { + if (get_network_payload(payload_length, 9900, payload_t) == -1) { //printf("Error: Problem with udp payload\n"); g_free(payload_t); return -1; @@ -2189,9 +2206,9 @@ int udp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) return 1; } - -int tcp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) { - + +static int tcp_get(guint32 pseudo_header_sum) +{ GtkWidget *srcport, *dstport, *sequence_number, *ack_number, *header_length; GtkWidget *flag_cwr, *flag_ecn; GtkWidget *flag_urg, *flag_ack, *flag_psh, *flag_rst, *flag_syn, *flag_fin; @@ -2471,8 +2488,7 @@ int tcp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) { //payload_t = gtk_editable_get_chars(GTK_EDITABLE(payload),0,-1); /* YYY 1514-number is not ok in case we use 802.1q!!! */ - if (get_network_payload(button, user_data, payload_length, - 9900-number, payload_t) == -1) { + if (get_network_payload(payload_length, 9900-number, payload_t) == -1) { //printf("Error: Problem with tcp payload\n"); g_free(payload_t); return -1; @@ -2521,8 +2537,8 @@ int tcp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) { return 1; } -int igmp_get(GtkButton *button, gpointer user_data) { - +static int igmp_get(void) +{ GtkWidget *type, *menux; GtkWidget *maxresptime, *checksum, *cks_bt, *groupaddress, *resv, *nosf, *sourceaddresses; @@ -2667,8 +2683,7 @@ int igmp_get(GtkButton *button, gpointer user_data) { /* source addresses */ payload_length = strlen(sourceaddresses_t); - if (get_network_payload(button, user_data, payload_length, - 9900, sourceaddresses_t) == -1) { + if (get_network_payload(payload_length, 9900, sourceaddresses_t) == -1) { //printf("problem with igmp reply payload\n"); return -1; } @@ -2733,8 +2748,7 @@ int igmp_get(GtkButton *button, gpointer user_data) { payload_length = strlen(sourceaddresses_t); /* YYY 1514-number is not ok in case we use 802.1q!!! */ - if (get_network_payload(button, user_data, payload_length, - 9900, sourceaddresses_t) == -1) { + if (get_network_payload(payload_length, 9900, sourceaddresses_t) == -1) { //printf("problem with igmp reply payload\n"); return -1; } @@ -2795,9 +2809,9 @@ int igmp_get(GtkButton *button, gpointer user_data) { return 1; } - -int icmp_get(GtkButton *button, gpointer user_data) { - + +static int icmp_get(void) +{ GtkWidget *type; GtkWidget *code, *checksum, *cks_bt, *identifier, *seq_nr, *unused; GtkWidget *data_bt, *data, *datalen; @@ -3318,9 +3332,9 @@ int icmp_get(GtkButton *button, gpointer user_data) { } return 1; } - + /* we have to parse the arp protocol information */ -int arp_get(GtkButton *button, gpointer user_data) +static int arp_get(void) { GtkWidget *hwtype, *prottype, *hwsize, *protsize; GtkWidget *rbt10, *rbt11, *rbt17, *en81; @@ -3516,10 +3530,10 @@ int arp_get(GtkButton *button, gpointer user_data) /* user choosed to manually attach payload, so here we are */ -int get_network_payload(GtkButton *button, gpointer user_data, int length, int max, gchar *entry) +static int get_network_payload(int length, int max, const gchar *entry) { int i, stevec = 0; - gchar *ptr; + const gchar *ptr; /* firs we check if total length without spaces is an even number */ ptr = entry; @@ -3561,7 +3575,7 @@ int get_network_payload(GtkButton *button, gpointer user_data, int length, int m } -int link_level_get(GtkButton *button, gpointer user_data) +static int link_level_get(void) { GtkWidget *ver2_tbt, *_801q_cbt, *_8023_tbt; GtkWidget *ethtype_e; @@ -3572,7 +3586,7 @@ int link_level_get(GtkButton *button, gpointer user_data) _801q_cbt = lookup_widget("bt_8021q"); /* always we need first the dest and source mac address */ - if (get_mac_from_string(button) == -1) { + if (get_mac_from_string() == -1) { //printf("Error: mac address field\n"); error("Error: mac address field"); return -1; @@ -3581,13 +3595,13 @@ int link_level_get(GtkButton *button, gpointer user_data) /* is 802.1q active - do we need to add 4 or 8 bytes? */ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(_801q_cbt))) { - if (get_8021q(button) == -1) { + if (get_8021q() == -1) { //printf("Error: 802.1q field\n"); return -1; } } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(_8023_tbt))) { /* uporabimo ethernet vezije 802.3 */ - if (get_8023(button) == -1) { + if (get_8023() == -1) { //printf("Error: 802.3 field"); return -1; } @@ -3624,7 +3638,7 @@ int link_level_get(GtkButton *button, gpointer user_data) /* if we are in the 802.3 ethernet version */ -int get_8023(GtkButton *button) +static int get_8023(void) { GtkWidget *ethlength_e/*, *L8023llc_tbt*/, *L8023llcsnap_tbt, *Ldsap_e, *Lssap_e; GtkWidget *Lctrl_e, *Loui_e, *Lpid_e, *autolength_bt; @@ -3745,7 +3759,7 @@ int get_8023(GtkButton *button) /* function parses 802.1q field */ -int get_8021q(GtkButton *button) +static int get_8021q(void) { GtkWidget *vlan_e, *priority_m, *cfi1_rbt, *vlanid_e, *QinQ_bt, *QinQ, *QinQpvid; gchar *vlan_t, *vlanid_t, *QinQ_t; @@ -3913,7 +3927,7 @@ guint16 get_checksum16(int cks_start, int cks_stop) //return sum; } /*check ip address */ -int check_ip_address(gchar *ptr) +int check_ip_address(const gchar *ptr) { int i, j; gchar tmp[4]; @@ -3939,11 +3953,11 @@ int check_ip_address(gchar *ptr) } /*check ipv6 address, if insert is==1, it means we insert the values, otherwise only check */ -int check_ipv6_address(gchar *ptr, int insert) +int check_ipv6_address(const gchar *ptr, int insert) { int stevec, dolzina, i=0, j=0, enojno=0, dvojno=-1; gchar paket[8][4]; - gchar *ptrstart; + const gchar *ptrstart; ptrstart = ptr; @@ -4070,7 +4084,7 @@ int check_ipv6_address(gchar *ptr, int insert) /* check mac address */ -int check_mac_address(gchar *ptr) +int check_mac_address(const gchar *ptr) { int i; @@ -4091,7 +4105,7 @@ int check_mac_address(gchar *ptr) /* function parses mac address */ -int get_mac_from_string(GtkButton *button) +static int get_mac_from_string(void) { GtkWidget *dstmac_e, *srcmac_e; gchar *dstmac_t, *srcmac_t; @@ -4141,7 +4155,7 @@ int get_mac_from_string(GtkButton *button) /* function takes pointer to char and converts two chars to hex and returns signed int. If you want to use te return value as char, you need to cast back to (unsigned char) */ -signed int char2x(char *p) +signed int char2x(const char *p) { unsigned char x=0; @@ -4248,7 +4262,7 @@ int insert_frequency(int codec, int frequency, int length, GtkWidget *payload_en /* Following three routines are from Sun Microsystems, Inc. */ -unsigned char linear2alaw(int pcm_val) /* 2's complement (16-bit range) */ +static unsigned char linear2alaw(int pcm_val) /* 2's complement (16-bit range) */ { static short seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF}; int mask; @@ -4282,7 +4296,7 @@ unsigned char linear2alaw(int pcm_val) /* 2's complement (16-bit range) */ } -unsigned char linear2ulaw(short pcm_val) /* 2's complement (16-bit range) */ +static unsigned char linear2ulaw(short pcm_val) /* 2's complement (16-bit range) */ { static short seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF}; short mask; @@ -4317,7 +4331,7 @@ unsigned char linear2ulaw(short pcm_val) /* 2's complement (16-bit range) */ } -short search(int val, short *table, int size) +static short search(int val, short *table, int size) { int i; @@ -4329,7 +4343,7 @@ short search(int val, short *table, int size) } -int check_digit(char *field, int length, char *text) +int check_digit(const char *field, int length, const char *text) { int i; @@ -4348,10 +4362,10 @@ int check_digit(char *field, int length, char *text) } } return 1; -} +} -int check_hex(char *field, int length, char *text) +int check_hex(const char *field, int length, const char *text) { int i; @@ -4406,8 +4420,8 @@ int check_if_file_is_packet(FILE *file_p) } -void statusbar_text(GtkButton *button, char *text) { - +void statusbar_text(const char *text) +{ GtkWidget *statusbar; gint context_id; char buff[101]; @@ -4417,10 +4431,9 @@ void statusbar_text(GtkButton *button, char *text) { snprintf(buff, strlen(text)+1, "%s", text ); gtk_statusbar_push(GTK_STATUSBAR(statusbar), GPOINTER_TO_INT(context_id), buff); - } -void gen_crc32_table() +static void gen_crc32_table() { unsigned long crc, poly; int i, j; @@ -4439,7 +4452,7 @@ void gen_crc32_table() } -unsigned long get_crc32(unsigned char *p, int len) +unsigned long get_crc32(const unsigned char *p, int len) { register unsigned long crc; int i; @@ -4462,8 +4475,8 @@ unsigned long get_crc32(unsigned char *p, int len) } -int icmpv6_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) { - +static int icmpv6_get(guint32 pseudo_header_sum) +{ GtkWidget *type, *code, *checksum, *cks_bt; GtkWidget *msgbody, *data_bt, *datapat, *datalen; @@ -4621,4 +4634,3 @@ int icmpv6_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum) return 1; } - diff --git a/src/function.h b/src/function.h index 461ce01..91e0ae5 100644 --- a/src/function.h +++ b/src/function.h @@ -16,46 +16,32 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . * - * function.c - all routines except callbacks and routines for sending + * function.h - all routines except callbacks and routines for sending * */ +#ifndef __FUNCTION_H__ +#define __FUNCTION_H__ + #include extern char iftext[20]; -signed int char2x(char *p); +signed int char2x(const char *p); char c4(int value); -guint32 get_checksum32(int start, int stop); -guint16 get_checksum16(int start, int stop); +guint32 get_checksum32(int start, int stop); +guint16 get_checksum16(int start, int stop); char *c8(char *s, unsigned char x); -unsigned char linear2alaw(int pcm_val); -unsigned char linear2ulaw(short pcm_val); -short search(int val, short *table, int size); int insert_frequency(int codec, int frequency, int length, GtkWidget *payload_entry, gint amp_index); -int check_mac_address(gchar *ptr); -int check_ip_address(gchar *ptr); -int check_ipv6_address(gchar *ptr, int insert); -int send_packet(GtkButton *button, gpointer user_data); -int make_packet(GtkButton *button, gpointer user_data); -int link_level_get(GtkButton *button, gpointer user_data); -int get_network_payload(GtkButton *button, gpointer user_data, int length, int max, gchar *entry); -int get_mac_from_string(GtkButton *button); -int get_8021q(GtkButton *button); -int get_8023(GtkButton *button); -int arp_get(GtkButton *button, gpointer user_data); -int ipv4_get(GtkButton *button, gpointer user_data); -int ipv6_get(GtkButton *button, gpointer user_data); -int udp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum); -int tcp_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum); -int icmp_get(GtkButton *button, gpointer user_data); -int icmpv6_get(GtkButton *button, gpointer user_data, guint32 pseudo_header_sum); -int igmp_get(GtkButton *button, gpointer user_data); -int check_digit(char *field, int length, char *text); +int check_mac_address(const gchar *ptr); +int check_ip_address(const gchar *ptr); +int check_ipv6_address(const gchar *ptr, int insert); +int send_packet(void); +int make_packet(void); +int check_digit(const char *field, int length, const char *text); int check_if_file_is_packet(FILE *file_p); -int check_hex(char *field, int length, char *text); -void statusbar_text(GtkButton *button, char *text); -void gen_crc32_table(void); -unsigned long get_crc32(unsigned char *p, int len); -int gtk_timer (GtkButton *button); +int check_hex(const char *field, int length, const char *text); +void statusbar_text(const char *text); +unsigned long get_crc32(const unsigned char *p, int len); +#endif /* __FUNCTION_H__ */ diff --git a/src/function_send.c b/src/function_send.c index 43b1dfd..f20b1c3 100644 --- a/src/function_send.c +++ b/src/function_send.c @@ -102,7 +102,7 @@ struct params { /* when you press Send inside the builder, one packet is sent */ -int packet_go_on_the_link(unsigned char *pkt, int nr) +int packet_go_on_the_link(const unsigned char *pkt, int nr) { int c, fd; struct sockaddr_ll sa; diff --git a/src/function_send.h b/src/function_send.h index a4607ad..cbec4f4 100644 --- a/src/function_send.h +++ b/src/function_send.h @@ -18,6 +18,11 @@ * */ -int packet_go_on_the_link(unsigned char *packet, int number); +#ifndef __FUNCTION_SEND_H__ +#define __FUNCTION_SEND_H__ + +int packet_go_on_the_link(const unsigned char *packet, int number); void* sendbuilt (void *); void* sendsequence (void *); + +#endif /* __FUNCTION_SEND_H__ */ diff --git a/src/headers.h b/src/headers.h index ba418dc..b2b367b 100644 --- a/src/headers.h +++ b/src/headers.h @@ -16,11 +16,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . * - * function.c - all routines except callbacks and routines for sending - * */ -#include +#ifndef __HEADERS_H__ +#define __HEADERS_H__ + +#include /*---------------------------------------------------------------------- * Stuff for writing a PCap file @@ -50,15 +51,15 @@ struct pcaprec_hdr { struct clist_hdr { gint16 pnrb; /* packet number */ gint32 time; /* delay since previous packet */ - gint16 plen; /* packet length */ + gint16 plen; /* packet length */ char src[40]; char dst[40]; gchar info[21]; }; - + typedef enum { - ETH_II, + ETH_II, ETH_802_3, ARP, IPv4, @@ -70,4 +71,4 @@ typedef enum { ICMPv6 } protocol_type; - +#endif /* __HEADERS_H__ */ diff --git a/src/interface.c b/src/interface.c index 66ee36c..0b05aac 100644 --- a/src/interface.c +++ b/src/interface.c @@ -9,9 +9,7 @@ #include #include -#include -#include "callbacks.h" #include "interface.h" #include "support.h" diff --git a/src/interface.h b/src/interface.h index 8861c89..5826e6f 100644 --- a/src/interface.h +++ b/src/interface.h @@ -1,3 +1,8 @@ +#ifndef __INTERFACE_H__ +#define __INTERFACE_H__ + +#include + GtkWidget* create_window1 (void); GtkWidget* create_sel1_dialog (void); GtkWidget* create_interface_dialog (void); @@ -9,3 +14,5 @@ GtkWidget* create_fileselection1 (void); GtkWidget* create_fileselection2 (void); GtkWidget* create_fileselection3 (void); void show_about_dialog (void); + +#endif /* __INTERFACE_H__ */ diff --git a/src/loadpacket.c b/src/loadpacket.c index 4e34963..c711d9f 100644 --- a/src/loadpacket.c +++ b/src/loadpacket.c @@ -19,7 +19,6 @@ */ #include -#include #include #include #include @@ -42,9 +41,27 @@ long i; int remain; protocol_type protokol; +static int load_gen_p_data(GtkTreeModel *model, const char *fieldek, const struct pcaprec_hdr *ph2, + int pkt_nr, const struct clist_hdr *clptr, double timediff, double timebeg); +static int arp_header(int whocalled); +static int igmp_header(int whocalled); +static int icmp_header(int whocalled); +static int usedef_insert(const char *entry, int whocalled); +static int tcp_header(int whocalled); +static int udp_header(int whocalled); +static int ipv4_header(int whocalled, struct clist_hdr *clptr); +static int ethernet_8023(int whocalled); +static int ethernet_verII(int whocalled); +static void inspar(const char *entry, const char *from, int length); +static void insint(const char *entry, const char *from, int length); +static signed int retint(const char *ch); +static unsigned long retint2(const char *ch, int length); +/*static void convert8field(char *to, const char *from);*/ +static int ipv6_header(int whocalled, struct clist_hdr *clptr); +static int icmpv6_header(int whocalled); + /* this one loads the parameters from file into notebook2 (Gen-b page) */ -int load_gen_b_data(GtkButton *button, FILE *file_p) { - +int load_gen_b_data(FILE *file_p) { long int buff4[5]; char buff[10]; char buffc[11][200]; @@ -148,8 +165,7 @@ int load_gen_b_data(GtkButton *button, FILE *file_p) { /* this one loads the parameters from file into notebook2 (Gen-s page) */ -int load_gen_s_data(GtkButton *button, FILE *file_p) { - +int load_gen_s_data(FILE *file_p) { long int buff4[5]; char buff[100]; char buffc[11][200]; @@ -331,14 +347,12 @@ int load_gen_s_data(GtkButton *button, FILE *file_p) { } return 1; - } /* opens the pcap file. * if we call this function from the builder window only one - first, packet will be read * from the Genp window, packets will be loaded untill EOF is reached */ -int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets) { - +int load_data(FILE *file_p, int whocalled, int howmanypackets) { struct pcap_hdr fh; struct pcaprec_hdr ph; struct clist_hdr clh; @@ -385,7 +399,7 @@ int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets c8(&field[2*ji], *(pkt_temp+ji)); field[2*ji+2] = '\0'; - load_packet_disector(button, field, 1, &clh, ph.incl_len); + load_packet_disector(field, 1, &clh, ph.incl_len); return 1; } @@ -427,7 +441,7 @@ int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets field[2*ji+2] = '\0'; /* we have to dissect the packet to get information for the list */ - load_packet_disector(button, field, 2, &clh, ph.incl_len); + load_packet_disector(field, 2, &clh, ph.incl_len); /* calculate the time information */ if (j==0) { @@ -447,7 +461,7 @@ int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets usecu = ph.ts_usec; /* insert a new row into model */ - load_gen_p_data(button, model, field, &ph, j+1, &clh, timediff, timebeg); + load_gen_p_data(model, field, &ph, j+1, &clh, timediff, timebeg); } if (j == howmanypackets) error("Only first 1000 packets loaded!\nTo change this modify #define on top of callbacks.c"); @@ -455,11 +469,11 @@ int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets return 1; } - + /* this one loads the parameters from file into notebook2 (Genp page) */ -int load_gen_p_data(GtkButton *button, GtkTreeModel *model, char *fieldek, struct pcaprec_hdr *ph2, - int pkt_nr, struct clist_hdr *clptr, double timediff, double timebeg) { +static int load_gen_p_data(GtkTreeModel *model, const char *fieldek, const struct pcaprec_hdr *ph2, + int pkt_nr, const struct clist_hdr *clptr, double timediff, double timebeg) { GtkTreeIter iter; gchar *datap[8]; gchar fieldp[7][41]; @@ -552,18 +566,17 @@ int load_gen_p_data(GtkButton *button, GtkTreeModel *model, char *fieldek, struc * if who called = 1 - we load the contents into builder field * if who called = 2 - we load the contenst into Genp window but we need the information for filling in the clist */ -int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct clist_hdr *clptr, int dolpaketa) { - +int load_packet_disector(char *fieldek, int whocalled, struct clist_hdr *clptr, int dolpaketa) { int c; ptrf = fieldek; ptrt = temp; //printf("\n:\n%s\n", fieldek); - //convert8field(ptrt, ptrf); insint(button, "entry179", ptrt, 8); ptrt = temp; ptrf = ptrf-8; - //convert8field(ptrt, ptrf+8); insint(button, "entry180", ptrt, 8); ptrt = temp; ptrf = ptrf-8; - //convert8field(ptrt, ptrf+16); insint(button, "entry181", ptrt, 8); ptrt = temp; ptrf = ptrf-8; - //convert8field(ptrt, ptrf+24); insint(button, "entry182", ptrt, 8); ptrt = temp; ptrf = ptrf-8; + //convert8field(ptrt, ptrf); insint("entry179", ptrt, 8); ptrt = temp; ptrf = ptrf-8; + //convert8field(ptrt, ptrf+8); insint("entry180", ptrt, 8); ptrt = temp; ptrf = ptrf-8; + //convert8field(ptrt, ptrf+16); insint("entry181", ptrt, 8); ptrt = temp; ptrf = ptrf-8; + //convert8field(ptrt, ptrf+24); insint("entry182", ptrt, 8); ptrt = temp; ptrf = ptrf-8; remain = dolpaketa; ptrf = ptrf + 32; @@ -644,7 +657,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct else if (i==37376) gtk_combo_box_set_active (GTK_COMBO_BOX (w8), 2); - inspar(button, "entry165", ptrf, 4); + inspar("entry165", ptrf, 4); } else ptrf = ptrf +3; @@ -681,7 +694,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), TRUE); - insint(button, "L_vlan_id", ptrf, 3); + insint("L_vlan_id", ptrf, 3); } else ptrf = ptrf+3; @@ -703,7 +716,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct /* ok, from now one, we split the dissection in different routines, depending on what values */ /* now if length is <= 1500, we have 802.3 ethernet and this value means length of ethernet packet */ if (i <= 1500) - next_prot = ethernet_8023(button, whocalled); + next_prot = ethernet_8023(whocalled); /* Values between 1500 and 1536 are forbidden */ else if ( (i>1500) && (i<1536) ) { error("Can't load packet: Wrong ethernet length/type field"); @@ -711,7 +724,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct } /* if i >= 1536 - ethernet ver II */ else - next_prot = ethernet_verII(button, whocalled); + next_prot = ethernet_verII(whocalled); /* ok, so we have dissected the ethernet layer and now move on two the next layer. @@ -729,7 +742,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct /* ipv4 */ else if (next_prot == 2048) { /* ok, ipv4 should follow, so we call the routine for parsing ipv4 header. */ - next_prot = ipv4_header(button, whocalled, clptr); + next_prot = ipv4_header(whocalled, clptr); if (next_prot == -1) return -1; @@ -742,7 +755,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct /* here we do the further parsing: tcp, udp, icmp, ...*/ if (next_prot == 1) { /* try to parse icmp header */ - next_prot = icmp_header(button, whocalled); + next_prot = icmp_header(whocalled); /* not ok, return an error */ if (next_prot == -1) return -1; @@ -754,7 +767,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct } else if (next_prot == 2) { /* try to parse igmp header */ - next_prot = igmp_header(button, whocalled); + next_prot = igmp_header(whocalled); /* not ok, return an error */ if (next_prot == -1) return -1; @@ -766,7 +779,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct } else if (next_prot == 6) { /* try to parse tcp header */ - next_prot = tcp_header(button, whocalled); + next_prot = tcp_header(whocalled); /* not ok, return an error */ if (next_prot == -1) return -1; @@ -781,7 +794,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct } else if (next_prot == 17) { /* try to parse udp header */ - next_prot = udp_header(button, whocalled); + next_prot = udp_header(whocalled); /* not ok, return an error */ if (next_prot == -1) return -1; @@ -795,7 +808,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct } /* protocol we do not support yet; user defined window */ else { - next_prot = usedef_insert(button, "text2", whocalled); + next_prot = usedef_insert("text2", whocalled); w1 = lookup_widget("ip_user_data_bt"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); } @@ -803,7 +816,7 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct /*arp */ else if (next_prot == 2054) { /* ok, arp header follows */ - next_prot = arp_header(button, whocalled); + next_prot = arp_header(whocalled); if (next_prot == -1) return -1; @@ -815,56 +828,56 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct else if (next_prot == 34525) { /* ok, ipv6 should follow, so we call the routine for parsing ipv6 header. */ - next_prot = ipv6_header(button, whocalled, clptr); - if (next_prot == -1) - return -1; + next_prot = ipv6_header(whocalled, clptr); + if (next_prot == -1) + return -1; w1 = lookup_widget("IPv6_rdbt"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - /* here we do the further parsing: tcp, udp, icmp, ...*/ - if (next_prot == 58) { - /* try to parse icmpv6 header */ - next_prot = icmpv6_header(button, whocalled); - /* not ok, return an error */ - if (next_prot == -1) - return -1; - /* ok, lets activate the icmpv6 notebook */ - else { - w1 = lookup_widget("radiobutton69"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - } - } - else if (next_prot == 6) { - /* try to parse tcp header */ - next_prot = tcp_header(button, whocalled); - /* not ok, return an error */ - if (next_prot == -1) - return -1; - /* ok, lets activate the tcp notebook */ - else { - w1 = lookup_widget("radiobutton68"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - } + /* here we do the further parsing: tcp, udp, icmp, ...*/ + if (next_prot == 58) { + /* try to parse icmpv6 header */ + next_prot = icmpv6_header(whocalled); + /* not ok, return an error */ + if (next_prot == -1) + return -1; + /* ok, lets activate the icmpv6 notebook */ + else { + w1 = lookup_widget("radiobutton69"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + } + } + else if (next_prot == 6) { + /* try to parse tcp header */ + next_prot = tcp_header(whocalled); + /* not ok, return an error */ + if (next_prot == -1) + return -1; + /* ok, lets activate the tcp notebook */ + else { + w1 = lookup_widget("radiobutton68"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + } } else if (next_prot == 17) { - /* try to parse udp header */ - next_prot = udp_header(button, whocalled); - /* not ok, return an error */ - if (next_prot == -1) - return -1; - /* ok, lets activate the udp notebook */ - else { - w1 = lookup_widget("radiobutton67"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - } - } - /* protocol we do not support yet; user defined window */ - else { - next_prot = usedef_insert(button, "text2", whocalled); - w1 = lookup_widget("radiobutton71"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - } + /* try to parse udp header */ + next_prot = udp_header(whocalled); + /* not ok, return an error */ + if (next_prot == -1) + return -1; + /* ok, lets activate the udp notebook */ + else { + w1 = lookup_widget("radiobutton67"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + } + } + /* protocol we do not support yet; user defined window */ + else { + next_prot = usedef_insert("text2", whocalled); + w1 = lookup_widget("radiobutton71"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + } } /* anything else - user defined */ @@ -873,28 +886,27 @@ int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct eth II type field and 802.3 pid field, so we have to fill this later */ w1 = lookup_widget("usedef2_radibt"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - + /* we still have c to distinguish between ver II and 802.3 */ /* ver II */ if (c >= 1536) { ptrf = ptrf - 4; - inspar(button, "L_ethtype", ptrf, 4); + inspar("L_ethtype", ptrf, 4); } /* 802.3 and with LLC SNAP */ else if (next_prot != -2) { ptrf = ptrf - 4; - inspar(button, "L_pid", ptrf, 4); - } + inspar("L_pid", ptrf, 4); + } - next_prot = usedef_insert(button, "text1", whocalled); + next_prot = usedef_insert("text1", whocalled); } return 1; } -int arp_header(GtkButton *button, int whocalled) { - +static int arp_header(int whocalled) { char tmp[5]; int x; @@ -912,16 +924,16 @@ int arp_header(GtkButton *button, int whocalled) { remain = remain - 28; /* hardware type */ - inspar(button, "A_hwtype", ptrf, 4); + inspar("A_hwtype", ptrf, 4); /* protocol type */ - inspar(button, "A_prottype", ptrf, 4); + inspar("A_prottype", ptrf, 4); /* hardware size */ - inspar(button, "A_hwsize", ptrf, 2); + inspar("A_hwsize", ptrf, 2); /* protocol size */ - inspar(button, "A_protsize", ptrf, 2); + inspar("A_protsize", ptrf, 2); /* opcode is next */ if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '1') ) { @@ -937,7 +949,7 @@ int arp_header(GtkButton *button, int whocalled) { else { w1 = lookup_widget("radiobutton17"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - inspar(button, "entry81", ptrf, 4); + inspar("entry81", ptrf, 4); } /* sender mac */ @@ -1005,12 +1017,10 @@ int arp_header(GtkButton *button, int whocalled) { gtk_entry_set_text(GTK_ENTRY(w1), temp); return 1; - } -int igmp_header(GtkButton *button, int whocalled) { - +static int igmp_header(int whocalled) { int x, x1; char tmp[5]; @@ -1030,7 +1040,7 @@ int igmp_header(GtkButton *button, int whocalled) { /* igmp type */ x = char2x(ptrf); /* insert version */ - inspar(button, "entry166", ptrf, 2); + inspar("entry166", ptrf, 2); w1 = lookup_widget("optionmenu20"); w2 = lookup_widget("notebook8"); @@ -1065,7 +1075,7 @@ int igmp_header(GtkButton *button, int whocalled) { gtk_notebook_set_current_page(GTK_NOTEBOOK(w2), 0); } - inspar(button, "entry167", ptrf, 2); + inspar("entry167", ptrf, 2); /* set checksum button on auto */ w2 = lookup_widget("checkbutton41"); @@ -1093,18 +1103,18 @@ int igmp_header(GtkButton *button, int whocalled) { } gtk_entry_set_text(GTK_ENTRY(w1), temp); - inspar(button, "entry171", ptrf, 4); + inspar("entry171", ptrf, 4); x1 = (int)retint2(ptrf, 4); - inspar(button, "entry172", ptrf, 4); - /*#inspar(button, "entry173", ptrf, x1);*/ - inspar(button, "entry173", ptrf, remain); + inspar("entry172", ptrf, 4); + /*#inspar("entry173", ptrf, x1);*/ + inspar("entry173", ptrf, remain); } else if (x==22) { /*IGMP V3 report */ - inspar(button, "entry176", ptrf, 4); + inspar("entry176", ptrf, 4); x1 = (int)retint2(ptrf, 4); - inspar(button, "entry177", ptrf, 4); - inspar(button, "entry178", ptrf, x1); + inspar("entry177", ptrf, 4); + inspar("entry178", ptrf, x1); } else { /*all the other versions */ @@ -1133,8 +1143,7 @@ int igmp_header(GtkButton *button, int whocalled) { return 1; } -int icmp_header(GtkButton *button, int whocalled) { - +static int icmp_header(int whocalled) { int x; char tmp5[5]; @@ -1154,7 +1163,7 @@ int icmp_header(GtkButton *button, int whocalled) { /* icmp type */ x = char2x(ptrf); /* insert version */ - inspar(button, "entry57", ptrf, 2); + inspar("entry57", ptrf, 2); w1 = lookup_widget("optionmenu4"); if (x == 0) @@ -1171,11 +1180,11 @@ int icmp_header(GtkButton *button, int whocalled) { /* insert code, checksum, identifier and seq number and data if there is some */ w1 = lookup_widget("notebook5"); gtk_notebook_set_current_page(GTK_NOTEBOOK(w1), 0); - inspar(button, "entry62", ptrf, 2); - //inspar(button, "entry63", ptrf, 4); + inspar("entry62", ptrf, 2); + //inspar("entry63", ptrf, 4); ptrf = ptrf + 4; - inspar(button, "entry64", ptrf, 4); - inspar(button, "entry65", ptrf, 4); + inspar("entry64", ptrf, 4); + inspar("entry65", ptrf, 4); /* set checksum button on auto */ w2 = lookup_widget("checkbutton16"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE); @@ -1188,9 +1197,9 @@ int icmp_header(GtkButton *button, int whocalled) { w1 = lookup_widget("checkbutton17"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE); } - inspar(button, "entry66", ptrf, 2); + inspar("entry66", ptrf, 2); sprintf(tmp5, "%d", remain); - inspar(button, "entry207", tmp5, 4); + inspar("entry207", tmp5, 4); } else if (x == 3) { /* destination unreacheable */ @@ -1199,7 +1208,7 @@ int icmp_header(GtkButton *button, int whocalled) { /* which code? */ x = char2x(ptrf); /* insert code */ - inspar(button, "entry58", ptrf, 2); + inspar("entry58", ptrf, 2); w1 = lookup_widget("optionmenu5"); if ( (x >= 0) && (x <= 15) ) @@ -1208,9 +1217,9 @@ int icmp_header(GtkButton *button, int whocalled) { gtk_combo_box_set_active (GTK_COMBO_BOX (w1), 16); /* insert code, checksum, identifier and seq number and data if there is some */ - //inspar(button, "entry59", ptrf, 4); + //inspar("entry59", ptrf, 4); ptrf = ptrf + 4; - inspar(button, "entry60", ptrf, 8); + inspar("entry60", ptrf, 8); /* set checksum button on auto */ w2 = lookup_widget("checkbutton15"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE); @@ -1224,19 +1233,19 @@ int icmp_header(GtkButton *button, int whocalled) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE); } - inspar(button, "entry66", ptrf, 2); + inspar("entry66", ptrf, 2); sprintf(tmp5, "%d", remain); - inspar(button, "entry210", tmp5, 4); + inspar("entry210", tmp5, 4); } else if (x == 8) { /* echo request */ w1 = lookup_widget("notebook5"); gtk_notebook_set_current_page(GTK_NOTEBOOK(w1), 5); /* insert code, checksum, identifier and seq number and data if there is some */ - inspar(button, "entry74", ptrf, 2); - //inspar(button, "entry77", ptrf, 4); + inspar("entry74", ptrf, 2); + //inspar("entry77", ptrf, 4); ptrf = ptrf + 4; - inspar(button, "entry75", ptrf, 4); - inspar(button, "entry78", ptrf, 4); + inspar("entry75", ptrf, 4); + inspar("entry78", ptrf, 4); /* set checksum button on auto */ w2 = lookup_widget("checkbutton20"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE); @@ -1249,17 +1258,17 @@ int icmp_header(GtkButton *button, int whocalled) { w1 = lookup_widget("checkbutton19"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE); } - inspar(button, "entry66", ptrf, 2); + inspar("entry66", ptrf, 2); sprintf(tmp5, "%d", remain); - inspar(button, "entry211", tmp5, 4); + inspar("entry211", tmp5, 4); } else { /* all the rest */ w1 = lookup_widget("notebook5"); gtk_notebook_set_current_page(GTK_NOTEBOOK(w1), 1); /* insert code, checksum and data if there is some */ - inspar(button, "entry157", ptrf, 2); - //inspar(button, "entry158", ptrf, 4); + inspar("entry157", ptrf, 2); + //inspar("entry158", ptrf, 4); ptrf = ptrf + 4; /* set checksum button on auto */ w2 = lookup_widget("checkbutton38"); @@ -1270,8 +1279,7 @@ int icmp_header(GtkButton *button, int whocalled) { } -int usedef_insert(GtkButton *button, char *entry, int whocalled) { - +static int usedef_insert(const char *entry, G_GNUC_UNUSED int whocalled) { int i, j; char tmp[31000]; @@ -1300,13 +1308,10 @@ int usedef_insert(GtkButton *button, char *entry, int whocalled) { gtk_text_buffer_set_text(buffer,tmp,-1); return 1; - - } -int tcp_header(GtkButton *button, int whocalled) { - +static int tcp_header(int whocalled) { int x, i, j; char tmp[31000], tmp2[3], ch; @@ -1335,16 +1340,16 @@ int tcp_header(GtkButton *button, int whocalled) { } /* source port */ - insint(button, "entry46", ptrf, 4); + insint("entry46", ptrf, 4); /* destination port */ - insint(button, "entry47", ptrf, 4); + insint("entry47", ptrf, 4); /* sequence number */ - insint(button, "entry48", ptrf, 8); + insint("entry48", ptrf, 8); /* acknowledgement number */ - insint(button, "entry49", ptrf, 8); + insint("entry49", ptrf, 8); /* now we insert value for length */ snprintf(tmp2, 3, "%d", x*4); @@ -1384,20 +1389,20 @@ int tcp_header(GtkButton *button, int whocalled) { ptrf = ptrf + 2; /* window size */ - insint(button, "entry51", ptrf, 4); + insint("entry51", ptrf, 4); /* checksum */ w1 = lookup_widget("checkbutton13"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //inspar(button, "entry52", ptrf, 4); + //inspar("entry52", ptrf, 4); ptrf = ptrf + 4; /* window size */ - insint(button, "entry53", ptrf, 4); + insint("entry53", ptrf, 4); /* any options ? */ /* - 20 for standard header */ - inspar(button, "entry54", ptrf, ( (x*4) - 20) * 2); + inspar("entry54", ptrf, ( (x*4) - 20) * 2); remain = remain - x*4; @@ -1437,8 +1442,7 @@ int tcp_header(GtkButton *button, int whocalled) { return 1; } -int udp_header(GtkButton *button, int whocalled) { - +static int udp_header(int whocalled) { int i, j; char tmp[31000]; @@ -1456,21 +1460,21 @@ int udp_header(GtkButton *button, int whocalled) { remain = remain - 8; /* source port */ - insint(button, "entry56", ptrf, 4); + insint("entry56", ptrf, 4); /* destination port */ - insint(button, "entry41", ptrf, 4); + insint("entry41", ptrf, 4); /* length */ w1 = lookup_widget("checkbutton3"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //insint(button, "entry42", ptrf, 4); + //insint("entry42", ptrf, 4); ptrf = ptrf + 4; /* checksum */ w1 = lookup_widget("checkbutton4"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //inspar(button, "entry43", "", 4); + //inspar("entry43", "", 4); ptrf = ptrf + 4; /* get access to buffer of the text field */ @@ -1509,8 +1513,7 @@ int udp_header(GtkButton *button, int whocalled) { } -int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { - +static int ipv4_header(int whocalled, struct clist_hdr *clptr) { char tmp[5]; int x, header_l, prot; @@ -1545,18 +1548,18 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { if (whocalled==1) { /* insert version */ - inspar(button, "entry26", ptrf, 1); + inspar("entry26", ptrf, 1); /* insert header length */ - inspar(button, "entry27", ptrf, 1); + inspar("entry27", ptrf, 1); /* insert tos */ - inspar(button, "entry28", ptrf, 2); + inspar("entry28", ptrf, 2); /* insert total length */ w1 = lookup_widget("checkbutton21"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //insint(button, "entry29", ptrf, 4); + //insint("entry29", ptrf, 4); } else ptrf = ptrf+4; @@ -1565,7 +1568,7 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { if (whocalled==1) { /* insert identification */ - inspar(button, "entry30", ptrf, 4); + inspar("entry30", ptrf, 4); } else ptrf = ptrf+4; @@ -1593,10 +1596,10 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { strncpy(tmp+1, ptrf+1, 3); if (whocalled==1) { - insint(button, "entry32", tmp, 4); - + insint("entry32", tmp, 4); + /* insert ttl */ - insint(button, "entry44", ptrf, 2); + insint("entry44", ptrf, 2); } else ptrf = ptrf+6; @@ -1605,12 +1608,12 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { if (whocalled==1) { /* insert protocol */ - insint(button, "entry34", ptrf, 2); + insint("entry34", ptrf, 2); /* insert header checksum */ w1 = lookup_widget("ip_header_cks_cbt"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //inspar(button, "entry35", ptrf, 4); + //inspar("entry35", ptrf, 4); } else ptrf = ptrf+2; @@ -1667,7 +1670,7 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { /* insert ipv4 options * header_l * 4 == total header length, - 20 for standard header == options length in bytes*/ if (whocalled==1) - inspar(button, "entry39", ptrf, ( (header_l*4) - 20) * 2); + inspar("entry39", ptrf, ( (header_l*4) - 20) * 2); remain = remain - (header_l * 4); @@ -1675,7 +1678,7 @@ int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { } -int ethernet_8023(GtkButton *button, int whocalled) { +static int ethernet_8023(int whocalled) { int dsap, lsap, ctrl; long pid; @@ -1699,7 +1702,7 @@ int ethernet_8023(GtkButton *button, int whocalled) { //gtk_notebook_set_current_page(GTK_NOTEBOOK(w3), 1); w1 = lookup_widget("entry5"); - //inspar(button, "entry5", ptrf, 4); + //inspar("entry5", ptrf, 4); ptrf = ptrf + 4; gtk_widget_set_sensitive (w1, FALSE); @@ -1713,11 +1716,11 @@ int ethernet_8023(GtkButton *button, int whocalled) { OUI == 0x000000 */ dsap = char2x(ptrf); - inspar(button, "L_dsap", ptrf, 2); + inspar("L_dsap", ptrf, 2); lsap = char2x(ptrf); - inspar(button, "L_ssap", ptrf, 2); + inspar("L_ssap", ptrf, 2); ctrl = char2x(ptrf); - inspar(button, "L_ctrl", ptrf, 2); + inspar("L_ctrl", ptrf, 2); /* in case dsap != ssap != 0xAA or ctrl != 0x03 or remain length < 5 bytes, we have only * LLC without SNAP and we return value for user defined next layer */ @@ -1753,7 +1756,7 @@ int ethernet_8023(GtkButton *button, int whocalled) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); /* insert 0x00 into oui field */ - inspar(button, "L_oui", ptrf, 6); + inspar("L_oui", ptrf, 6); pid = char2x(ptrf)*256 + char2x(ptrf+2); ptrf = ptrf + 4; @@ -1762,7 +1765,7 @@ int ethernet_8023(GtkButton *button, int whocalled) { } -int ethernet_verII(GtkButton *button, int whocalled) { +static int ethernet_verII(int whocalled) { int pid; @@ -1784,13 +1787,12 @@ int ethernet_verII(GtkButton *button, int whocalled) { /* this one inserts (length) characters from (char *from) into entry named (char *entry). It adds \0 at the end and in moves pointer ptrf (this one points the the next "data" to be inserted) by length */ -void inspar(GtkButton *button, char *entry, char *from, int length) { - +static void inspar(const char *entry, const char *from, int length) { GtkWidget *widg; //char tmp[81]; char *ptr; - ptr = malloc(length * sizeof(char) + 1); + ptr = malloc(length * sizeof(char) + 1); widg = lookup_widget(entry); @@ -1800,14 +1802,13 @@ void inspar(GtkButton *button, char *entry, char *from, int length) { ptrf = ptrf + length; free(ptr); -} +} /* this one reads (length) characters strating at (char *from), converts them to int and inserts them into field (*entry) as integer. f.e: 0x56 == (int)86 => writes into (*entry) 86 note that max size for length is 10!!! when calling this routine */ -void insint(GtkButton *button, char *entry, char *from, int length) { - +static void insint(const char *entry, const char *from, int length) { GtkWidget *widg; char tmp[11]; unsigned long value = 0; @@ -1836,7 +1837,7 @@ void insint(GtkButton *button, char *entry, char *from, int length) { /* from a character return int */ -signed int retint(char *ch) { +static signed int retint(const char *ch) { unsigned char x; @@ -1855,8 +1856,7 @@ signed int retint(char *ch) { /* this one reads (length) characters strating at (*from), and returns integer (max 10 char length) */ -unsigned long retint2(char *from, int length) { - +static unsigned long retint2(const char *from, int length) { unsigned long value = 0; int i; unsigned char x = 0; @@ -1876,13 +1876,12 @@ unsigned long retint2(char *from, int length) { return value; } - +#if 0 /* i have newer really understood the endians... help appreciated... * this routines just converts the contents of a char field of size 8 chars * it works also, if destination and source are the same field*/ -void convert8field(char *to, char *from) { - +static void convert8field(char *to, const char *from) { char f1[8]; /* we copy first the source contents */ @@ -1897,9 +1896,9 @@ void convert8field(char *to, char *from) { memcpy(to+6, f1+0,1); memcpy(to+7, f1+1,1); } +#endif -int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { - +static int ipv6_header(int whocalled, struct clist_hdr *clptr) { //char tmp[5]; //int x; int prot, header_l=0; @@ -1914,42 +1913,42 @@ int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { return -1; } - if (whocalled==1) { - /* insert version */ - inspar(button, "entry195", ptrf, 1); + if (whocalled==1) { + /* insert version */ + inspar("entry195", ptrf, 1); - /* insert traffic class */ - inspar(button, "entry196", ptrf, 2); + /* insert traffic class */ + inspar("entry196", ptrf, 2); - /* insert tos */ - inspar(button, "entry197", ptrf, 5); + /* insert tos */ + inspar("entry197", ptrf, 5); - /* insert total length */ - w1 = lookup_widget("checkbutton43"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - //insint(button, "entry29", ptrf, 4); - } - else - ptrf = ptrf + 8; + /* insert total length */ + w1 = lookup_widget("checkbutton43"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + //insint("entry29", ptrf, 4); + } + else + ptrf = ptrf + 8; - ptrf = ptrf + 4; + ptrf = ptrf + 4; prot = char2x(ptrf); - if (whocalled==1) { - /* insert next header */ - inspar(button, "entry199", ptrf, 2); - } - else - ptrf = ptrf+2; + if (whocalled==1) { + /* insert next header */ + inspar("entry199", ptrf, 2); + } + else + ptrf = ptrf+2; if (whocalled==1) { - /* insert hop limit */ - insint(button, "entry200", ptrf, 2); + /* insert hop limit */ + insint("entry200", ptrf, 2); } - else - ptrf = ptrf+2; + else + ptrf = ptrf+2; /*insert source ip */ ptrt = temp6; @@ -1998,8 +1997,7 @@ int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { while ( (prot==0) || (prot==43) || (prot==44) || (prot==51) || (prot==50) || (prot==60) ) { prot = char2x(ptrf); header_l = retint2(ptrf+2, 2); - inspar(button, "entry203", ptrf, header_l); - + inspar("entry203", ptrf, header_l); } remain = remain - 40 - header_l; @@ -2007,8 +2005,7 @@ int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) { return prot; } -int icmpv6_header(GtkButton *button, int whocalled) { - +static int icmpv6_header(int whocalled) { //char tmp5[5]; if (whocalled==2) { @@ -2024,41 +2021,39 @@ int icmpv6_header(GtkButton *button, int whocalled) { remain = remain -4; - inspar(button, "entry215", ptrf, 2); + inspar("entry215", ptrf, 2); - inspar(button, "entry216", ptrf, 2); + inspar("entry216", ptrf, 2); w1 = lookup_widget("checkbutton48"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - ptrf = ptrf + 4; - - //if (remain >=511) { - // inspar(button, "entry214", ptrf, 1024); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + ptrf = ptrf + 4; + + //if (remain >=511) { + // inspar("entry214", ptrf, 1024); // //remain = remain -4; //} //else if (remain > 0) { - // inspar(button, "entry214", ptrf, remain*2); + // inspar("entry214", ptrf, remain*2); //} if (remain > 0) { - inspar(button, "entry214", ptrf, remain*2); + inspar("entry214", ptrf, remain*2); } else return 1; /*if (remain > 0) { - w1 = lookup_widget("checkbutton47"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); - inspar(button, "entry212", ptrf, 2); - sprintf(tmp5, "%d", remain); - inspar(button, "entry213", tmp5, 4); - } - else { - w1 = lookup_widget("checkbutton47"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE); - } */ + w1 = lookup_widget("checkbutton47"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE); + inspar("entry212", ptrf, 2); + sprintf(tmp5, "%d", remain); + inspar("entry213", tmp5, 4); + } + else { + w1 = lookup_widget("checkbutton47"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE); + } */ return 1; - } - diff --git a/src/loadpacket.h b/src/loadpacket.h index 1c49ad8..7041baf 100644 --- a/src/loadpacket.h +++ b/src/loadpacket.h @@ -18,34 +18,19 @@ * */ +#ifndef __LOADPACKET_H__ +#define __LOADPACKET_H__ + +#include + #include "headers.h" -int load_gen_p_data(GtkButton *button, GtkTreeModel *model, char *, struct pcaprec_hdr *, int, struct clist_hdr *clptri, - double timediff, double timebeg); -int load_packet_disector(GtkButton *button, char *, int whocalled, struct clist_hdr *clptr, int); -int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr); -int ipv6_header(GtkButton *button, int whocalled, struct clist_hdr *clptr); - - - -int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets); -//int load_packet_disector(GtkButton *button, FILE *); -int load_gen_b_data(GtkButton *button, FILE *); -int load_gen_s_data(GtkButton *button, FILE *); -//int load_gen_p_data(GtkButton *button, char *, pcaprec_hdr *); -int ethernet_8023(GtkButton *button, int whocalled); -int ethernet_verII(GtkButton *button, int whocalled); -//int ipv4_header(GtkButton *button, int whocalled); -int arp_header(GtkButton *button, int whocalled); -int userdef2_field(GtkButton *button, int whocalled); -void inspar(GtkButton *button, char *entry, char *from, int length); -void insint(GtkButton *button, char *entry, char *from, int length); -signed int retint(char *ch); -unsigned long retint2(char *ch, int length); -int tcp_header(GtkButton *button, int whocalled); -int udp_header(GtkButton *button, int whocalled); -int igmp_header(GtkButton *button, int whocalled); -int icmp_header(GtkButton *button, int whocalled); -int icmpv6_header(GtkButton *button, int whocalled); -int usedef_insert(GtkButton *button, char *entry, int whocalled); -void convert8field(char *to, char *from); +int load_packet_disector(char *, int whocalled, struct clist_hdr *clptr, int); + + + +int load_data(FILE *file_p, int whocalled, int howmanypackets); +int load_gen_b_data(FILE *file_p); +int load_gen_s_data(FILE *file_p); + +#endif /* __LOADPACKET_H__ */ diff --git a/src/savepacket.c b/src/savepacket.c index 9432a6d..cf1b66f 100644 --- a/src/savepacket.c +++ b/src/savepacket.c @@ -19,7 +19,6 @@ */ #include -#include #include #include #include "savepacket.h" @@ -35,9 +34,8 @@ extern unsigned char packet[9300]; static unsigned long pcap_link_type = 1; /* Default is DLT-EN10MB */ /* this one saves the paremeters from builder window into a file */ -int save_packet(GtkButton *button, gpointer user_data, FILE *file_p) { - - if (make_packet(button, user_data) == -1) { +int save_packet(FILE *file_p) { + if (make_packet() == -1) { return -1; } @@ -64,8 +62,7 @@ int save_packet(GtkButton *button, gpointer user_data, FILE *file_p) { } -int save_gen_b(GtkButton *button, FILE *file_p) { - +int save_gen_b(FILE *file_p) { GtkWidget /**bt2,*/ *bt3, *bt4, *bt5 /*,*bt7, *bt8*/; gchar *bt1_t, *bt2_t; long count = 0, del = 0; @@ -126,8 +123,7 @@ int save_gen_b(GtkButton *button, FILE *file_p) { } -int save_gen_s(GtkButton *button, FILE *file_p) { - +int save_gen_s(FILE *file_p) { GtkWidget *bt1, *bt2, *bt5, *bt6, *bt7; gchar *bt1_t, *bt2_t; long count = 0, del = 0; @@ -281,8 +277,7 @@ int save_gen_s(GtkButton *button, FILE *file_p) { } -int save_gen_pcap(GtkButton *button, FILE *file_p) { - +int save_gen_pcap(G_GNUC_UNUSED FILE *file_p) { error("Nothing to save here!"); return 1; diff --git a/src/savepacket.h b/src/savepacket.h index 3a1cdfd..95d460d 100644 --- a/src/savepacket.h +++ b/src/savepacket.h @@ -18,7 +18,14 @@ * */ -int save_packet(GtkButton *button, gpointer user_data, FILE *file_p); -int save_gen_b(GtkButton *button, FILE *file_p); -int save_gen_s(GtkButton *button, FILE *file_p); -int save_gen_pcap(GtkButton *button, FILE *file_p); +#ifndef __SAVEPACKET_H__ +#define __SAVEPACKET_H__ + +#include + +int save_packet(FILE *file_p); +int save_gen_b(FILE *file_p); +int save_gen_s(FILE *file_p); +int save_gen_pcap(FILE *file_p); + +#endif /* __SAVEPACKET_H__ */