~ubuntu-branches/ubuntu/wily/packeth/wily

« back to all changes in this revision

Viewing changes to src/savepacket.c

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-03-04 21:32:00 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100304213200-dnrtvqlt9c5nont4
Tags: 1.6.5-1
* New upstream version
* debian/control:
  - updated my email address
  - DMUA removed
  - bumped Standards-Version to 3.8.4 (no changes needed)
  - bumped debhelper dependency to >= 7.0.50~, to use
    overridden rules
  - removed Build-Dependency on quilt
* debian/rules:
  - use dh7
  - rename /usr/bin/packETH to /usr/bin/packeth
* debian/watch updated
* debian/source/format: use 3.0 (quilt)
* debian/patches/:
  - fix_pixmaps.patch removed, fixed upstream
  - fix_warnings.patch updated, and renamed to 01-fix_warnings.patch
  - fix_Makefile.patch removed, fixed in debian/rules
  - 02-fix_typo.patch added
* debian/examples removed, no more available upstream
* debian/packeth.1 manually rewritten, without using docbook sources
* debian/copyright: point to the non-symlink license

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * packETH - ethernet packet generator
 
3
 * By Miha Jemec <jemcek@gmail.com>
 
4
 * Copyright 2003 Miha Jemec, Iskratel
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * 
 
21
 */
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
#include "savepacket.h"
 
28
#include "support.h"
 
29
#include "function.h"
 
30
#include "callbacks.h"
 
31
#include "headers.h"
 
32
 
 
33
extern int number;
 
34
extern unsigned char packet[1522];
 
35
 
 
36
/* this one saves the paremeters from builder window into a file */
 
37
int save_packet(GtkButton *button, gpointer user_data, FILE *file_p) {
 
38
 
 
39
        if (make_packet(button, user_data) == -1) {
 
40
                return -1;
 
41
        }
 
42
 
 
43
        struct pcap_hdr fh;
 
44
        fh.magic = PCAP_MAGIC;
 
45
        fh.version_major = 2;
 
46
        fh.version_minor = 4;
 
47
        fh.thiszone = 0;
 
48
        fh.sigfigs = 0;
 
49
        fh.snaplen = 102400;
 
50
        fh.network = pcap_link_type;
 
51
        fwrite(&fh, sizeof(fh), 1, file_p);
 
52
    
 
53
        struct pcaprec_hdr ph;
 
54
        ph.ts_sec = 0;
 
55
        ph.ts_usec = 0;
 
56
        ph.incl_len = number;
 
57
        ph.orig_len = number;
 
58
        fwrite(&ph, sizeof(ph), 1, file_p);
 
59
 
 
60
        fwrite(packet, number, 1, file_p);
 
61
 
 
62
        return 1;
 
63
}
 
64
 
 
65
 
 
66
int save_gen_b(GtkButton *button, FILE *file_p) {
 
67
 
 
68
        GtkWidget *bt1, *bt2, *bt3, *bt4, *bt5, *bt6, *bt7, *bt8;
 
69
        gchar *bt1_t, *bt2_t;
 
70
        long count = 0, del = 0;
 
71
        int timeflag = 0, index = 0;
 
72
 
 
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");
 
79
 
 
80
        bt1_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt3));
 
81
        bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt4));
 
82
 
 
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);
 
87
 
 
88
        if (GTK_TOGGLE_BUTTON(bt5)->active) {
 
89
                count = -3;
 
90
        }
 
91
        else {
 
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)
 
94
                        return -1;
 
95
 
 
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)");
 
101
                        return -1;
 
102
                }
 
103
        }
 
104
 
 
105
        if (GTK_TOGGLE_BUTTON(bt6)->active) {
 
106
                del = 0;
 
107
        }
 
108
        else {
 
109
                /* there can be rubbish in this field */
 
110
                if (check_digit(bt2_t, strlen(bt2_t), "Error: Delay between packets field") == -1)
 
111
                        return -1;
 
112
 
 
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");
 
118
                        return -1;
 
119
                }
 
120
        }
 
121
 
 
122
        if (GTK_TOGGLE_BUTTON(bt1)->active)
 
123
                timeflag = 1;
 
124
        else
 
125
                timeflag = 0;
 
126
 
 
127
 
 
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);
 
134
 
 
135
        return 1;
 
136
}
 
137
 
 
138
 
 
139
int save_gen_s(GtkButton *button, FILE *file_p) {
 
140
 
 
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];
 
147
        char buff4[101];
 
148
 
 
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");
 
154
 
 
155
        bt1_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt6));
 
156
        bt2_t = (char *) gtk_entry_get_text(GTK_ENTRY(bt7));
 
157
 
 
158
        if (GTK_TOGGLE_BUTTON(bt1)->active)
 
159
                timeflag = 1;
 
160
        else
 
161
                timeflag = 0;
 
162
 
 
163
        if (GTK_TOGGLE_BUTTON(bt5)->active) {
 
164
                count = -3;
 
165
        }
 
166
        else {
 
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)
 
170
                        return -1;
 
171
 
 
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)");
 
177
                        return -1;
 
178
                }
 
179
        }
 
180
 
 
181
        
 
182
        if (count == 1)
 
183
                del = 0;
 
184
        else {
 
185
                /* there can be rubbish in this field */
 
186
                if (check_digit(bt2_t, strlen(bt2_t), "Error: Delay between sequences field") == -1)
 
187
                        return -1;
 
188
 
 
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)");
 
194
                        return -1;
 
195
                }
 
196
        }
 
197
 
 
198
        for (i=0; i<10; i++) {
 
199
 
 
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));
 
204
 
 
205
                /* if there is no name, skip it */
 
206
                if ( strlen(bt1_t) == 0 )  {
 
207
                        partable[i][0] = 0;
 
208
                        continue;
 
209
                }
 
210
                else
 
211
                        partable[i][0] = 1;
 
212
                /* copy the name in the table */
 
213
                strncpy(&pkttable[i][0], bt1_t, 70);
 
214
 
 
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)
 
221
                        return -1;
 
222
 
 
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);
 
228
                        error(buff4);
 
229
                        return -1;
 
230
                }
 
231
 
 
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)
 
238
                        return -1;
 
239
                
 
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);
 
245
                        error(buff4);
 
246
                        return -1;
 
247
                }
 
248
 
 
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)
 
255
                        return -1;
 
256
 
 
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);
 
262
                        error(buff4);
 
263
                        return -1;
 
264
                }
 
265
 
 
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)
 
270
                        partable[i][4] = 0;
 
271
                else
 
272
                        partable[i][4] = 1;
 
273
        }
 
274
 
 
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");
 
283
                }
 
284
                else
 
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]);
 
287
                }
 
288
 
 
289
        return 1;
 
290
}
 
291
 
 
292
 
 
293
int save_gen_pcap(GtkButton *button, FILE *file_p) {
 
294
 
 
295
        error("Nothing to save here!");
 
296
 
 
297
        return 1;
 
298
}