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 "loadpacket.h"
31
#include "callbacks.h"
32
//#include "libnet/libnet-headers.h"
33
//#include "headers.h"
35
static GtkWidget *w1, *w2, *w3, *w4, *w5, *w6, *w7, *w8;
43
protocol_type protokol;
45
/* this one loads the parameters from file into notebook2 (Gen-b page) */
46
int load_gen_b_data(GtkButton *button, FILE *file_p) {
53
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton35");
54
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton34");
55
w3 = lookup_widget(GTK_WIDGET (button), "optionmenu9");
56
w4 = lookup_widget(GTK_WIDGET (button), "entry109");
57
w5 = lookup_widget(GTK_WIDGET (button), "entry110");
58
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton35");
59
w7 = lookup_widget(GTK_WIDGET(button), "checkbutton37");
60
/* we read the file ohh python, where are you... */
63
/* rules for config files:
64
* - comments start with #
65
* - there can be spaces and newlines
66
* - only digits and - are acceptable characters
69
/* we have to limit the lines we read paramters from */
70
while ( (c = fgetc( file_p )) != EOF ) {
71
/* all the comment lines, starting with # , no limit for comment lines*/
72
if ( (j==0) && (c == 35)) {
73
/* ok, read till the end of line */
74
while ( getc(file_p) != 10);
78
/* let's limit the size */
79
if ( (j > 9) || (k > 2) )
82
/* ok, it is not a comment line so the info: only digits and minus sign are acceptable */
83
if ( (isdigit(c) != 0) || (c == 45) ) {
88
/* no digit is it a newline? */
92
if (strlen(buff) == 0)
94
buff4[k] = strtol(buff, (char **)NULL, 10);
96
strncpy(&buffc[k][j], buff, 9);
99
/* not, ok this is an error */
106
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
107
else if (buff4[0] == 0)
108
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
113
/* adjusting parameters...
114
if ( (buff4[1] >= 0) && (buff4[1] <= 4) )
115
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), buff4[1]);
120
if (buff4[1] == - 3) {
121
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
122
gtk_entry_set_text(GTK_ENTRY(w4), "");
123
gtk_widget_set_sensitive (w4, FALSE);
125
else if ( (buff4[1] > 0) && (buff4[1] <= 9999999) ) {
126
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
127
gtk_widget_set_sensitive (w4, TRUE);
128
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[1][0]);
135
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 1);
136
gtk_entry_set_text(GTK_ENTRY(w5), "");
137
gtk_widget_set_sensitive (w5, FALSE);
139
else if ( (buff4[2] >= 1) && (buff4[2] <= 999999999) ) {
140
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w7), 0);
141
gtk_widget_set_sensitive (w5, TRUE);
142
gtk_entry_set_text(GTK_ENTRY(w5), &buffc[2][0]);
153
/* this one loads the parameters from file into notebook2 (Gen-s page) */
154
int load_gen_s_data(GtkButton *button, FILE *file_p) {
160
char *ptr = NULL, *ptr2 = NULL;
166
/* rules for config files:
167
* - comments start with #
168
* - there can be spaces and newlines
169
* - only digits and - are acceptable characters
172
while ( (c = fgetc( file_p )) != EOF ) {
173
/* all the comment lines, starting with # */
174
if ( (j==0) && (c == 35)) {
175
while ( getc(file_p) != 10);
178
/* all blank lines */
179
if ( (j==0) && (c == 10))
181
/* read the whole lines */
182
if ((isascii(c) != 0) && (j<200) && (c!=10) && (k<11)) {
187
/* , or \n mean end of string */
197
w1 = lookup_widget(GTK_WIDGET (button), "radiobutton36");
198
w2 = lookup_widget(GTK_WIDGET (button), "radiobutton37");
199
w4 = lookup_widget(GTK_WIDGET (button), "entry151");
200
w5 = lookup_widget(GTK_WIDGET (button), "entry152");
201
w6 = lookup_widget(GTK_WIDGET(button), "checkbutton36");
203
/* first line should have three parameters */
204
/* first is absolute or relative delay, allowed values 0 and 1 */
205
if (strncmp(&buffc[0][0], "1", 1) == 0)
206
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w1), 1);
207
else if (strncmp(&buffc[0][0], "0", 1) == 0)
208
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
213
/* second is number of packets: -3 means infinite, or 1 till 9999999) */
214
if (strncmp(&buffc[0][2], "-3", 2) == 0) {
215
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 1);
216
gtk_entry_set_text(GTK_ENTRY(w4), "");
217
gtk_widget_set_sensitive (w4, FALSE);
221
if ( (ptr = strchr(&buffc[0][2], 44)) == NULL) {
225
buff4[0] = strtol(&buffc[0][2], (char **)NULL, 10);
227
if ( (buff4[0] >= 0) && (buff4[0] <= 9999999) ) {
228
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w6), 0);
229
gtk_widget_set_sensitive (w4, TRUE);
230
gtk_entry_set_text(GTK_ENTRY(w4), &buffc[0][2]);
237
/* last parameter is delay between sequences */
238
buff4[0] = strtol(ptr+1, (char **)NULL, 10);
240
if ( (buff4[0] >= 0) && (buff4[0] <= 999999999) ) {
241
gtk_entry_set_text(GTK_ENTRY(w5), ptr+1);
247
/* we have to clean everything */
248
for (j = 0; j < 10; j++) {
249
snprintf(buff, 10, "entry%d", 111+j);
250
w2 = lookup_widget(GTK_WIDGET (button), buff);
251
gtk_entry_set_text(GTK_ENTRY(w2), "");
252
snprintf(buff, 100, "entry%d", 121+j);
253
w3 = lookup_widget(GTK_WIDGET (button), buff);
254
gtk_entry_set_text(GTK_ENTRY(w3), "");
255
snprintf(buff, 100, "entry%d", 131+j);
256
w3 = lookup_widget(GTK_WIDGET (button), buff);
257
gtk_entry_set_text(GTK_ENTRY(w3), "");
258
snprintf(buff, 100, "entry%d", 141+j);
259
w3 = lookup_widget(GTK_WIDGET (button), buff);
260
gtk_entry_set_text(GTK_ENTRY(w3), "");
261
snprintf(buff, 100, "checkbutton%d", 25+j);
262
w2 = lookup_widget(GTK_WIDGET(button), buff);
263
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
266
/* and now all the rest */
267
for (j = 1; j < k; j++) {
268
/* first is packet name */
269
if ( (ptr2 = strchr(&buffc[j][0], 44)) == NULL)
272
if ( (strlen(&buffc[j][0]) > 0 ) && (strlen(&buffc[j][0]) < 70) ) {
273
snprintf(buff, 10, "entry%d", 110+j);
274
w2 = lookup_widget(GTK_WIDGET (button), buff);
275
gtk_entry_set_text(GTK_ENTRY(w2), &buffc[j][0]);
280
/* number of packets */
282
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
286
cc = strtol(ptr, (char **)NULL, 10);
287
if ( (cc < 0) || (cc > 9999999) ) {
290
snprintf(buff, 100, "entry%d", 120+j);
291
w3 = lookup_widget(GTK_WIDGET (button), buff);
292
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
294
/* delay between packets */
296
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
300
cc = strtol(ptr, (char **)NULL, 10);
301
if ( (cc < 0) || (cc > 999999999) ) {
304
snprintf(buff, 100, "entry%d", 130+j);
305
w3 = lookup_widget(GTK_WIDGET (button), buff);
306
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
310
if ( (ptr2 = strchr(ptr, 44)) == NULL) {
314
cc = strtol(ptr, (char **)NULL, 10);
315
if ( (cc < 0) || (cc > 999999999) ) {
318
snprintf(buff, 100, "entry%d", 140+j);
319
w3 = lookup_widget(GTK_WIDGET (button), buff);
320
gtk_entry_set_text(GTK_ENTRY(w3), ptr);
322
/* enable or disable */
324
snprintf(buff, 100, "checkbutton%d", 24+j);
325
w2 = lookup_widget(GTK_WIDGET(button), buff);
327
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 0);
328
else if (*ptr == '0')
329
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w2), 1);
340
/* opens the pcap file.
341
* if we call this function from the builder window only one - first, packet will be read
342
* from the Genp window, packets will be loaded untill EOF is reached */
343
int load_data(GtkButton *button, FILE *file_p, int whocalled, int howmanypackets) {
346
struct pcaprec_hdr ph;
347
struct clist_hdr clh;
349
guint32 secu = 0, secb = 0;
350
guint32 usecu = 0, usecb = 0;
356
/* first we read the pcap file header */
357
freads = fread(pkt_temp, sizeof(fh), 1, file_p);
362
memcpy(&fh, pkt_temp, 24);
364
/* if magic number in NOK, exit */
365
if (fh.magic != PCAP_MAGIC)
368
/* hm, I forgot a little bit, but I assume 1 means builder here */
369
if (whocalled == 1) {
371
/* next the pcap packet header */
372
freads = fread(pkt_temp, sizeof(ph), 1, file_p);
378
/* copy the 16 bytes into ph structure */
379
memcpy(&ph, pkt_temp, 16);
381
/* and the packet itself, but only up to the capture length */
382
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
388
/* convert the packet information from int to hex */
389
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
390
c8(&field[2*ji], *(pkt_temp+ji));
391
field[2*ji+2] = '\0';
393
load_packet_disector(button, field, 1, &clh, ph.incl_len);
400
clis = lookup_widget(GTK_WIDGET (button), "clist2");
401
gtk_clist_clear(GTK_CLIST(clis));
403
for (j=0; j<howmanypackets; j++) {
405
/* next the pcap packet header */
406
fread(pkt_temp, sizeof(ph), 1, file_p);
412
/* copy the 16 bytes into ph structure */
413
memcpy(&ph, pkt_temp, 16);
415
/* and the packet itself, but only up to the capture length */
416
freads = fread(pkt_temp+sizeof(ph), ph.incl_len, 1, file_p);
422
/* convert the packet information from int to hex */
423
for(ji=0; ji<(sizeof(ph)+ph.incl_len); ji++)
424
c8(&field[2*ji], *(pkt_temp+ji));
425
field[2*ji+2] = '\0';
427
/* we have to dissect the packet to get information for the list */
428
load_packet_disector(button, field, 2, &clh, ph.incl_len);
429
//printf("tukaj3 %s\n", field);
431
/* calculate the time information */
439
timediff = ((double)((double)ph.ts_sec - (double)secu)*1000000 +
440
(double)((double)ph.ts_usec - (double)usecu)) / 1000000;
441
timebeg = ((double)((double)ph.ts_sec - (double)secb)*1000000 +
442
(double)((double)ph.ts_usec - (double)usecb)) / 1000000;
445
//printf("tukaj2 %s\n", field);
450
/* insert a new row into clist */
451
load_gen_p_data(button, clis, field, &ph, j+1, &clh, timediff, timebeg);
453
if (j == howmanypackets)
454
error("Only first 1000 packets loaded!\nTo change this modify #define on top of callbacks.c");
462
/* this one loads the parameters from file into notebook2 (Genp page) */
463
int load_gen_p_data(GtkButton *button, GtkWidget *clis, char *fieldek, struct pcaprec_hdr *ph2,
464
int pkt_nr, struct clist_hdr *clptr, double timediff, double timebeg) {
468
gchar field_p[1][3100];
470
datap[0]=&fieldp[0][0];
471
datap[1]=&fieldp[1][0];
472
datap[2]=&fieldp[2][0];
473
datap[3]=&fieldp[3][0];
474
datap[4]=&fieldp[4][0];
475
datap[5]=&fieldp[5][0];
476
datap[6]=&fieldp[6][0];
477
datap[7]=&field_p[0][0];
479
//printf("TUKAJ1:%s\n", fieldek);
480
g_snprintf(fieldp[0], 20, "%d", pkt_nr);
481
g_snprintf(fieldp[1], 20, "%f", timebeg);
482
g_snprintf(fieldp[2], 20, "%f", timediff);
484
if ( (*ph2).incl_len == (*ph2).orig_len )
485
g_snprintf(fieldp[3], 20, "%d", (*ph2).incl_len);
487
g_snprintf(fieldp[3], 20, "%d !", (*ph2).incl_len);
489
g_snprintf(fieldp[4], 20, "%s", clptr->src);
490
g_snprintf(fieldp[5], 20, "%s", clptr->dst);
494
g_snprintf(fieldp[6], 20, "Ethernet II");
498
g_snprintf(fieldp[6], 20, "Ethernet 802.3");
502
g_snprintf(fieldp[6], 20, "ARP");
506
g_snprintf(fieldp[6], 20, "IPv4");
510
g_snprintf(fieldp[6], 20, "TCP");
514
g_snprintf(fieldp[6], 20, "UDP");
518
g_snprintf(fieldp[6], 20, "IGMP");
522
g_snprintf(fieldp[6], 20, "ICMP");
527
g_snprintf(field_p[0], 2*(32+(*ph2).incl_len), "%s", fieldek);
529
gtk_clist_append(GTK_CLIST(clis), datap);
535
/* this routine was changed. it loads the packet into notebook2 (Builder page) or it checks the file containing the packets
536
* for loading into Genp window
537
* if who called = 1 - we load the contents into builder field
538
* if who called = 2 - we load the contenst into Genp window but we need the information for filling in the clist
540
int load_packet_disector(GtkButton *button, char *fieldek, int whocalled, struct clist_hdr *clptr, int dolpaketa) {
547
//printf("\n:\n%s\n", fieldek);
548
//convert8field(ptrt, ptrf); insint(button, "entry179", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
549
//convert8field(ptrt, ptrf+8); insint(button, "entry180", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
550
//convert8field(ptrt, ptrf+16); insint(button, "entry181", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
551
//convert8field(ptrt, ptrf+24); insint(button, "entry182", ptrt, 8); ptrt = temp; ptrf = ptrf-8;
555
/* what is the shortest length we still allow?
556
* we don't care if the packet is shorter than actually allowed to go on ethernet
557
* maybe the user just wanted to save packet even if it is to short, so why not load it?
558
* what we do demand is, that every layer must be completed
559
* ok, here at least 14 bytes: 6 dest mac, 6 source mac and 2 for type or length*/
561
error("Can't load packet: Ethernet header is not long enough!");
565
/* first there is destination mac */
566
w1 = lookup_widget(GTK_WIDGET(button), "L_dst_mac");
567
for (i=1; i<=18; i++, ptrt++) {
577
gtk_entry_set_text(GTK_ENTRY(w1), temp);
579
memcpy(clptr->dst, temp, 20);
583
w2 = lookup_widget(GTK_WIDGET(button), "L_src_mac");
584
for (i=1; i<=18; i++, ptrt++) {
594
gtk_entry_set_text(GTK_ENTRY(w2), temp);
596
memcpy(clptr->src, temp, 20);
598
/* next there is type or length field or 802.1q or QinQ! */
599
i = char2x(ptrf)*256 + char2x(ptrf+2);
601
remain = remain - 14;
603
/* in case of a vlan tag 0x8100 == 33024) */
604
w1 = lookup_widget(GTK_WIDGET(button), "bt_8021q");
605
w2 = lookup_widget(GTK_WIDGET(button), "frame6");
607
if ((i == 33024) || (i==34984) || (i==37120) || (i==37376)) {
608
w3 = lookup_widget(GTK_WIDGET(button), "L_optmenu2_bt");
609
w4 = lookup_widget(GTK_WIDGET(button), "checkbutton39");
610
w5 = lookup_widget(GTK_WIDGET(button), "checkbutton40");
611
w6 = lookup_widget(GTK_WIDGET(button), "L_vlan_id");
612
w7 = lookup_widget(GTK_WIDGET(button), "entry165");
613
w8 = lookup_widget(GTK_WIDGET(button), "optionmenu21");
615
//if we have 8100 after the next 4 bytes we do QinQ
616
if ( ((char2x(ptrf+8)*256 + char2x(ptrf+10))==33024) && remain>=8)
620
if (whocalled == 1) {
621
gtk_widget_set_sensitive (w7, TRUE);
622
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), TRUE);
624
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 0);
626
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 3);
628
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 1);
630
gtk_option_menu_set_history (GTK_OPTION_MENU (w8), 2);
632
inspar(button, "entry165", ptrf, 4);
637
i = char2x(ptrf)*256 + char2x(ptrf+2);
640
if (whocalled == 1) {
641
gtk_widget_set_sensitive (w7, FALSE);
642
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w5), FALSE);
648
error("Can't load packet: Ethernet VLAN field is not long enough!");
658
if (whocalled == 1) {
659
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
660
gtk_widget_set_sensitive (w2, TRUE);
662
gtk_option_menu_set_history (GTK_OPTION_MENU (w3), (i>>1));
665
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), FALSE);
667
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w4), TRUE);
669
inspar(button, "L_vlan_id", ptrf, 3);
674
i = char2x(ptrf)*256 + char2x(ptrf+2);
678
if (whocalled == 1) {
679
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
680
gtk_widget_set_sensitive (w2, FALSE);
684
/* c will tell us which ethernet type we have */
687
/* ok, from now one, we split the dissection in different routines, depending on what values */
688
/* now if length is <= 1500, we have 802.3 ethernet and this value means length of ethernet packet */
690
next_prot = ethernet_8023(button, whocalled);
691
/* Values between 1500 and 1536 are forbidden */
692
else if ( (i>1500) && (i<1536) ) {
693
error("Can't load packet: Wrong ethernet length/type field");
696
/* if i >= 1536 - ethernet ver II */
698
next_prot = ethernet_verII(button, whocalled);
701
/* ok, so we have dissected the ethernet layer and now move on two the next layer.
702
* if the ethernet dissector returns -1, this means an error and we quit
703
* otherwise, the return value can be 2048 == 0x0800 and this means the ipv4
704
* so we try to dissect ipv4 header. in case it is ok, we activate the ippkt_radibt
705
* and this one then calls the callback which fills in ethernet ver II type field
706
* and PID field in 802.3 LLC/SNAP field. It is the same for arp packets
707
* for other packets we will try to open the userdefined window */
709
/* we got an error? */
714
else if (next_prot == 2048) {
715
/* ok, ipv4 should follow, so we call the routine for parsing ipv4 header. */
716
next_prot = ipv4_header(button, whocalled, clptr);
720
/* if the return value from parsing ipv4 header was != 0, then the header parameters
721
* are ok and we can open ipv4 notebook page activate toggle button (button calls
722
* the callback then!!! */
723
w1 = lookup_widget(GTK_WIDGET(button), "ippkt_radibt");
724
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
726
/* here we do the further parsing: tcp, udp, icmp, ...*/
727
if (next_prot == 1) {
728
/* try to parse icmp header */
729
next_prot = icmp_header(button, whocalled);
730
/* not ok, return an error */
733
/* ok, lets activate the icmp notebook */
735
w1 = lookup_widget(GTK_WIDGET(button), "icmp_bt");
736
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
739
else if (next_prot == 2) {
740
/* try to parse igmp header */
741
next_prot = igmp_header(button, whocalled);
742
/* not ok, return an error */
745
/* ok, lets activate the igmp notebook */
747
w1 = lookup_widget(GTK_WIDGET(button), "igmp_bt");
748
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
751
else if (next_prot == 6) {
752
/* try to parse tcp header */
753
next_prot = tcp_header(button, whocalled);
754
/* not ok, return an error */
757
/* ok, lets activate the tcp notebook */
759
w1 = lookup_widget(GTK_WIDGET(button), "tcp_bt");
760
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
763
/* protocols on top of tcp would follow here */
766
else if (next_prot == 17) {
767
/* try to parse udp header */
768
next_prot = udp_header(button, whocalled);
769
/* not ok, return an error */
772
/* ok, lets activate the udp notebook */
774
w1 = lookup_widget(GTK_WIDGET(button), "udp_bt");
775
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
778
/* protocols on top of udp would follow here */
780
/* protocol we do not support yet; user defined window */
782
next_prot = usedef_insert(button, "text2", whocalled);
783
w1 = lookup_widget(GTK_WIDGET(button), "ip_user_data_bt");
784
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
788
else if (next_prot == 2054) {
789
/* ok, arp header follows */
790
next_prot = arp_header(button, whocalled);
794
w1 = lookup_widget(GTK_WIDGET(button), "arppkt_radiobt");
795
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
798
/* when ipv6 will be added, activate ipv6 button instead of userdef button */
799
else if (next_prot == 34525) {
800
//w1 = lookup_widget(GTK_WIDGET(button), "IPv6_rdbt");
801
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
802
w1 = lookup_widget(GTK_WIDGET(button), "usedef2_radibt");
803
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
806
inspar(button, "L_ethtype", ptrf, 4);
808
/* -2 means only llc without snap was used, so we don't insert the value in pid field */
809
if (next_prot != -2) {
811
inspar(button, "L_pid", ptrf, 4);
814
/* anything else - user defined */
816
/* setting "usedef2_radibt" toggle button to true will call the callback which will clear
817
eth II type field and 802.3 pid field, so we have to fill this later */
818
w1 = lookup_widget(GTK_WIDGET(button), "usedef2_radibt");
819
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
821
/* we still have c to distinguish between ver II and 802.3 */
825
inspar(button, "L_ethtype", ptrf, 4);
827
/* 802.3 and with LLC SNAP */
828
else if (next_prot != -2) {
830
inspar(button, "L_pid", ptrf, 4);
833
next_prot = usedef_insert(button, "text1", whocalled);
840
int arp_header(GtkButton *button, int whocalled) {
850
/* arp header length == 28; but packet can be longer, f.e. to satisfy the min packet length */
852
error("Can't load packet: Packet length shorter than ARP header length!");
856
remain = remain - 28;
859
inspar(button, "A_hwtype", ptrf, 4);
862
inspar(button, "A_prottype", ptrf, 4);
865
inspar(button, "A_hwsize", ptrf, 2);
868
inspar(button, "A_protsize", ptrf, 2);
871
if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '1') ) {
872
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton10");
873
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
876
else if ( (*ptrf == '0') && (*(ptrf+1) == '0') && (*(ptrf+2) == '0') && (*(ptrf+3) == '2') ) {
877
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton11");
878
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
882
w1 = lookup_widget(GTK_WIDGET(button), "radiobutton17");
883
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
884
inspar(button, "entry81", ptrf, 4);
889
w1 = lookup_widget(GTK_WIDGET(button), "A_sendermac");
890
for (i=1; i<=18; i++, ptrt++) {
898
gtk_entry_set_text(GTK_ENTRY(w1), temp);
903
w1 = lookup_widget(GTK_WIDGET(button), "A_senderip");
904
for (i=1; i<=12; i++, ptrt++) {
908
snprintf(tmp, 4, "%d", x);
910
snprintf(tmp, 5, "%d.", x);
914
tmp[(i-1)%3] = *ptrf++;
917
gtk_entry_set_text(GTK_ENTRY(w1), temp);
921
w1 = lookup_widget(GTK_WIDGET(button), "A_targetmac");
922
for (i=1; i<=18; i++, ptrt++) {
930
gtk_entry_set_text(GTK_ENTRY(w1), temp);
935
w1 = lookup_widget(GTK_WIDGET(button), "A_targetip");
936
for (i=1; i<=12; i++, ptrt++) {
940
snprintf(tmp, 4, "%d", x);
942
snprintf(tmp, 5, "%d.", x);
946
tmp[(i-1)%3] = *ptrf++;
949
gtk_entry_set_text(GTK_ENTRY(w1), temp);
956
int igmp_header(GtkButton *button, int whocalled) {
966
/* well normal igmp type should have at least 8 bytes, so this is min for us */
968
error("Can't load packet: Packet length shorter than IGMP header length!");
977
inspar(button, "entry166", ptrf, 2);
979
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu20");
980
w2 = lookup_widget(GTK_WIDGET(button), "notebook8");
983
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
984
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 1);
987
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
988
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
992
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
993
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
996
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
997
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1000
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 4);
1001
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 2);
1004
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 5);
1005
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1008
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 6);
1009
gtk_notebook_set_page(GTK_NOTEBOOK(w2), 0);
1012
inspar(button, "entry167", ptrf, 2);
1014
/* set checksum button on auto */
1015
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton41");
1016
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1020
if ( (x == 17) && (remain>4) ) { /* IGMP V3 query */
1021
/*insert group ip */
1023
memset(temp, 0, 20);
1024
w1 = lookup_widget(GTK_WIDGET(button), "entry169");
1025
for (i=1; i<=12; i++, ptrt++) {
1029
snprintf(tmp, 4, "%d", x);
1031
snprintf(tmp, 5, "%d.", x);
1035
tmp[(i-1)%3] = *ptrf++;
1038
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1040
inspar(button, "entry171", ptrf, 4);
1041
x1 = (int)retint2(ptrf, 4);
1042
inspar(button, "entry172", ptrf, 4);
1043
/*#inspar(button, "entry173", ptrf, x1);*/
1044
inspar(button, "entry173", ptrf, remain);
1047
else if (x==22) { /*IGMP V3 report */
1048
inspar(button, "entry176", ptrf, 4);
1049
x1 = (int)retint2(ptrf, 4);
1050
inspar(button, "entry177", ptrf, 4);
1051
inspar(button, "entry178", ptrf, x1);
1054
else { /*all the other versions */
1055
/*insert group ip */
1057
memset(temp, 0, 20);
1058
w1 = lookup_widget(GTK_WIDGET(button), "entry175");
1059
for (i=1; i<=12; i++, ptrt++) {
1063
snprintf(tmp, 4, "%d", x);
1065
snprintf(tmp, 5, "%d.", x);
1069
tmp[(i-1)%3] = *ptrf++;
1072
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1080
int icmp_header(GtkButton *button, int whocalled) {
1089
/* well normal icmp type should have at least 8 bytes, so this is min for us */
1091
error("Can't load packet: Packet length shorter than ICMP header length!");
1099
/* insert version */
1100
inspar(button, "entry57", ptrf, 2);
1102
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu4");
1104
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 0);
1106
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 1);
1108
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 2);
1110
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 3);
1113
if (x == 0) { /* echo reply */
1114
/* insert code, checksum, identifier and seq number and data if there is some */
1115
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1116
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 0);
1117
inspar(button, "entry62", ptrf, 2);
1118
//inspar(button, "entry63", ptrf, 4);
1120
inspar(button, "entry64", ptrf, 4);
1121
inspar(button, "entry65", ptrf, 4);
1122
/* set checksum button on auto */
1123
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton16");
1124
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1126
inspar(button, "entry66", ptrf, remain * 2);
1128
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1129
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1132
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton17");
1133
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1137
else if (x == 3) { /* destination unreacheable */
1138
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1139
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 2);
1143
inspar(button, "entry58", ptrf, 2);
1145
w1 = lookup_widget(GTK_WIDGET(button), "optionmenu5");
1146
if ( (x >= 0) && (x <= 15) )
1147
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), x);
1149
gtk_option_menu_set_history (GTK_OPTION_MENU (w1), 16);
1151
/* insert code, checksum, identifier and seq number and data if there is some */
1152
//inspar(button, "entry59", ptrf, 4);
1154
inspar(button, "entry60", ptrf, 8);
1155
/* set checksum button on auto */
1156
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton15");
1157
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1159
inspar(button, "entry61", ptrf, remain * 2);
1161
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1162
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1165
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton24");
1166
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1169
else if (x == 8) { /* echo request */
1170
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1171
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 5);
1172
/* insert code, checksum, identifier and seq number and data if there is some */
1173
inspar(button, "entry74", ptrf, 2);
1174
//inspar(button, "entry77", ptrf, 4);
1176
inspar(button, "entry75", ptrf, 4);
1177
inspar(button, "entry78", ptrf, 4);
1178
/* set checksum button on auto */
1179
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton20");
1180
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1182
inspar(button, "entry76", ptrf, remain * 2);
1184
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1185
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1188
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton19");
1189
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1193
else { /* all the rest */
1194
w1 = lookup_widget(GTK_WIDGET(button), "notebook5");
1195
gtk_notebook_set_page(GTK_NOTEBOOK(w1), 1);
1196
/* insert code, checksum and data if there is some */
1197
inspar(button, "entry157", ptrf, 2);
1198
//inspar(button, "entry158", ptrf, 4);
1200
/* set checksum button on auto */
1201
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton38");
1202
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1204
inspar(button, "entry159", ptrf, (remain + 4) * 2);
1212
int usedef_insert(GtkButton *button, char *entry, int whocalled) {
1220
/* get access to buffer of the text field */
1221
w2 = lookup_widget(GTK_WIDGET(button), entry);
1222
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1224
/* copy data to tmp field */
1225
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1226
tmp[i] = *ptrf++; i++;
1227
tmp[i] = *ptrf++; i++;
1228
/* we allow only 16 bytes in each row - looks nicer */
1229
if ((j % 16) == 0 && (j > 1)) {
1238
/* insert the text in the text field */
1239
gtk_text_buffer_set_text(buffer,tmp,-1);
1247
int tcp_header(GtkButton *button, int whocalled) {
1250
char tmp[4600], tmp2[3], ch;
1258
/* for standard header this is minimum length */
1260
error("Can't load packet: Packet length shorter than TCP header length!");
1264
/* ok, packet is long enough to fill in the standard header, but what is the header length?
1265
* we insert this later but need now to see that the packet is long enough */
1266
x = retint(ptrf+24);
1267
if ( (x * 4) > remain ) {
1268
error("Can't load packet:\nPacket lenght shorter than TCP header length!");
1272
error("Can't load packet:\nTCP header length shorter than 20 bytes!");
1277
insint(button, "entry46", ptrf, 4);
1279
/* destination port */
1280
insint(button, "entry47", ptrf, 4);
1282
/* sequence number */
1283
insint(button, "entry48", ptrf, 8);
1285
/* acknowledgement number */
1286
insint(button, "entry49", ptrf, 8);
1288
/* now we insert value for length */
1289
snprintf(tmp2, 3, "%d", x*4);
1290
w1 = lookup_widget(GTK_WIDGET(button), "entry50");
1291
gtk_entry_set_text(GTK_ENTRY(w1), tmp2);
1293
/* increase by one for length and for another one for 4 bits that are reserved */
1296
/* flags; next byte */
1297
ch = char2x(ptrf) % 0x0100;
1299
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton22");
1300
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x80) > 0 ? TRUE : FALSE);
1302
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton23");
1303
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x40) > 0 ? TRUE : FALSE);
1305
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton7");
1306
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x20) > 0 ? TRUE : FALSE);
1308
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton8");
1309
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x10) > 0 ? TRUE : FALSE);
1311
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton9");
1312
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x08) > 0 ? TRUE : FALSE);
1314
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton10");
1315
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x04) > 0 ? TRUE : FALSE);
1317
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton11");
1318
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x02) > 0 ? TRUE : FALSE);
1320
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton12");
1321
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), (ch & 0x01) > 0 ? TRUE : FALSE);
1326
insint(button, "entry51", ptrf, 4);
1329
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton13");
1330
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1331
//inspar(button, "entry52", ptrf, 4);
1335
insint(button, "entry53", ptrf, 4);
1338
/* - 20 for standard header */
1339
inspar(button, "entry54", ptrf, ( (x*4) - 20) * 2);
1341
remain = remain - x*4;
1343
/* get access to buffer of the text field */
1344
w2 = lookup_widget(GTK_WIDGET(button), "text4");
1345
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1348
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1349
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1351
/* copy data to tmp field */
1352
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1353
tmp[i] = *ptrf++; i++;
1354
tmp[i] = *ptrf++; i++;
1355
/* we allow only 16 bytes in each row - looks nicer */
1356
if ((j % 16) == 0 && (j > 1)) {
1365
/* insert the text in the text field */
1366
gtk_text_buffer_set_text(buffer,tmp,-1);
1369
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton14");
1370
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1373
/* since tcp does not have any protocol field we could return destination port value which
1374
* usually describes next layer protocol; currently we return 1 */
1379
int udp_header(GtkButton *button, int whocalled) {
1389
/* for standard header this is minimum length */
1391
error("Can't load packet: Packet length shorter than UDP header length!");
1395
remain = remain - 8;
1398
insint(button, "entry56", ptrf, 4);
1400
/* destination port */
1401
insint(button, "entry41", ptrf, 4);
1404
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton3");
1405
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1406
//insint(button, "entry42", ptrf, 4);
1410
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton4");
1411
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1412
//inspar(button, "entry43", "", 4);
1415
/* get access to buffer of the text field */
1416
w2 = lookup_widget(GTK_WIDGET(button), "text3");
1417
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w2));
1420
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1421
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1423
/* copy data to tmp field */
1424
for (i=0, j=1; (i < (remain * 3) ); i++, j++) {
1425
tmp[i] = *ptrf++; i++;
1426
tmp[i] = *ptrf++; i++;
1427
/* we allow only 16 bytes in each row - looks nicer */
1428
if ((j % 16) == 0 && (j > 1)) {
1437
/* insert the text in the text field */
1438
gtk_text_buffer_set_text(buffer,tmp,-1);
1441
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton5");
1442
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), FALSE);
1445
/* since udp does not have any protocol field we could return destination port value which
1446
* usually describes next layer protocol; currently we return 1 */
1451
int ipv4_header(GtkButton *button, int whocalled, struct clist_hdr *clptr ) {
1454
int x, header_l, prot;
1460
/* for standard header this is minimum length */
1462
error("Can't load packet: IPv4 header field is not long enough!");
1466
/* first comes version but we will first check the length and then insert version */
1469
/* check the header length */
1470
/* we don't need to check the return value here, it is already done when reading from file */
1471
header_l = retint(ptrf);
1472
/* header length is the number of 32-bit words in the header, including any options.
1473
* Since this is a 4-bit field, it limits the header to 60 bytes. So the remaining length
1474
* should be at least that long or we exit here */
1475
if ( (header_l * 4) < 20 ) {
1476
error("Can't load packet:\nIPv4 header length shorter than 20 bytes!");
1479
if ( (header_l * 4) > remain ) {
1480
error("Can't load packet:\nPacket lenght shorter than IPv4 header length!");
1486
/* insert version */
1487
inspar(button, "entry26", ptrf, 1);
1489
/* insert header length */
1490
inspar(button, "entry27", ptrf, 1);
1493
inspar(button, "entry28", ptrf, 2);
1495
/* insert total length */
1496
w1 = lookup_widget(GTK_WIDGET(button), "checkbutton21");
1497
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1498
//insint(button, "entry29", ptrf, 4);
1506
/* insert identification */
1507
inspar(button, "entry30", ptrf, 4);
1513
*tmp = 0x30; /* 0x30 == 0 */
1516
x = x >> 1; /* use only first 3 bits */
1519
w1 = lookup_widget(GTK_WIDGET(button), "entry31");
1520
snprintf(tmp, 4, "%d", x);
1521
gtk_entry_set_text(GTK_ENTRY(w1), tmp);
1524
/* insert fragment offset */
1525
*tmp = 0x30; /* 0x30 == 0 */
1527
x = (char2x(tmp)%2); /* need only last bit */
1532
strncpy(tmp+1, ptrf+1, 3);
1535
insint(button, "entry32", tmp, 4);
1538
insint(button, "entry44", ptrf, 2);
1543
prot = char2x(ptrf);
1546
/* insert protocol */
1547
insint(button, "entry34", ptrf, 2);
1549
/* insert header checksum */
1550
w1 = lookup_widget(GTK_WIDGET(button), "ip_header_cks_cbt");
1551
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1552
//inspar(button, "entry35", ptrf, 4);
1559
/*insert source ip */
1561
memset(temp, 0, 20);
1563
w1 = lookup_widget(GTK_WIDGET(button), "entry38");
1564
for (i=1; i<=12; i++, ptrt++) {
1568
snprintf(tmp, 4, "%d", x);
1570
snprintf(tmp, 5, "%d.", x);
1574
tmp[(i-1)%3] = *ptrf++;
1579
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1581
memcpy(clptr->src, temp, 20);
1583
/*insert destination ip */
1585
memset(temp, 0, 20);
1587
w1 = lookup_widget(GTK_WIDGET(button), "entry37");
1588
for (i=1; i<=12; i++, ptrt++) {
1592
snprintf(tmp, 4, "%d", x);
1594
snprintf(tmp, 5, "%d.", x);
1598
tmp[(i-1)%3] = *ptrf++;
1602
gtk_entry_set_text(GTK_ENTRY(w1), temp);
1604
memcpy(clptr->dst, temp, 20);
1606
/* insert ipv4 options
1607
* header_l * 4 == total header length, - 20 for standard header == options length in bytes*/
1609
inspar(button, "entry39", ptrf, ( (header_l*4) - 20) * 2);
1611
remain = remain - (header_l * 4);
1617
int ethernet_8023(GtkButton *button, int whocalled) {
1619
int dsap, lsap, ctrl;
1623
protokol = ETH_802_3;
1628
error("Can't load packet: Ethernet 802.3 LLC field is not long enough!");
1631
remain = remain - 3;
1633
w1 = lookup_widget(GTK_WIDGET(button), "bt_8023");
1634
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1636
//w2 = lookup_widget(GTK_WIDGET(button), "frame7");
1637
//gtk_widget_set_sensitive (w2, TRUE);
1638
//gtk_notebook_set_page(GTK_NOTEBOOK(w3), 1);
1640
w1 = lookup_widget(GTK_WIDGET(button), "entry5");
1641
//inspar(button, "entry5", ptrf, 4);
1643
gtk_widget_set_sensitive (w1, FALSE);
1645
w2 = lookup_widget(GTK_WIDGET(button), "checkbutton2");
1646
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w2), TRUE);
1648
/*now the LLC / LLC-SNAP part */
1649
/* we decode only RFC 1042 format, that means the following value:
1650
dsap == ssap == 0xAA
1654
dsap = char2x(ptrf);
1655
inspar(button, "L_dsap", ptrf, 2);
1656
lsap = char2x(ptrf);
1657
inspar(button, "L_ssap", ptrf, 2);
1658
ctrl = char2x(ptrf);
1659
inspar(button, "L_ctrl", ptrf, 2);
1661
/* in case dsap != ssap != 0xAA or ctrl != 0x03 or remain length < 5 bytes, we have only
1662
* LLC without SNAP and we return value for user defined next layer */
1663
if ( (dsap != 170 ) || (lsap != 170) || (ctrl != 3) || (remain < 5) ) {
1664
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1665
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1666
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1667
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1668
gtk_widget_set_sensitive (w1, FALSE);
1669
gtk_widget_set_sensitive (w2, FALSE);
1670
/* this means we insert all the data as user defined field */
1673
/* in this case everything is ok but oui in not 0 */
1674
/* <--------------this is oui---------------------> */
1675
else if ( (char2x(ptrf) + char2x(ptrf+2) + char2x(ptrf+4) != 0 ) ) {
1676
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llc_tbt");
1677
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1678
w1 = lookup_widget(GTK_WIDGET(button), "L_oui");
1679
w2 = lookup_widget(GTK_WIDGET(button), "L_pid");
1680
gtk_widget_set_sensitive (w1, FALSE);
1681
gtk_widget_set_sensitive (w2, FALSE);
1682
/* this means we insert all the data as user defined field */
1686
/* substract 3 for oui and 2 for pid */
1687
remain = remain - 5;
1689
/* ok, so we have dsap and ssap == 0xAA, Ctlr == 0x03, OUI == 0x0 and lenght is long enough */
1690
/* set llc-snap button */
1691
w1 = lookup_widget(GTK_WIDGET(button), "L_8023_llcsnap_tbt");
1692
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1694
/* insert 0x00 into oui field */
1695
inspar(button, "L_oui", ptrf, 6);
1696
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1704
int ethernet_verII(GtkButton *button, int whocalled) {
1712
w1 = lookup_widget(GTK_WIDGET(button), "bt_ver2");
1713
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w1), TRUE);
1716
pid = char2x(ptrf)*256 + char2x(ptrf+2);
1724
/* this one inserts (length) characters from (char *from) into entry named (char *entry). It adds \0
1725
at the end and in moves pointer ptrf (this one points the the next "data" to be inserted) by length */
1726
void inspar(GtkButton *button, char *entry, char *from, int length) {
1732
ptr = malloc(length * sizeof(char) + 1);
1734
widg = lookup_widget(GTK_WIDGET(button), entry);
1736
strncpy(ptr, from, length);
1738
gtk_entry_set_text(GTK_ENTRY(widg), ptr);
1739
ptrf = ptrf + length;
1745
/* this one reads (length) characters strating at (char *from), converts them to int and inserts them
1746
into field (*entry) as integer. f.e: 0x56 == (int)86 => writes into (*entry) 86
1747
note that max size for length is 10!!! when calling this routine */
1748
void insint(GtkButton *button, char *entry, char *from, int length) {
1752
unsigned long value = 0;
1754
unsigned char x = 0;
1756
widg = lookup_widget(GTK_WIDGET(button), entry);
1758
for (i = 0; i < length; i++) {
1759
if ( (*from >= '0') && (*from <= '9'))
1761
else if ((*from >= 'A') && (*from <= 'F'))
1763
else if ((*from >= 'a') && (*from <= 'f'))
1766
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1770
ptrf = ptrf + length;
1772
snprintf(tmp, 11, "%lu", value);
1773
gtk_entry_set_text(GTK_ENTRY(widg), tmp);
1777
/* from a character return int */
1778
signed int retint(char *ch) {
1782
if ( (*ch >= '0') && (*ch <= '9'))
1784
else if ((*ch >= 'A') && (*ch <= 'F'))
1786
else if ((*ch >= 'a') && (*ch <= 'f'))
1796
/* this one reads (length) characters strating at (*from), and returns integer (max 10 char length) */
1797
unsigned long retint2(char *from, int length) {
1799
unsigned long value = 0;
1801
unsigned char x = 0;
1803
for (i = 0; i < length; i++) {
1804
if ( (*from >= '0') && (*from <= '9'))
1806
else if ((*from >= 'A') && (*from <= 'F'))
1808
else if ((*from >= 'a') && (*from <= 'f'))
1811
value = value + ((int)x) * ((unsigned long)1 << (4*(length-1-i)) );
1819
/* i have newer really understood the endians... help appreciated...
1820
* this routines just converts the contents of a char field of size 8 chars
1821
* it works also, if destination and source are the same field*/
1823
void convert8field(char *to, char *from) {
1827
/* we copy first the source contents */
1828
memcpy(f1, from, 8);
1830
memcpy(to+0, f1+6,1);
1831
memcpy(to+1, f1+7,1);
1832
memcpy(to+2, f1+4,1);
1833
memcpy(to+3, f1+5,1);
1834
memcpy(to+4, f1+2,1);
1835
memcpy(to+5, f1+3,1);
1836
memcpy(to+6, f1+0,1);
1837
memcpy(to+7, f1+1,1);