2
* packETH - ethernet packet generator
3
* By Miha Jemec <jemcek@gmail.com>
4
* Copyright 2003 Miha Jemec, Iskratel
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include "savepacket.h"
30
#include "callbacks.h"
34
extern unsigned char packet[1522];
36
/* this one saves the paremeters from builder window into a file */
37
int save_packet(GtkButton *button, gpointer user_data, FILE *file_p) {
39
if (make_packet(button, user_data) == -1) {
44
fh.magic = PCAP_MAGIC;
50
fh.network = pcap_link_type;
51
fwrite(&fh, sizeof(fh), 1, file_p);
53
struct pcaprec_hdr ph;
58
fwrite(&ph, sizeof(ph), 1, file_p);
60
fwrite(packet, number, 1, file_p);
66
int save_gen_b(GtkButton *button, FILE *file_p) {
68
GtkWidget *bt1, *bt2, *bt3, *bt4, *bt5, *bt6, *bt7, *bt8;
70
long count = 0, del = 0;
71
int timeflag = 0, index = 0;
73
bt1 = lookup_widget(GTK_WIDGET (button), "radiobutton34");
74
bt2 = lookup_widget(GTK_WIDGET (button), "optionmenu9");
75
bt3 = lookup_widget(GTK_WIDGET (button), "entry109");
76
bt4 = lookup_widget(GTK_WIDGET (button), "entry110");
77
bt5 = lookup_widget(GTK_WIDGET(button), "checkbutton35");
78
bt6 = lookup_widget(GTK_WIDGET(button), "checkbutton37");
80
bt1_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt3));
81
bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt4));
83
bt7 = GTK_OPTION_MENU(bt2)->menu;
84
bt8 = gtk_menu_get_active (GTK_MENU (bt7));
85
/* YYY we don't save this value, since we don't know how to load it. We don't know what packet this is */
86
index = g_list_index (GTK_MENU_SHELL (bt7)->children, bt8);
88
if (GTK_TOGGLE_BUTTON(bt5)->active) {
92
/* there can be rubbish in this field */
93
if (check_digit(bt1_t, strlen(bt1_t), "Error: Number of packets to send field") == -1)
96
count = strtol(bt1_t, (char **)NULL, 10);
97
/* we allow to send 9999999 max */
98
if ( (count > 9999999) || (count < 1) ) {
99
//printf("Error: Packets send number value\n");
100
error("Error: Packets send number value (1 - 9999999)");
105
if (GTK_TOGGLE_BUTTON(bt6)->active) {
109
/* there can be rubbish in this field */
110
if (check_digit(bt2_t, strlen(bt2_t), "Error: Delay between packets field") == -1)
113
del = strtol(bt2_t, (char **)NULL, 10);
114
/* max delay 999,999999 s */
115
if ( (del > 999999999) || (del < 1) ) {
116
//printf("Error: Delay between packets value\n");
117
error("Error: Delay between packets value (1 - 999999999");
122
if (GTK_TOGGLE_BUTTON(bt1)->active)
128
fprintf(file_p, "#configuration parameters for send built generator\n");
129
fprintf(file_p, "#absolute/relative timing (1/0)\n%d\n"
130
/*"#adjust parameters while sending\n%d\n"*/
131
"#number of packets to send (-3 for infinite)\n%ld\n"
132
"#delay between packets (0 for max speed)\n%ld\n",
133
timeflag /*,index*/, count, del);
139
int save_gen_s(GtkButton *button, FILE *file_p) {
141
GtkWidget *bt1, *bt2, *bt5, *bt6, *bt7;
142
gchar *bt1_t, *bt2_t;
143
long count = 0, del = 0;
144
int i = 0, timeflag = 0;
145
unsigned char pkttable[10][71];
146
long int partable[10][5];
149
bt1 = lookup_widget(GTK_WIDGET (button), "radiobutton36");
150
bt2 = lookup_widget(GTK_WIDGET (button), "radiobutton37");
151
bt5 = lookup_widget(GTK_WIDGET (button), "checkbutton36");
152
bt6 = lookup_widget(GTK_WIDGET (button), "entry151");
153
bt7 = lookup_widget(GTK_WIDGET (button), "entry152");
155
bt1_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt6));
156
bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt7));
158
if (GTK_TOGGLE_BUTTON(bt1)->active)
163
if (GTK_TOGGLE_BUTTON(bt5)->active) {
167
/* there can be rubbish in this field */
168
if (check_digit(bt1_t, strlen(bt1_t),
169
"Error: Number of sequences to send field") == -1)
172
count = strtol(bt1_t, (char **)NULL, 10);
173
/* we allow to send 9999999 max */
174
if ( (count > 9999999) || (count < 1) ) {
175
//printf("Error: Number of sequences to send field\n");
176
error("Error: Number of sequences to send field (1 - 9999999)");
185
/* there can be rubbish in this field */
186
if (check_digit(bt2_t, strlen(bt2_t), "Error: Delay between sequences field") == -1)
189
del = strtol(bt2_t, (char **)NULL, 10);
190
/* max delay 999,999999 s */
191
if ( (del > 999999999) || (del < 0) ) {
192
//printf("Error: Delay between sequences field\n");
193
error("Error: Delay between sequences field (0 - 999999999)");
198
for (i=0; i<10; i++) {
200
/* name of the packet and packet contents */
201
snprintf(buff4, 100, "entry%d", 111+i);
202
bt1 = lookup_widget(GTK_WIDGET (button), buff4);
203
bt1_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt1));
205
/* if there is no name, skip it */
206
if ( strlen(bt1_t) == 0 ) {
212
/* copy the name in the table */
213
strncpy(&pkttable[i][0], bt1_t, 70);
215
/* number of packets to send */
216
snprintf(buff4, 100, "entry%d", 121+i);
217
bt2 = lookup_widget(GTK_WIDGET (button), buff4);
218
bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt2));
219
snprintf(buff4, 100, "Error: Number of packets field in row %d", i+1);
220
if (check_digit(bt2_t,strlen(bt2_t), buff4) == -1)
223
partable[i][1] = strtol(bt2_t, (char **)NULL, 10);
224
/* we allow to send 9999999 max */
225
if ( (partable[i][1] > 9999999) || (partable[i][1] < 0) ) {
226
snprintf(buff4, 100, "Error: number of packets value in row %d", i+1);
227
//printf("Error: number of packets value in row %d\n", i+1);
232
/* delay between packets */
233
snprintf(buff4, 100, "entry%d", 131+i);
234
bt2 = lookup_widget(GTK_WIDGET (button), buff4);
235
bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt2));
236
snprintf(buff4, 100, "Error: Delay between packets field in row %d", i+1);
237
if (check_digit(bt2_t,strlen(bt2_t), buff4) == -1)
240
partable[i][2] = strtol(bt2_t, (char **)NULL, 10);
241
/* max delay 999,999999 s */
242
if ( (partable[i][2] > 999999999) || (partable[i][2] < 0) ) {
243
snprintf(buff4, 100, "Error: delay between value in row %d", i+1);
244
//printf("Error: delay between value in row %d\n", i+1);
249
/* delay to next sequence */
250
snprintf(buff4, 100, "entry%d", 141+i);
251
bt2 = lookup_widget(GTK_WIDGET (button), buff4);
252
bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt2));
253
snprintf(buff4, 100, "Error: Delay to next value in row %d", i+1);
254
if (check_digit(bt2_t,strlen(bt2_t), buff4) == -1)
257
partable[i][3] = strtol(bt2_t, (char **)NULL, 10);
258
/* max delay 999,999999 s */
259
if ( (partable[i][3] > 999999999) || (partable[i][3] < 0) ) {
260
snprintf(buff4, 100, "Error: delay to next value in row %d", i+1);
261
//printf("Error: delay to next value in row %d\n", i+1);
266
/* enable or disable */
267
snprintf(buff4, 100, "checkbutton%d", 25+i);
268
bt1 = lookup_widget(GTK_WIDGET(button), buff4);
269
if (GTK_TOGGLE_BUTTON(bt1)->active)
275
fprintf(file_p, "#configuration parameters for send sequence generator\n");
276
fprintf(file_p, "#absolute/relative timing (1/0), number (-3=infinite), delay (1=max)\n");
277
fprintf(file_p, "%d,%ld,%ld\n", timeflag, count,del);
278
fprintf(file_p, "#parameters for each sequence should have:\n#name, number of packets, delay between packets, delay to next sequence, enable/disable\n");
279
for (i=0; i<10; i++) {
280
fprintf(file_p, "#parameters for sequence number %d\n", i);
281
if (partable[i][0] == 0) {
282
fprintf(file_p, "0\n");
285
fprintf(file_p, "%s,%ld,%ld,%ld,%ld\n", &pkttable[i][0], partable[i][1],
286
partable[i][2], partable[i][3],partable[i][4]);
293
int save_gen_pcap(GtkButton *button, FILE *file_p) {
295
error("Nothing to save here!");